XSLT: iterating over a node-set stored in a variable

Discussion in 'XML' started by Steffen Beyer, Oct 27, 2004.

  1. Hi,

    following situation:

    <xsl:variable name="newsarticles">
    <xsl:call-template name="find_current_newsarticles"/>
    </xsl:variable>

    <!--
    $newsarticles now contains something like

    <news:article> ... </news:article>
    <news:article> ... </news:article>
    -->

    <xsl:if test="$newsarticles">
    <p>News</p>

    <xsl:for-each select="$newsarticles">
    <p>Article</p>

    <xsl:apply-templates select="."/>
    </xsl:for-each>
    </xsl:if>

    The body of the if-clause gets executed but the for-each doesn't loop at
    all. I'm really stuck - what XPath expression do I need to use here?

    BTW, this is of course not for-each specific. <apply-templates
    select="$newsarticles"/> does not work either.

    Regards,
    --
    Steffen Beyer <>

    GnuPG key fingerprint: CA00 1611 242B 89D4 E643 E235 05F3 7689 DD3E EB26
    Public key available upon request or at http://wwwkeys.de.pgp.net
     
    Steffen Beyer, Oct 27, 2004
    #1
    1. Advertising

  2. Steffen Beyer

    Marrow Guest

    Re: iterating over a node-set stored in a variable

    Hi Steffen,

    Your variable $newsarticles will contain an RTF (result tree fragment) - in
    XSLT 1.0 RTFs cannot be used as a node-set therefore this line...

    > <xsl:for-each select="$newsarticles">


    should raise a transformation error. Having said that, some transformation
    engines do allow RTFs to be used as node-sets without conversion.

    Your transformation may support an extension function that enables you to
    convert RTFs to node-sets (e.g. xxx:Node-set() - where 'xxx' will be an
    appropriate extension prefix). Or your transformation engine may support
    EXSLT (www.exslt.org) in which case you should be able to use
    exsl:node-set().

    HTH
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator


    "Steffen Beyer" <> wrote in message
    news:...
    > Hi,
    >
    > following situation:
    >
    > <xsl:variable name="newsarticles">
    > <xsl:call-template name="find_current_newsarticles"/>
    > </xsl:variable>
    >
    > <!--
    > $newsarticles now contains something like
    >
    > <news:article> ... </news:article>
    > <news:article> ... </news:article>
    > -->
    >
    > <xsl:if test="$newsarticles">
    > <p>News</p>
    >
    > <xsl:for-each select="$newsarticles">
    > <p>Article</p>
    >
    > <xsl:apply-templates select="."/>
    > </xsl:for-each>
    > </xsl:if>
    >
    > The body of the if-clause gets executed but the for-each doesn't loop at
    > all. I'm really stuck - what XPath expression do I need to use here?
    >
    > BTW, this is of course not for-each specific. <apply-templates
    > select="$newsarticles"/> does not work either.
    >
    > Regards,
    > --
    > Steffen Beyer <>
    >
    > GnuPG key fingerprint: CA00 1611 242B 89D4 E643 E235 05F3 7689 DD3E EB26
    > Public key available upon request or at http://wwwkeys.de.pgp.net
     
    Marrow, Oct 27, 2004
    #2
    1. Advertising

  3. Re: iterating over a node-set stored in a variable

    On Wed, 27 Oct 2004 11:32:18 GMT
    "Marrow" <> wrote:

    > Your transformation may support an extension function that enables you
    > to convert RTFs to node-sets (e.g. xxx:Node-set() - where 'xxx' will be
    > an appropriate extension prefix). Or your transformation engine may
    > support EXSLT (www.exslt.org) in which case you should be able to use
    > exsl:node-set().


    I'm using LibXSLT - libxslt:node-set() and exsl:node-set() do both work
    and solve my problem.

    Thanks a lot!

    Regards,
    --
    Steffen Beyer <>

    GnuPG key fingerprint: CA00 1611 242B 89D4 E643 E235 05F3 7689 DD3E EB26
    Public key available upon request or at http://wwwkeys.de.pgp.net
     
    Steffen Beyer, Oct 27, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,465
  2. Ralf Wahner
    Replies:
    2
    Views:
    2,409
    Ralf Wahner
    Jul 15, 2003
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,437
    Dimitre Novatchev
    Aug 24, 2006
  4. Replies:
    3
    Views:
    3,842
    A. Bolmarcich
    Oct 20, 2006
  5. njsimha
    Replies:
    0
    Views:
    783
    njsimha
    Sep 16, 2008
Loading...

Share This Page