[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Sorting unique and sub-total problem

Subject: Sorting unique and sub-total problem
From: roger.wyatt@xxxxxxxxxxxxx
Date: Wed, 2 Jun 2004 16:27:42 +0100
xsl sort unique
I am struggling with what is turning out to be a rather nasty problem using
FOP  0.20.5 .  I have a set of unordered nodes along the lines of :...

      <ITEM item_id='1'>  <CARD number='123456789' \>  <AMOUNT amt='100'\>
</ITEM>
      <ITEM item_id='2'>  <CARD number='987654321' \>  <AMOUNT amt='30'\>
</ITEM>
      <ITEM item_id='3'>  <CARD number='123456789' \>  <AMOUNT amt='200'\>
</ITEM>
      <ITEM item_id='4'>  <CARD number='123456789' \>  <AMOUNT amt='50'\>
</ITEM>


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.  I have proven this to myself using
something along the lines of...

<xsl:for-each select=".//ITEM" >
<xsl:sort select="CARD/@number" order="ascending" />
      <fo:block>
            CUR NUMBER: <xsl:value-of select=".//CARD/@number"/>
            NXT NUMBER: <xsl:value-of select="following-sibling::
*/CARD/@number"/>
            CUR ID IS: <xsl:value-of select="./@item_id"/>
            NXT ID IS: <xsl:value-of select="following-sibling::
*/@item_id"/>
      </fo:block>
</xsl:for-each>

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

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

Thanks for any help in advance...

Roger.


***************************************
Roger Wyatt
Principal Consultant
Nomad Software Ltd.
***************************************
This e-mail (including attachments) is confidential and is intended solely
for the addressee.  Unless authorised you may not read, copy, use or store
this e-mail in any way, or permit others to do so.  If you have received it
in error, please contact Nomad Software on +44 (0) 20 7292 2400



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.