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

Steffen Beyer

Usenet Archive
Joined
Apr 17, 2001
Messages
7
Reaction score
0
Hi,

following situation:

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

<!--
$newsarticles now contains something like

<... </<... </-->

<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,
 

Marrow (2)

Usenet Archive
Joined
Nov 19, 2003
Messages
37
Reaction score
0
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

Usenet Archive
Joined
Apr 17, 2001
Messages
7
Reaction score
0
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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top