473,466 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 9984
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: <struct> <node level="1" no="1">
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 them all. For example, this is the company now ...
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, attribute, text, comments etc. from source and write in...
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 does not return a DOM node. registration)=1]<--
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 own node. I defined the xslt as follows: ...
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 on the Node, which is coded correctly as XHTML....
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) it is taking between 1hr-2hrs to just transform...
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' element. i.e. for each <featuresI would like to...
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 version="1.0" encoding="UTF-8"?> <page> ...
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 another XML, I use xslt and it works, but there is a...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.