0

我有 :

<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>

4

1 回答 1

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>
于 2013-02-26T13:56:34.237 回答