This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: newbie problem - following-sibling
- From: "Hesselberth, Jan" <Jan dot Hesselberth at northernrock dot co dot uk>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 19 Apr 2002 13:42:28 +0100
- Subject: RE: [xsl] newbie problem - following-sibling
- Reply-to: xsl-list at lists dot mulberrytech dot com
Michael,
Thanks for that. It works perfectly. However, I have expanded it to produce
the total at the end of each SPV but I only get the first total each time.
For each SPV the code looks like
<xsl:template name="Details">
<xsl:param name="Style" select="'REPORT'"/>
<fo:table break-after="auto" space-after="10pt"
border-after-style="solid" border-after-width="1pt">
.
.
<fo:table-body>
<xsl:apply-templates select="following-sibling::*[1]"
mode="recurse"/>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="ACCDATA" mode="recurse">
<fo:table-row>
.
.
</fo:table-row>
<xsl:apply-templates select="following-sibling::*[1]"
mode="recurse"/>
</xsl:template>
<xsl:template match="TOTALS" mode="recurse">
<fo:table-row>
.
.
</fo:table-row>
<!--xsl:apply-templates select="following-sibling::*[1]"
mode="recurse"/--> (This line doesn't seem to make any difference)
</xsl:template>
<xsl:template match="SPV" mode="recurse"/>
I don't understand why it only processes the first TOTALS. I tried the
section on recursion in your book but to no avail. Perhaps I need to change
to the Muenchian technique.
Any help would be appreciated.
Regards
Jan
-----Original Message-----
From: Michael Kay [mailto:michael.h.kay@ntlworld.com]
Sent: 19 April 2002 11:08
To: xsl-list@lists.mulberrytech.com
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@ntlworld.com
work: Michael.Kay@softwareag.com
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of
> Hesselberth,
> Jan
> Sent: 19 April 2002 10:39
> To: XSL-List@lists.mulberrytech.com
> 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