我正在将一种XML转换为另一种。假设我们从这里开始的XML看起来像这样
<fruit id="123">
<apple></apple>
<banana></banana>
<lemon></lemon>
</fruit>
现在,在转换后的XML中,我想使用旧XML中的id属性值创建一个新属性。
我试图这样做:
<xsl:template match="fruit">
<xsl:attribute name="reference">
<xsl:value-of select="fruit/@id"/>
</xsl:attribute>
</xsl:template>
我收到此错误:
cannot create an attribute node whose parent is a document node
有人可以向我解释我在做什么错,因为我不理解错误。一个解决方案将是不错的。
谢谢!
问题在于文档节点不能具有属性,并且您没有在输出树中为要应用的属性创建元素。文档节点还必须具有一个Element子元素。
像下面这样的东西应该起作用。
<xsl:template match="fruit">
<fruit>
<xsl:attribute name="reference">
<xsl:value-of select="@id"/>
</xsl:attribute>
</fruit>
</xsl:template>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句