Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting a subtree and storing it in an xsl:variable
    primarykey
    data
    text
    <p>I'm working with an XSL stylesheet, and I'm trying to use the method shown <a href="https://stackoverflow.com/questions/2272123/how-sort-elements-and-store-them-in-a-variable-xslt/2272522#2272522">here</a> to store a sorted subtree as a variable. I'm using saxon 8.7 vis the xml-maven-plugin to transform my XML file. Here's the code that I have:</p> <pre><code>&lt;xsl:variable name="miniDays"&gt; &lt;xsl:for-each select="//day[position() &gt; $firstPosToShow]"&gt; &lt;xsl:sort select="@date" order="descending" /&gt; &lt;xsl:copy-of select=".|@*" /&gt; &lt;/xsl:for-each&gt; &lt;/xsl:variable&gt; </code></pre> <p>When I run the stylesheet, I get the following error:</p> <pre><code>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 </code></pre> <p>If I just set the subtree to the variable without sorting, it works, but it's not sorted:</p> <pre><code>&lt;xsl:variable name="miniDays" select="//day[position() &gt; $firstPosToShow]" /&gt; </code></pre> <p>If I set the copy-of statement's select to ".", it gets past that point, but gives me an error later on when I actually try to use the variable data. Here's how it's being used:</p> <pre><code>&lt;xsl:for-each select="exsl:node-set($miniDays)"&gt; &lt;xsl:variable name="in" select="local:calculate-total-in-days(.)" /&gt; &lt;!-- do some stuff with the var --&gt; &lt;/xsl:for-each&gt; </code></pre> <p>And the error: </p> <pre><code>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() </code></pre> <p>The function:</p> <pre><code>&lt;xsl:function name="local:calculate-total-in-days"&gt; &lt;xsl:param name="days" as="element()*" /&gt; &lt;!-- Do some calculations --&gt; &lt;/xsl:function&gt; </code></pre> <p>Am I using exsl:node-set incorrectly? And what should be in the copy-of's select, "." or ".|@*"?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload