472,333 Members | 1,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

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 9928
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ruthless | last post by:
hello. All XML and XSLT are processed by preprocessor as a trees. How can i simply display my XML as some kind of tree. given xml: ...
1
by: Victor | last post by:
Hi, this might sound silly but I cannot figure out how to incorporate some XML of employees into some XML of a company to give new XML containing...
1
by: Bartek | last post by:
Hello This is my problem: It consider xml 2 xml conversion. source document had unknown structure (xhtml), xslt must process every node,...
4
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression...
5
by: crazydiode | last post by:
HI All, I am new to XSLT. I am trying to use xslt with xml in my java code. I am basically trying to replace one node of the original xml with my...
4
by: elsigh | last post by:
I'm wondering if anyone has any ideas about a way to quickly convert an HTML DOM Node into an XML Document. The goal is that I want to perform XSLT...
12
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB)...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features'...
0
by: krina | last post by:
I am new in this field and have just started learning XML and xslt, Now I am having a XML file.......having structure as follows..... <?xml...
8
by: Hercules Dev. | last post by:
Hi all, I'm new in xslt and xpath, so my question might be simple but i'm learning. I have an XML document and need to transform it into...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.