请原谅我对 XSLT 的无知,我对它还很陌生。
使用 saxon xslt 2.0:我试图从 xsl:variable 中获取单个元素,在应用时看起来像这样<xsl:copy-of select="$type">
:
<type>
<label>Book</label>
<id>book</id>
</type>
仅尝试访问 id 元素-我尝试过:
<xsl:copy-of select="$type/id">
<xsl:copy-of select="$type[2]">
<xsl:value-of select="$type/id">
<xsl:value-of select="$type[2]">
也试过这个和一些变种
<xsl:value-of select="$type[name()='id']"/>
并尝试更改数据类型
<xsl:variable name="type" as="element">
使用 XSLT 2.0 node-set() 操作似乎并不适用。
我寻求有关如何正确访问 xsl:variable 元素的详细描述,并且很高兴发现我使用这一切都错了,有更好的方法。感谢您的见解和努力。
@martin-honnen 添加时:
<xsl:variable name="test1">
<type>
<label>Book</label>
<id>book</id>
</type>
</xsl:variable>
<TEST1><xsl:copy-of select="$test1/type/id"/></TEST1>
<xsl:variable name="test2" as="element()">
<type>
<label>Book</label>
<id>book</id>
</type>
</xsl:variable>
<TEST2><xsl:copy-of select="$test2/id"/></TEST2>
我得到结果:
<TEST1/>
<TEST2/>