Xml 将节点属性复制到xslt中的新节点
我的xml如下所示:Xml 将节点属性复制到xslt中的新节点,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我的xml如下所示: <definitions xmlns:xxx="test.com" xmlns:yyy="test2.com" test="test"> </definitions> <test xmlns:xxx="test.com" xmlns:yyy="test2.com" test="test"> </test> <xsl:template match="definitions"> <xsl:elemen
<definitions xmlns:xxx="test.com" xmlns:yyy="test2.com" test="test">
</definitions>
<test xmlns:xxx="test.com" xmlns:yyy="test2.com" test="test">
</test>
<xsl:template match="definitions">
<xsl:element name="test">
<xsl:copy-of select="@*" />
</xsl:element>
</xsl:template>
我需要这样转换:
<definitions xmlns:xxx="test.com" xmlns:yyy="test2.com" test="test">
</definitions>
<test xmlns:xxx="test.com" xmlns:yyy="test2.com" test="test">
</test>
<xsl:template match="definitions">
<xsl:element name="test">
<xsl:copy-of select="@*" />
</xsl:element>
</xsl:template>
我编写了如下xslt:
<definitions xmlns:xxx="test.com" xmlns:yyy="test2.com" test="test">
</definitions>
<test xmlns:xxx="test.com" xmlns:yyy="test2.com" test="test">
</test>
<xsl:template match="definitions">
<xsl:element name="test">
<xsl:copy-of select="@*" />
</xsl:element>
</xsl:template>
这将产生:
<test test="test">
</test>
但是它不包含xmlns:xxx=“test.com”xmlns:yyy=“test2.com”
名称空间为什么
我怎样才能同时复制名称空间 名称空间也必须在XSL文件中声明:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xxx="test.com"
xmlns:yyy="test2.com">
名称空间也必须在XSL文件中声明:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xxx="test.com"
xmlns:yyy="test2.com">
似乎您只想将元素“definitions”重命名为“test”。 你可以用这样的东西
<xsl:template match="definitions">
<test>
<xsl:apply-templates select="@*" />
</test>
似乎您只想将元素“definitions”重命名为“test”。 你可以用这样的东西
<xsl:template match="definitions">
<test>
<xsl:apply-templates select="@*" />
</test>
它不包含xmlns:xxx=“test.com”xmlns:yyy=“test2.com”名称空间为什么
它不包含名称空间声明,因为它们没有在任何地方使用,所以XSLT处理器不会输出它们
我怎样才能同时复制名称空间
我不明白你为什么想要它们——但如果你坚持,你可以明确地复制它们:
<xsl:template match="definitions">
<test>
<xsl:copy-of select="@* | namespace::*" />
</test>
</xsl:template>
注意,当元素的名称已知时,不必使用xsl:element
它不包含xmlns:xxx=“test.com”xmlns:yyy=“test2.com”名称空间为什么
它不包含名称空间声明,因为它们没有在任何地方使用,所以XSLT处理器不会输出它们
我怎样才能同时复制名称空间
我不明白你为什么想要它们——但如果你坚持,你可以明确地复制它们:
<xsl:template match="definitions">
<test>
<xsl:copy-of select="@* | namespace::*" />
</test>
</xsl:template>
请注意,当元素的名称已知时,不必使用
xsl:element
。这假定名称空间事先已知。我认为问题在于复制输入可能包含的任何名称空间声明。这假设名称空间是预先知道的。我认为问题在于复制输入可能包含的任何名称空间声明。