[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Nodes between two nodes with the same name (again

Subject: RE: Nodes between two nodes with the same name (again :-(
From: Américo Albuquerque <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Tue, 6 May 2003 23:36:17 +0100
xsl nodes
Hi.

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Smirnov, Anatoliy
> Sent: Tuesday, May 06, 2003 1:48 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Nodes between two nodes with the same name (again :-(
> 
> 
> 
> I need to output all nodes between two nodes with the same 
> name, so that from the node <h> becomes the HEADER and all 
> nodes after <h> until the next <h> become the BODY. The 
> source file is: 
>  
> <html>
>   <body>
> 
>     <h> Header </h>
> 
>     <p> A </p>
>     <dl>
>       <dt> B </dt>
>       <dt> C </dt>
>     </dl>
> 
>     <h>Header </h>
> 
>     <p> D </p>
>     <dl>
>       <dt>
>         <dt> E </dt>
>       </dt>
>     </dl>
>     <p> F </p>
> 
>   </body>
> </html>
> 
> I need to have this output 
> 
> <ROWSET>
>   <ROW>
>    <HEADER> Header </HEADER>
>    <BODY> ABC </BODY>
>   </ROW>
>   <ROW>
>    <HEADER> Header </HEADER>
>    <BODY> DEF </BODY>
>   </ROW>
> <ROWSET>
> 

Try this:
 <xsl:template match="/html">
  <ROWSET>
   <xsl:apply-templates select="body/h"/>
  </ROWSET>
 </xsl:template>
 
 <xsl:template match="h">
  <ROW>
   <HEADER><xsl:apply-templates/></HEADER>
   <BODY><xsl:apply-templates
select="following-sibling::*[generate-id(following-sibling::h[1])=genera
te-id(current()/following-sibling::h[1])]"/></BODY>
  </ROW>
 </xsl:template>

Notice the match="/html" on the first template. This is so I start
applying templates only on /html. In this template I set wrapper node
<ROWSET> and apply-templates to body/h nodes only. This prevents the
text nodes from appearing in between <ROW> nodes.

Hope this helps you

(...)




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.