我是 xslt 的新手,如果其中一个子元素属性值与特定字符串匹配,我需要从 xml 文件中删除整个节点。输入xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<gpm xmlns="http://www.airbus.com/topcased/gPM" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.airbus.com/topcased/gPM">
<version>1.2</version>
<version>1.2</version>
<filters>
<sheetFilter description=" " labelKey="Liste de distribution" hidden="false">
<userLogin>TO44452</userLogin>
<resultSummary>
<fieldResult name="DL_NAME"/>
<fieldResult name="DL_USERS"/>
<fieldResult name="$SHEET_STATE"/>
</resultSummary>
<scope>
<productScope name="$CURRENT_PRODUCT" includeSubProducts="false"/>
</scope>
<containers>
<sheetTypeRef name="DistributionList"/>
</containers>
</sheetFilter>
<sheetFilter .../>
....
</filters>
</gpm>
如果元素的名称属性与特定值匹配,我必须删除整个节点。
我使用的 xslt 文件是:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1"
xmlns="http://www.airbus.com/topcased/gPM"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gpmns="http://www.airbus.com/topcased/gPM"
exclude-result-prefixes="gpmns">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<!-- Delete extra blank lines -->
<xsl:strip-space elements="*"/>
<!-- template for any attribute node, copy -->
<xsl:template match="*|@*" name="copy_all">
<xsl:copy disable-output-escaping="yes">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="gpmns:sheetTypeRef[@name = 'DL']">
<xsl:apply-templates match="gpmns:sheetFilter"/>
</xsl:template>
</xsl:stylesheet>
我得到的转变是:
<?xml version="1.0" encoding="UTF-8"?>
<gpm xmlns="http://www.airbus.com/topcased/gPM" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.airbus.com/topcased/gPM">
<version>1.2</version>
<filters>
<sheetFilter description=" " labelKey="Liste de distribution" hidden="false">
<userLogin>TO44452</userLogin>
<resultSummary>
<fieldResult name="DL_NAME"/>
<fieldResult name="DL_USERS"/>
<fieldResult name="$SHEET_STATE"/>
</resultSummary>
<scope>
<productScope name="$CURRENT_PRODUCT" includeSubProducts="false"/>
</scope>
<containers/>
</sheetFilter>
<sheetFilter ..... />
提前致谢..