[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] (How) can I randomly access the result of a
Subject: Re: [xsl] (How) can I randomly access the result of a <xsl:for-each select="...?
From: Ferdinand Soethe <xsl-list@xxxxxxxxxx>
Date: Sat, 15 Oct 2005 09:09:50 +0200


Thanks everybody for your quick responses. I'm one major step closer
to my goals now.

Yet I seem to be missing something in this part if Michaels code:

> First, you put the result in a variable:

> <xsl:variable name="x">
>   <xsl:for-each select=...
>     <something/>
>   </xsl:for-each>
> </xsl:variable>

Still XSLT 1.0:

If I do

 <xsl:variable name="fragment" select="//ul"/>

(not using a for-each) everything works fine and I can cast the
variable to a nodeset and access it as documented.

However if I try

<xsl:variable name="fragment">
    <xsl:for-each select="//ul">
        <xsl:copy-of select="."/>
    </xsl:for-each>
</xsl:variable>

or

<xsl:variable name="fragment">
    <xsl:for-each select="//ul">
        <xsl:value-of select="."/>
    </xsl:for-each>
</xsl:variable>


I only get a count() of 1 when transforming this test-document:

<?xml version="1.0" encoding="UTF-8"?>
<html>
    <head></head>
    <body>
        <ul id="1">
            <li id="11">Listenpunkt 11</li>
            <li id="12">Listenpunkt 12</li>
            <li id="13">Listenpunkt 13</li>
            <li id="14">Listenpunkt 14</li>
        </ul>  
        <ul id="2">
            <li id="21">Listenpunkt 21</li>
            <li id="22">Listenpunkt 22</li>
            <li id="23">Listenpunkt 23</li>
            <li id="24">Listenpunkt 24</li>
        </ul>    
        <ul id="3">
            <li id="31">Listenpunkt 31</li>
            <li id="32">Listenpunkt 32</li>
            <li id="33">Listenpunkt 33</li>
            <li id="34">Listenpunkt 34</li>
        </ul>    
    </body>
</html>

Any ideas what I got wrong here?

--
Ferdinand Soethe

(Btw: Xalan seems to also support the common:node-set function from
 the xmlns:common="http://exslt.org/common" namespace, so I used that
 for portability)


Current Thread
Keywords