如何使用 XSLT 制作 xml 节点的子节点的精确副本?
问题描述:
我的问题是我的 XML 文档中包含 XHTML 片段,在通过 XSLT 传递它时,我希望它呈现这些片段而不破坏它们.
My problem is that my XML document contains snippets of XHTML within it and while passing it through an XSLT I would like it to render those snippets without mangling them.
我尝试将代码片段包装在 CDATA 中,但它不起作用,因为小于和大于被转换为 <和 >而不是直接回显.
I've tried wrapping the snippet in a CDATA but it doesn't work since less than and greater than are translated to < and > as opposed to being echoed directly.
这样做需要什么 XSL?
What's the XSL required for doing this?
答
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
这在 XSLT 规范中称为身份转换".
This is referred to as the "identity transformation" in the XSLT specification.