[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] newbie problem - following-sibling

Subject: RE: [xsl] newbie problem - following-sibling
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 19 Apr 2002 11:08:00 +0100

This is a positional grouping problem: there's a logical group consisting of
an <SPV> element and its following-sibling <ACCDATA> and <TOTAL> elements up
to the next <SPV>, and there is no containing element to represent this

Positional grouping in XSLT 1.0 isn't easy. It is easy in XSLT 2.0, so I'll
show you that solution first:

<xsl:template match="REPORT">
<xsl:for-each-group select="*" group-starting-with="SPV">
    <xsl:for-each select="current-group()/ACCDATA">

You can try this using Saxon 7.0.

In XSLT 1.0 there are two approaches. The first is a recursive template
along the following lines (starting at an SPV element):

<xsl:apply-templates select="following-sibling::*[1]" mode="recurse"/>

<xsl:template match="ACCDATA" mode="recurse">
  process the ACCDATA
  <xsl:apply-templates select="following-sibling::*[1]" mode="recurse"/>

<xsl:template match="SPV|TOTAL" mode="recurse"/>
  <!-- this terminates the recursion -->

The second approach is to adapt the Muenchian technique for value-based
grouping, which you will find in textbooks or at www.jenitennison.com. This
groups elements that have a common value for a grouping key; in this case
the grouping key for ACCDATA elements (the thing that they all have in
common) is:

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of
> Hesselberth,
> Jan
> Sent: 19 April 2002 10:39
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] newbie problem - following-sibling
> Hi,
> I tried reading the book and searching the archive but
> couldn't find the
> answer.
> I have the following xlm. I want to process it as:
> for each <SPV> process each <ACCDATA> below the <SPV> until I
> get to the
> next <SVP>
> So in the xsl I did
> <xsl:for-each select="/REPORT/SPV">
> and tried various themes around
> 		<xsl:for-each select="following-sibling::ACCDATA">
> 		<xsl:if test="not(following-sibling::*[2][self::SPV])">
> (I know this isn't correct as it misses one ACCDATA)
> However, I allways get all ACCDATA for the first SPV. How do
> I break the
> processing when it gets to the next SPV?
> Any help would be greatly appreciated.
> Cheers
> 	Jan
> --------------------------------------------------------------
> ------------
> The information contained in this e-mail and any files
> transmitted with it
> is private and confidential. It is intended for the named
> addressee only.
> If you are not the intended addressee you are prohibited from
> storing, copying or using the information in any way.
> If you received this e-mail due to a transmission error
> please notify the
> sender immediately. No liability is accepted by Northern Rock
> for any losses caused by viruses contracted during transit
> over the Internet or present in any receiving system.
> This e-mail is not intended to create legally binding commitments on
> behalf of Northern Rock plc, nor do its contents reflect the
> corporate
> views or policies of Northern Rock plc.
> --------------------------------------------------------------
> ------------
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

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

Current Thread