xsl-list
[Top] [All Lists]

RE: Grouping is not working that great over here

2003-04-11 04:32:24
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(_dot_)H(_dot_)Kay(_at_)ntlworld(_dot_)com
work: Michael(_dot_)Kay(_at_)softwareag(_dot_)com 

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Matts Isuls
Sent: 11 April 2003 06:32
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
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