Re: [xsl] Selecting a range of siblings between specified elements: resend

Subject: Re: [xsl] Selecting a range of siblings between specified elements: resend
From: David Holden <dh@xxxxxxxx>
Date: Mon, 8 Mar 2004 16:58:56 +0000
On Monday 08 March 2004 14:03, David Holden wrote:

Hello,

 thanks to everyone for their reply it helped alot. To summarise, given the 
following XML file:



<?xml version="1.0"?>
<doc>
<a>cont1</a><b id="b1"/><b id="b2"/>
<a>cont2</a><b id="b3"/><b id="b4"/>
<a>cont3</a><b id="b5"/><b id="b6"/><c/><c/>
<a>cont4</a><b id="b7"/><b id="b8"/><b id="b9"/><c/><c/>
</doc>


The following XSLT file demonstrates what I needed:-

<?xml version="1.0"?>
<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 version="1.0" >
  <xsl:output method="xml"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="/">
    <xsl:for-each select="//a">
      <!-- iterate over grouped b's -->
      <xsl:text>Group </xsl:text>
      <xsl:value-of select="position()"/>
      <xsl:text> </xsl:text>
      <xsl:for-each 
select="following-sibling::b[generate-id(preceding-sibling::a[1]) = 
generate-id(current()) ]">
        <xsl:value-of select="./@id"/>
      </xsl:for-each>
      <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>


Cheers,

       Dave.

> Hello,
>
> I'm currently a little puzzled on how to select a range of siblings between
> specified elements, e.g.
>
> <?xml version="1.0"?>
> <doc>
> <a>cont1</a><b/><b/>
> <a>cont2</a><b/><b/>
> <a>cont3</a><b/><b/><c/><c/>
> <a>cont4</a><b/><b/><c/><c/>
> </doc>
>
>
> I would like to select firstly the <b/><b/> of
>
> <a>cont1</a><b/><b/>
>
> then the <b/><b/> of
>
> <a>cont2</a><b/><b/>
>
> then the <b/><b/> of
>
> <a>cont3</a><b/><b/><c/><c/>
>
> and finally the <b/><b/> of
>
> <a>cont4</a><b/><b/><c/><c/>
>
>
> So:
>
> /doc/a[1]/following-sibling::*
>
> will select all elements after the first <a>
>
> how do I reduce this to just the <b/><b/> before the second <a>
>
> and similarly for the <b/><b/> between the all the other <a>'s.
>
>  thanks.
>
>  Dave.

-- 
Dr. David Holden. (Systems Developer)
Crystallography Journals Online: <http://journals.iucr.org>

Thanks in advance:-
Please avoid sending me Word or PowerPoint attachments.
See: <http://www.fsf.org/philosophy/no-word-attachments.html>

UK Privacy (R.I.P)  : http://www.stand.org.uk/commentary.php3
Public GPG key available on request.
-------------------------------------------------------------

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


Current Thread