2013-02-26 17 views
0

篩選我:如何在XSLT

<ExtData> 
<table> 
    <Column biz="Bus" desc="" id="Bus" > 
     <CoreColumn coreEntityName="ser" coreId="Bus" coreColumnDataType="TypeInt" coreColumnLength=""/> 
    </Column> 
    <Column biz="ser" desc="" id="NAME" > 
     <CoreColumn coreEntityName="ser" coreId="NAME" coreColumnDataType="TypeVarChar" /> 
    </Column> 
    <Column biz="ID" desc="" id="GLOBAL_ID" > 
     <CoreColumn coreEntityName="ser" coreId="UCMDB_ID" coreColumnDataType="VarChar" /> 
     <CoreColumn coreEntityName="ser_xxx" coreId="UCMDB_ID" coreColumnDataType="VarChar" /> 
    </Column> 
    <Column biz="State" desc="" id="ser_STATE" > 
     <CoreColumn coreEntityName="ser" coreId="ser_STATE" coreColumnDataType="VarChar" /> 
    </Column> 
</table> 

,需要輸出>>>通過屬性附加傷害@coreEntityName="ser"過濾:

<ExtData> 
<table> 
    <Column biz="Bus" desc="" id="Bus" > 
     <CoreColumn coreEntityName="ser" coreId="Bus" coreColumnDataType="TypeInt" coreColumnLength=""/> 
    </Column> 
    <Column biz="ser" desc="" id="NAME" > 
     <CoreColumn coreEntityName="ser" coreId="NAME" coreColumnDataType="TypeVarChar" /> 
    </Column> 
    <Column biz="ID" desc="" id="GLOBAL_ID" > 
     <CoreColumn coreEntityName="ser" coreId="UCMDB_ID" coreColumnDataType="VarChar" /> 
    </Column> 
    <Column biz="State" desc="" id="ser_STATE" > 
     <CoreColumn coreEntityName="ser" coreId="ser_STATE" coreColumnDataType="VarChar" /> 
    </Column> 
</table> 

+0

您的XSL的外觀如何,轉換的問題是什麼? – 2013-02-26 13:54:18

回答

3

下面的XSLT樣式表實現所需輸出:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/> 

    <!-- Identity template : copy attributes and elements by default --> 
    <xsl:template match="@*|*"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|*" /> 
     </xsl:copy> 
    </xsl:template> 

    <!-- Exclude all the CoreColumn elements such as their @coreEntityname 
     attribute is other than ser --> 
    <xsl:template match="CoreColumn[@coreEntityName != 'ser']" /> 

</xsl:stylesheet> 
+0

謝謝巴勃羅! – Vikonto 2013-02-26 14:15:01

+0

乾杯!很高興我可以幫助:) – 2013-02-26 14:16:31

+0

嗨巴勃羅。它是工作,但爲什麼match =「CoreColumn [@coreEntityName!='ser']」(不等於)和不匹配=「CoreColumn [@coreEntityName ='ser']」(等於) – Vikonto 2013-02-26 14:21:13