469,312 Members | 2,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

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

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 <sb****@reactor.de>

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
Jul 20 '05 #1
2 9806
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" <sb****@reactor.de> wrote in message
news:20041027120145.66aeb2c5.sb****@reactor.de... 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 <sb****@reactor.de>

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

Jul 20 '05 #2
On Wed, 27 Oct 2004 11:32:18 GMT
"Marrow" <ma****@somewhere.so.fu> 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 <sb****@reactor.de>

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
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Ruthless | last post: by
1 post views Thread by Victor | last post: by
1 post views Thread by Bartek | last post: by
4 posts views Thread by Chris Kettenbach | last post: by
5 posts views Thread by crazydiode | last post: by
8 posts views Thread by Hercules Dev. | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.