我可以使用什么代码来代替 <xsl:copy-of select="tag"/>
,当应用于以下 xml 时..
<tag>
content
<a>
b
</a>
</tag>
..会给出以下结果:?
content
<a>
b
</a>
我希望回显其中的所有内容,但不包括父标签
<小时/>基本上,我的 xml 文件中有几部分内容,采用 html 格式,按 xml 标签分组
我希望有条件地访问它们并回显它们
例如:<xsl:copy-of select="description"/>
生成的额外父标签不会影响浏览器渲染,但它们是无效标签,我希望能够删除它们
我是否以完全错误的方式处理这个问题?
最佳答案
由于您还想包含 content
部分,因此您需要 node()
函数,而不是 *
运算符:
<xsl:copy-of select="tag/node()"/>
我已经在输入示例上对此进行了测试,结果是示例结果:
content
<a>
b
</a>
如果不硬编码根节点名称,这可以是:
<xsl:copy-of select="./node()" />
当您已经在处理根节点并想要内部所有元素(不包括根节点)的精确副本时,这非常有用。例如:
<xsl:variable name="head">
<xsl:copy-of select="document('head.html')" />
</xsl:variable>
<xsl:apply-templates select="$head" mode="head" />
<!-- ... later ... -->
<xsl:template match="head" mode="head">
<head>
<title>Title Tag</title>
<xsl:copy-of select="./node()" />
</head>
</xsl:template>
关于xslt - xsl :copy-of excluding parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1755661/