Americo,
Thank you very much. It worked !!!
Anatoliy
-----Original Message-----
From: Américo Albuquerque
[mailto:aalbuquerque(_at_)viseu(_dot_)ipiaget(_dot_)pt]
Sent: Tuesday, May 06, 2003 6:36 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Nodes between two nodes with the same name (again :-(
Hi.
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
Smirnov, Anatoliy
Sent: Tuesday, May 06, 2003 1:48 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list