473,729 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi,

following situation:

<xsl:variable name="newsartic les">
<xsl:call-template name="find_curr ent_newsarticle s"/>
</xsl:variable>

<!--
$newsarticles now contains something like

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

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

<xsl:for-each select="$newsar ticles">
<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="$newsar ticles"/> 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 10011
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="$newsar ticles">
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:2004102712 0145.66aeb2c5.s b****@reactor.d e... Hi,

following situation:

<xsl:variable name="newsartic les">
<xsl:call-template name="find_curr ent_newsarticle s"/>
</xsl:variable>

<!--
$newsarticles now contains something like

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

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

<xsl:for-each select="$newsar ticles">
<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="$newsar ticles"/> 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****@somewhe re.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
2225
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
8684
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 <COMPANY> <EMPLOYEE currentEmployee="true"> <NAME>Victor</NAME>
1
3682
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 destination file. During that process i must catch some nodes (e.g. <input> position of this node in XML tree is unknown )and change the value attribute. The destination xml file must be the exact copy of source file + changes on
4
1831
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
1400
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: <xsl:stylesheet xmlns:xsl=" http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="directions"> myNode = <xsl:value-of select="directions"/> </xsl:template>
4
3125
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. In Mozillae, it works to parse the serializeToString output, but this functionality doesn't exist for IE. I've made one function that loops through all the nodes & attributes and constructs a string that can be successfully parsed into xml, but...
12
2918
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 the file. Here is the code snippet: XPathDocument xdoc = new XPathDocument(fs); XPathNavigator nav = xdoc.CreateNavigator(); xslt.Transform(nav, null, strWriter, null);
18
2084
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 look up what each feature depends on and gerenate a text file. For example, in the following file, I would like to find out feature A depends on A1 and A2 and feature B depends on B1 and B2. And write that to a text file.
0
1225
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> <item xPos="20" yPos="10" layer="1">This is at layer one <item xPos="30" yPos="10" layer="1">This is 1st child of item one</item>
8
15899
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 case that i don't know how to solve, I need to concat a string from multiple childs into a standard way, the following is an example of the source and the target XML.
0
8913
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8144
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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 we have to send another system
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.