我试图在变量声明中使用Textbox2
,但它似乎没有效果。
输入XML:
xsl:perform-sort
变换:
<root>
<section>
<seq>2</seq>
</section>
<section>
<seq>1</seq>
</section>
</root>
输出:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/*">
<xsl:comment>using perform-sort</xsl:comment>
<xsl:variable name="vSections" as="element() *">
<xsl:perform-sort select="section">
<xsl:sort data-type="number" select="seq" />
</xsl:perform-sort>
</xsl:variable>
<xsl:sequence select="$vSections/seq" />
<xsl:comment>using for-each</xsl:comment>
<xsl:for-each select="section">
<xsl:sort data-type="number" select="seq" />
<xsl:sequence select="seq" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我希望<!--using perform-sort--><seq>2</seq><seq>1</seq><!--using for-each--><seq>1</seq><seq>2</seq>
变量中的xsl:perform-sort
对其中包含的vSections
元素进行排序。
我正在试图弄清楚section
我做错了什么。
答案 0 :(得分:1)
在<xsl:sequence select="$vSections/seq" />
中,您使用按文档顺序(https://www.w3.org/TR/xpath-31/#id-path-operator)排序的步骤/seq
,因此您需要<xsl:sequence select="$vSections!seq" />
(我认为它是XPath 3.0)或{{ 1}}