对于XSL文件,我有以下输入:
<node>
<xsl:value-of select="ROOT/LEVEL1/LEVEL2" />
</node>
我的预期输出是:
<node2>
<xsl:value-of select="ROOT/LEVEL1/LEVEL2" />
</node2>
如何获得此功能?
我能做的最好的是:
<xsl:template match="node" >
<node2>
<xsl:copy-of select="." />
</node2>
</xsl:template>
这会产生:
<node2><node>
<xsl:value-of select="ROOT/LEVEL1/LEVEL2"/>
</node></node2>
发布于 2012-05-18 08:11:50
执行<xsl:copy-of select="." />
将复制现有节点,但在本例中,您只想复制子节点。相反,试试这个
<xsl:copy-of select="node()" />
实际上,使用身份模板可能更好,因为这将允许您对节点元素的子元素进行进一步的转换,而不仅仅是按原样复制。例如:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node">
<node2>
<xsl:apply-templates select="@*|node()"/>
</node2>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
https://stackoverflow.com/questions/10647658
复制