473,414 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

xslt - applying template to sequential group of nodes

Hi,

I have a problem I would like help solving:

My xml:

<node id=1>
<nodeContent>xyz</nodeContent>
</node>
<node id=2>
<nodeContent>xyz2</nodeContent>
</node>
<node id=3>
<nodeContent>xyz3</nodeContent>
</node>
<node id=4>
<nodeContent>xyz4</nodeContent>
</node>

I would like to use xslt to apply a <divtag between the 2nd and 4th
tag so that my the output will be

<div>
xyz2
xyz3
xyz4
</div>

I have tried using something like

<xsl:template match=""> </xsl:template but it seems that I cannot
set an opening div tag for 2 and a closing div tag for node 4 without
errors. i.e. the xml withing the xsl:template tag must be well
formed... Not much luck with if tags either...

TIA

Jun 21 '07 #1
3 1821
tuka wrote:
My xml:

<node id=1>
<nodeContent>xyz</nodeContent>
</node>
<node id=2>
<nodeContent>xyz2</nodeContent>
</node>
<node id=3>
<nodeContent>xyz3</nodeContent>
</node>
<node id=4>
<nodeContent>xyz4</nodeContent>
</node>

I would like to use xslt to apply a <divtag between the 2nd and 4th
tag so that my the output will be

<div>
xyz2
xyz3
xyz4
</div>
Those node elements need to have a parent element so write a template
for that parent element, assuming its tag name is 'some-element' use e.g.
<xsl:template match="some-element">
<div>
<xsl:apply-templates select="node[@id &gt;= 2 and @id &lt;=
4]/nodeContent"/>
</div>
</xsl:template>

<xsl:template match="nodeContent">
<xsl:value-of select="concat(., ' ')"/>
</xsl:template>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 21 '07 #2
Thanks,

It worked nicely
Tuka

Jun 21 '07 #3
<xsl:template match=""> </xsl:template>

The empty string is not a legal match patern.
errors. i.e. the xml withing the xsl:template tag must be well
formed.
XSLT is an XML language. XML must be well formed. Period. You can't
generate the open tag and close tag in separate templates. Generate them
at a higher-level template than the one generating the content.

Tutorials.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jun 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Iain | last post by:
I want to create an XML configuration file which might look like <REGION Name="Europe" WingDing="Blue"> <COUNTRY Name="UK" WingDing="white"> <TOWN Name="London" WingDing="Orange" /> </COUNTRY>...
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
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]<--
1
by: arnold | last post by:
Hi, I've been knocking my head against the wall trying to create an XSL transform to perform "normalizations" of a set of XML files that have a common structure. % XML file before transform
7
by: pstachy | last post by:
Hi all, I'm having problem with XSLT transformation concerned with sort and numberings at a time. I wish to have my registries sorted alfabetically and would like them to have numberings at a...
2
by: milecimm | last post by:
Hello, I need some help to solve the following problem (if it is possible, that's it): I'm using a xpath expression to programatically get data from my xml file. I want to transform ONLY the...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
4
by: MRe | last post by:
Hi, Is it possible using XSLT to transform this.. <test> <b>0</b> <a>1</a> <a>2</a> <b>3</b> <b>4</b>
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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...

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.