Subject: RE: [xsl] Grouping is not working that great over here From: "Michael Kay" <mhk@xxxxxxxxx> Date: Fri, 11 Apr 2003 12:32:24 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Grouping is not working that , Matts Isuls | Thread | [xsl] Seeking methods using XSLT fr, Gary Cornelius |
RE: [xsl] template match for subele, Kathy Burke | Date | RE: [xsl] Self index?, Michael Kay |
Month |