Re: [xsl] Grouping by an attribute of a child

Subject: Re: [xsl] Grouping by an attribute of a child
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 14 Apr 2003 15:45:47 +0100
You haven't really shown the necessary parts of your stylesheet,
but guessing...

If this template:

   <xsl:template match="Invoices/Invoice/Activity">
     <xsl:if test="position()!=1">
         <xsl:if test="Attribute[@Name='Railcar
Number']/Value=preceding-sibling

Is called by an xl:apply-templates that is using xsl:sort, then

position() will refer to the sorted order as you intend, but
preceding-sibling:: always refers to nodes in the input tree so is
unaffected by xsl:sort.

For simple cases your problem is a grouping problem solvable by keys see
Jeni Tennison's site or at least three answers already posted today
on this list. However if you need to do any complicated totalling and
reporting of the sorted/grouped set it will be much easier to do it in
two passes.

First group the input nodes sorting them into order and wrapping each
group in a wrapper element.

then process this new tree, using the template for the wrapper element
to trigger adding total lines etc.

You can either generate a temporary document and process on teh second
pass with a new stylesheet, or do it all in one pass using xalan's
node-set extension function.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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


Current Thread