xsl-list
[Top] [All Lists]

Re: Sorting unique and sub-total problem

2004-06-02 08:48:49
Roger,

At 11:27 AM 6/2/2004, you wrote:
The <ITEM> nodes can be in any order.  What I would like to get at the end
is the following out put.

      Card: 123456789  Total:350
      Card: 987654321  Total:  30

At the moment I can't even sort unique! I have tried to sort the nodes and
then compare the current node to the following sibling, using...

<xsl:for-each select=".//ITEM" >
<xsl:sort select="CARD/@number" order="ascending" />
      <xsl:if test="./CARD/@number[ not
(.=following-sibling::ITEM/CARD/@number) ]">
            ....print number etc. etc....

But what I have found is that the following sibling is as it would be if
the nodes have not been ordered.

Yes: the axes provide access to the document in its original order.

You have a fairly standard grouping problem. Grouping is a very common requirement that is not addressed well by XSLT 1.0 (it is a species of up-conversion), but for which a multitude of sophisticated techniques have nonetheless been devised.

Start researching them on the FAQ at http://www.dpawson.co.uk/xsl/sect2/sect21.html, and at Jeni's pages at http://www.jenitennison.com/xslt/grouping.

I fear that the only way to deal with this is to use XSLT to preorder the
nodes and then use a 2nd script using the same approach as described.

You could do this, but your problem does not look so difficult that you couldn't do it in one pass.

Alternatively I could go right back to the process that originally created
the XML file and order / sub total from there... something I really want to
avoid if at all possible.

This, however, is sometimes the best solution: sometimes the source comes out of a relational database, and relational technology is very good at this kind of operation.

Is there another approach I can take ?  Am I expecting too much from XSLT
with all this... ?

Nope. Just dig a little deeper under "grouping".

Good luck,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================



<Prev in Thread] Current Thread [Next in Thread>