Re: [xsl] Grouping immediate follow sibling

Subject: Re: [xsl] Grouping immediate follow sibling
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Mon, 31 Jan 2005 16:44:46 +0100
Tempore 13:44:35, die 01/31/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Paul Clarke <pclarke@xxxxxxxxxxxxxxxx>:

Hello,

I receive XML similar to that shown below:>
	<ProgAbs>More text</ProgAbs>
	<ProgAbs>Even more</ProgAbs>
</bodyFrag>

Using 'following-sibling::ProgAbs' gives me all the siblings of that name,
as it should. I just need to know how to construct an expression to select
only those <ProgAbs> that follow on immendiately after the <p> element.
Hi,

In an XPath one-liner, that could be something like
'following-sibling::ProgAbs[count(current()|preceding-sibling::p[1])=1]'

But because of performance reasons, a recursive approach would be better I think.
e.g:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">


<xsl:template match="bodyFrag">
<xsl:apply-templates select="p"/>
</xsl:template>

<xsl:template match="p">
<h1><xsl:value-of select="."/></h1>
<p>
<xsl:apply-templates select="following-sibling::*[1][self::ProgAbs]"/>
</p>
</xsl:template>

<xsl:template match="ProgAbs">
<xsl:value-of select="."/>
<xsl:apply-templates select="following-sibling::*[1][self::ProgAbs]"/>
</xsl:template>

</xsl:stylesheet>


regards, -- Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041) Spread the wiki (http://www.wikipedia.org)

Current Thread