Altova Mailing List Archives


RE: [xsl] Grouping is not working that great over here

From: "Michael Kay" <mhk@--------->
To:
Date: 4/11/2003 3:29:00 AM
I haven't looked through this in detail, but if X has no date child,
then X[date=$date] will always select nothing (any "=" comparison with
an empty node-set returns false). If you want two non-existent dates to
compare equal, force the value to a string: X[string(date)=$date] - do
this wherever you use the date as a grouping key.

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 
> Matts Isuls
> Sent: 11 April 2003 06:32
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Subject: [xsl] Grouping is not working that great over here
> 
> 
> Hi
> 
> Having problems grouping (first timer). Someone please help 
> me out of this darkness.
> 
> thanks,
> Matts Isuls
> 
> 
> 
> I get this:
> 
> ------
> 20030404::1
> 20030405::2
> ------
> ::0
> 20030101::2
> ::0
> ------
> 20030202::2
> 20030303::1
> ------
> ::0
> ::0
> ------
> ::0
> ::0
> 
> but would like to get this:
> ------
> 20030404::1
> 20030405::2
> ------
> 20030101::2
> 20030404::1
> 20030405::2
> ------
> 20030202::2
> 20030303::1
> 20030404::1
> ------
> 20030404::1
> 20030405::2
> ------
> 20030404::1
> 
> ----------
> ---XSL----
> ----------
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <!-- leave payment nodes without date out -->
> <xsl:key name="mkey" match="payments/payment[date]" use="date"/>
> 
> <xsl:template match="/">
>         <xsl:apply-templates select="parcels" /> 
> </xsl:template> <xsl:template match="parcels">
>         <xsl:apply-templates select="parcel" />
> </xsl:template>
> 
> <xsl:template match="parcel">
>    <br/>        ------
>     <xsl:for-each 
> select="payments/payment[count(.|key('mkey',date)[1])=1]">
>       <xsl:sort select="date" />
>       <xsl:variable name="date" select="date" />
>       <xsl:variable name="tot"
>          select="sum(../../payments/payment[date=$date]/amount)" />
>                         <br/><xsl:value-of select="$date" />
>                         ::<xsl:value-of select="$tot" />
>     </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
> 
> ----------
> --XML-----
> ----------
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- <date> in <payment> may be missing -->
> <!-- normaly there is more data here but cut that out --> <parcels>
>         <parcel>
>                 <payments>
>                         <payment>
>                                 <date>20030404</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030405</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030405</date>
>                                 <amount>1</amount>
>                         </payment>
>                 </payments>
>         </parcel>
>         <parcel>
>                 <payments>
>                         <payment>
>                                 <amount>449</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030101</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030404</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030405</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030101</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030405</date>
>                                 <amount>1</amount>
>                         </payment>
>                 </payments>
>         </parcel>
>         <parcel>
>                 <payments>
>                         <payment>
>                                 <date>20030202</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030303</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030404</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030202</date>
>                                 <amount>1</amount>
>                         </payment>
>                 </payments>
>         </parcel>
>         <parcel>
>                 <payments>
>                         <payment>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030404</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030405</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030405</date>
>                                 <amount>1</amount>
>                         </payment>
>                 </payments>
>         </parcel>
>         <parcel>
>                 <payments>
>                         <payment>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <date>20030404</date>
>                                 <amount>1</amount>
>                         </payment>
>                         <payment>
>                                 <amount>1</amount>
>                         </payment>
>                 </payments>
>         </parcel>
> </parcels> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.