我正在使用 XSL 样式表,并且正在尝试使用此处显示的方法将已排序的子树存储为变量。我正在使用 saxon 8.7 与 xml-maven-plugin 来转换我的 XML 文件。这是我的代码:
<xsl:variable name="miniDays">
<xsl:for-each select="//day[position() > $firstPosToShow]">
<xsl:sort select="@date" order="descending" />
<xsl:copy-of select=".|@*" />
</xsl:for-each>
</xsl:variable>
当我运行样式表时,我收到以下错误:
Error at xsl:copy-of on line 598 of file:/D:/home/Projects/src/main/xsl/site.xsl:
XTDE0420: Cannot create an attribute node (date) whose parent is a document node
如果我只是将子树设置为变量而不进行排序,它可以工作,但它没有排序:
<xsl:variable name="miniDays" select="//day[position() > $firstPosToShow]" />
如果我将复制语句的选择设置为“。”,它会超过那个点,但是稍后当我实际尝试使用变量数据时会给我一个错误。以下是它的使用方式:
<xsl:for-each select="exsl:node-set($miniDays)">
<xsl:variable name="in" select="local:calculate-total-in-days(.)" />
<!-- do some stuff with the var -->
</xsl:for-each>
和错误:
Error on line 676 of file:/D:/home/Projects/src/main/xsl/site.xsl:
XPTY0004: Required item type of first argument of local:calculate-total-in-days() is element(); supplied value has item type document-node()
功能:
<xsl:function name="local:calculate-total-in-days">
<xsl:param name="days" as="element()*" />
<!-- Do some calculations -->
</xsl:function>
我是否错误地使用了 exsl:node-set?什么应该在副本的选择中,“。” 还是“。|@*”?