我正在尝试使用具有模式的应用模板和应用模板,如下例中所述:
我的输入 xml 看起来像:
<catalog>
<product dept="aaa">
<number>111</number>
<name>cap</name>
<color>blue</color>
</product>
<product dept="bbb">
<number>222</number>
<name>bat</name>
<color>white</color>
</product>
<product dept="ccc">
<number>333</number>
<name>bag</name>
<color>red</color>
</product>
现在我正在尝试使用下面显示的 xslt 来删除带有 dept=bbb 的产品元素,但它不起作用。相同的输入 xml 出现在输出中。我知道我可以通过删除最后一个模板上的 mode 属性来实现我想要的结果,但我试图理解为什么它不能以我在这里尝试的方式工作。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" version="1.0" exclude-result-prefixes="exsl">
<xsl:template match="/">
<xsl:variable name="modXml">
<xsl:apply-templates />
<xsl:apply-templates mode="remove" />
</xsl:variable>
<xsl:copy-of select="exsl:node-set($modXml)/*" />
</xsl:template>
<xsl:template match="node( ) | @*">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="/catalog/product[@dept='bbb']" mode="remove" />
</xsl:stylesheet>
有人可以解释一下 XSLT 处理器是如何在这里运行转换的吗?
非常感谢..!