Xslt 标识转换与其他模板一起使用时的奇怪行为
我见过奇怪的行为,用奇怪的意思来说,它的行为与我们通常的情况相反。 详情如下: XSLT代码Xslt 标识转换与其他模板一起使用时的奇怪行为,xslt,transform,xslt-2.0,identity,Xslt,Transform,Xslt 2.0,Identity,我见过奇怪的行为,用奇怪的意思来说,它的行为与我们通常的情况相反。 详情如下: XSLT代码 源XML 我不确定你的期望是基于什么 第一个模板的优先级为0.5,而第二个(身份转换)模板的优先级为-0.5 因此,应用于其include属性为1的所有子元素的模板是第一个模板此模板为空,因此不输出任何内容。因此,输出中不会出现具有include属性1的child元素 所有其他节点由第二个模板匹配,该模板将它们(以及通过递归,它们的后代)复制到输出 谢谢@michael,这就是我想要的:
源XML
我不确定你的期望是基于什么
第一个模板的优先级为0.5,而第二个(身份转换)模板的优先级为-0.5
因此,应用于其include
属性为1
的所有子元素的模板是第一个模板此模板为空,因此不输出任何内容。因此,输出中不会出现具有include
属性1
的child
元素
所有其他节点由第二个模板匹配,该模板将它们(以及通过递归,它们的后代)复制到输出 谢谢@michael,这就是我想要的:)
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:template match="child[@include='1']"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<?xml version="1.0" encoding="UTF-8"?>
<Parent>
<child include='1'>
<Attribute>Attribute1</Attribute>
</child>
<child include='1'>
<Attribute>Attribute2</Attribute>
</child>
<child include='0'>
<Attribute>Attribute3</Attribute>
</child>
<child include='0'>
<Attribute>Attribute4</Attribute>
</child>
</Parent>
<Parent>
<child include="0">
<Attribute>Attribute3</Attribute>
</child>
<child include="0">
<Attribute>Attribute4</Attribute>
</child>
</Parent>
<xsl:template match="child[@include='1']"/>
<Parent>
<child include="1">
<Attribute>Attribute3</Attribute>
</child>
<child include="1">
<Attribute>Attribute4</Attribute>
</child>
</Parent>