OP 在评论中澄清他的问题是:
是否可以创建没有任何父元素的属性节点?
是的,在 XSLT 2.0 中可以这样写:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vAttr" as="attribute()">
<xsl:attribute name="x">y</xsl:attribute>
</xsl:variable>
<xsl:template match="/*">
<xsl:copy>
<xsl:copy-of select="$vAttr"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
当此转换应用于以下 XML 文档时:
<t/>
Run Code Online (Sandbox Code Playgroud)
产生了想要的正确结果:
<t x="y"/>
Run Code Online (Sandbox Code Playgroud)
因此,该属性被创建为没有任何父元素的独立项。然后,我们可以将它的实例复制到任何元素上。
| 归档时间: |
|
| 查看次数: |
4772 次 |
| 最近记录: |