Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to store node set in a variable based on choose-when condition
    text
    copied!<p>I have following XML structure</p> <pre><code>&lt;pages&gt; &lt;page id="8992" filename="news7" extension=".aspx" title="News 7" real="True" virtual="False" visible="True" day="18" month="3" year="2010" /&gt; &lt;page id="8991" filename="news6" extension=".aspx" title="News 6" real="True" virtual="False" visible="True" day="18" month="3" year="2010" /&gt; &lt;page id="8990" filename="news5" extension=".aspx" title="News 5" real="True" virtual="False" visible="True" day="18" month="3" year="2010" /&gt; &lt;page id="8883" filename="news2" extension=".aspx" title="News 2" real="True" virtual="False" visible="True" day="15" month="2" year="2010" /&gt; &lt;page id="8989" filename="news4" extension=".aspx" title="News 4" real="True" virtual="False" visible="True" day="18" month="3" year="2009" /&gt; &lt;/pages&gt; </code></pre> <p>Now there is a variable </p> <pre><code>&lt;xsl:variable name="valid_pages"/&gt; </code></pre> <p>I want to store /pages/page in a variable based on following conditions</p> <pre><code>&lt;xsl:variable name="valid_pages"&gt; &lt;xsl:when test="count(/pages/page) &amp;lt; 2"&gt; &lt;xsl:value-of select="/pages/page[0]" /&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="/pages/page[position() &amp;gt; 2]" /&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:variable&gt; </code></pre> <p>now when I use</p> <pre><code>&lt;xsl:value-of select="count($valid_pages)" /&gt; </code></pre> <p>I get an error </p> <blockquote> <p><code>To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function</code></p> </blockquote>
 

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