【发布时间】:2018-01-31 12:08:37
【问题描述】:
<xsl:template match="BaseNode">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates/>
<None attr1="0" attt2="1" attr2="0">
<xsl:apply-templates select="//BaseNode/BasicDouble[@Descr = 'Input A']"/>
<xsl:apply-templates select="//BaseNode/BasicDouble[@Descr = 'Input B']"/>
</None>
</xsl:copy>
</xsl:template>
上面是我尝试使用的 XSLT 将现有子节点移动到新创建的节点。 该规则正在创建新节点并将节点复制为子节点。 问题是我在父节点中仍然有旧元素。 我想要的是剪切和粘贴操作,而不是复制粘贴。 预先感谢您的帮助。
输入 XML
<ParentNode attr1="1" attr2="2">
<BasicInt attr1="1" attr2="2"/>
<BasicInt attr1="1" attr2="2"/>
<BasicDouble attr1="1" attr2="2"/>
<BasicEnum attr1="1" attr2="2"/>
<Pair Key="0" Value="a"/>
<Pair Key="1" Value="b"/>
<Pair Key="2" Value="c"/>
<Pair Key="3" Value="d"/>
</BasicEnum>
<BasicDouble attr1="1" attr2="2"/>
<BasicDouble attr1="1" attr2="2"/>
</ParentNode>
期望的输出
<ParentNode attr1="1" attr2="2">
<BasicInt attr1="1" attr2="2"/>
<BasicInt attr1="1" attr2="2"/>
<BasicDouble attr1="1" attr2="2"/>
<BasicEnum attr1="1" attr2="2"/>
<Pair Key="0" Value="a"/>
<Pair Key="1" Value="b"/>
<Pair Key="2" Value="c"/>
<Pair Key="3" Value="d"/>
</BasicEnum>
<NewElement>
<BasicDouble attr1="1" attr2="2"/>
<BasicDouble attr1="1" attr2="2"/>
</NewElement>
</ParentNode>
使用我的规则获得输出
<ParentNode attr1="1" attr2="2">
<BasicInt attr1="1" attr2="2"/>
<BasicInt attr1="1" attr2="2"/>
<BasicDouble attr1="1" attr2="2"/>
<BasicEnum attr1="1" attr2="2"/>
<Pair Key="0" Value="a"/>
<Pair Key="1" Value="b"/>
<Pair Key="2" Value="c"/>
<Pair Key="3" Value="d"/>
</BasicEnum>
<BasicDouble attr1="1" attr2="2"/>
<BasicDouble attr1="1" attr2="2"/>
<NewElement>
<BasicDouble attr1="1" attr2="2"/>
<BasicDouble attr1="1" attr2="2"/>
</NewElement>
【问题讨论】:
-
请共享输入 XML 和所需的输出 XML,以便共享的 XSLT 可用于重现问题。
-
只是猜测:尝试删除
<xsl:apply-templates/>元素。 -
通过删除
我需要的其余子节点不会被复制。 -
如果您使用的是 XSLT 1.0 处理器(并且不打算升级),请不要标记问题 XSLT 2.0。