Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old June 21st, 2007, 12:45 PM
tuka
Guest
 
Posts: n/a
Default 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

  #2  
Old June 21st, 2007, 01:05 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: xslt - applying template to sequential group of nodes

tuka wrote:
Quote:
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/
  #3  
Old June 21st, 2007, 02:25 PM
tuka
Guest
 
Posts: n/a
Default Re: xslt - applying template to sequential group of nodes

Thanks,

It worked nicely
Tuka

  #4  
Old June 22nd, 2007, 12:05 AM
Joe Kesselman
Guest
 
Posts: n/a
Default Re: xslt - applying template to sequential group of nodes

<xsl:template match=""> </xsl:template>

The empty string is not a legal match patern.
Quote:
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
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles