[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Nodes between two nodes with the same name (again :-(
Subject: RE: [xsl] Nodes between two nodes with the same name (again :-( From: Américo Albuquerque <aalbuquerque@xxxxxxxxxxxxxxxx> Date: Tue, 6 May 2003 23:36:17 +0100 |
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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Nodes between two nodes with , Smirnov, Anatoliy | Thread | RE: [xsl] Nodes between two nodes w, Smirnov, Anatoliy |
[xsl] XPath question., Ben Trafford | Date | Re: [xsl] Importing stylesheets (ov, Karl J. Stubsjoen |
Month |