RE: [xsl] newbie problem - following-sibling

Subject: RE: [xsl] newbie problem - following-sibling
From: "Hesselberth, Jan" <Jan.Hesselberth@xxxxxxxxxxxxxxxxxx>
Date: Fri, 19 Apr 2002 14:10:02 +0100
Thanks for your help. I've sorted the TOTALS problem. It was to do with the
xsl:value-of select.
Cheers
	Jan

-----Original Message-----
From: Michael Kay [mailto:michael.h.kay@xxxxxxxxxxxx]
Sent: 19 April 2002 11:08
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] newbie problem - following-sibling


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
group.

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">
  <x>
    <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>

<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:
  generate-id(preceding-sibling::SPV[1]).

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>
>
> <REPORT>
> <SPV><SPVNAME>N</SPVNAME></SPV>
> <ACCDATA><MFACCNO>13990A-00189</MFACCNO><INTYRDATE>0</INTYRDAT
> E></ACCDATA>
> <ACCDATA><MFACCNO>51590X-00066</MFACCNO><INTYRDATE>0</INTYRDAT
> E></ACCDATA>
> <TOTALS><TOTCURBAL>3035525.63</TOTCURBAL><TOTNOACCS>6</TOTNOAC
> CS></TOTALS>
> <SPV><SPVNAME>QC006</SPVNAME></SPV>
> <ACCDATA><MFACCNO>43990Q-00189</MFACCNO><INTYRDATE>0</INTYRDAT
> E></ACCDATA>
> <ACCDATA><MFACCNO>49590P-00021</MFACCNO><INTYRDATE>0</INTYRDAT
> E></ACCDATA>
> <TOTALS><TOTCURBAL>3035525.63</TOTCURBAL><TOTNOACCS>6</TOTNOAC
> CS></TOTALS>
> </REPORT>
>
> 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
>
>
>
>
> --------------------------------------------------------------
> ------------
> CONFIDENTIALITY
> 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




-------------------------------------------------------------------------- 
CONFIDENTIALITY 
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


Current Thread