Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 标识转换与其他模板一起使用时的奇怪行为_Xslt_Transform_Xslt 2.0_Identity - Fatal编程技术网

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,这就是我想要的:

我见过奇怪的行为,用奇怪的意思来说,它的行为与我们通常的情况相反。 详情如下:

XSLT代码



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