[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Re: Grouping / Count Issue


Subject: [xsl] Re: Grouping / Count Issue
From: "Miraodb" <miraodb@xxxxxxxxxxx>
Date: Fri, 2 Dec 2005 10:37:05 +0100

Hi,

first of all, thanks all for your quick and great answers !
David's first solution works fine, however the xslt 2 one gives me an error
which i dont understand:
java.lang.RuntimeException: Required type of second operand of '/' is
node(); supplied value has type xs:string

Gabriel's solution is a nice one too...

I indeed use xslt2 and i would love to have it work. any help is much
appreciated.

Just for info, i actually found myself another solution but it's like 3
times slower coz i use two nested for-each which slow down the process a
lot.

Thanks a lot in advance for your help again.

Fabrice

> Grouping / Count Issue
> 23111 by: Miraodb
> 23112 by: David Carlisle
> 23113 by: Gabriel Osorio
> 23114 by: David Carlisle
> David
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:key name="f" match="Field" use="@name"/>
>
> <xsl:template match="/">
> <xsl:text>
> </xsl:text>
>
> <xsl:for-each select="Report/GrandTotal/RecordValues/Record">
>
> <xsl:variable name="v">
> <xsl:for-each  select="FieldValue[key('f',@fieldName)/@dataType='V']">
> <xsl:value-of select="@fieldValue"/>
> </xsl:for-each>
> </xsl:variable>
>
> <xsl:for-each select="FieldValue[key('f',@fieldName)/@dataType='F']">
> <xsl:value-of select="$v"/>
> <xsl:value-of select="substring(key('f',@fieldName)/@title,1,2)"/>
> <xsl:text> </xsl:text>
> <xsl:value-of select="@fieldValue"/>
> <xsl:text>
> </xsl:text>
> </xsl:for-each>
> <xsl:text>
> </xsl:text>
> </xsl:for-each>
>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
> Date: Thu, 1 Dec 2005 09:55:40 -0500
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> From: "Gabriel Osorio" <gosorio@xxxxxxxxxxx>
> Subject: RE: [xsl] Grouping / Count Issue
> Message-ID: <EXCHANGECndg5oQJgAG000005f4@xxxxxxxxxxxxxxxxxxxx>
>
> This formula:
>
> Put Record fields on a string variable separated by commas.
> Then, with a loop, call recursive template.
> Get first element and the rest.
>
> This example works fine for my own last troubles:
>
> <xsl:template match="Report">
> <xsl:variable name="fieldNames">
>    ,<xsl:for-each select="GrandTotal/RecordValues/Record/FieldValue">
> <xsl:value-of select="@fieldName"/>,
>    </xsl:for-each>x
> </xsl:variable>
>
> <xsl:for-each select="Layout/Field[@dataType = 'F']">
> <xsl:call-template name="split">
> <xsl:with-param name="fields" select="$fieldNames"/>
> </xsl:call-template>
> </xsl:for-each>
>
> <!--Logic for Field[not(@dataType = 'F')]-->
> </xsl:template>
>
> <xsl:template name="split">
>   <xsl:param name="fields"/>
>   <xsl:variable name="head" select="substring-before($fields,',')"/>
>   <xsl:variable name="tail" select="substring-after($fields,',')"/>
>
>   <xsl:if test='$head'>
> ...
>   </xsl:if>
>
>   <xsl:if test='$tail'>
> <xsl:call-template name="split">
> <xsl:with-param name="fields" select="$tail"/>
> </xsl:call-template>
>   </xsl:if>
> </xsl:template>
>
> Gabriel
>
> -----Original Message-----
> From: Miraodb [mailto:miraodb@xxxxxxxxxxx]
> Sent: Thursday, December 01, 2005 8:52 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Grouping / Count Issue
>
> > Grouping / Count Issue
> > 22986 by: Miraodb
> > 22987 by: Gabriel Osorio
>
> > Date: Mon, 28 Nov 2005 11:02:07 -0500
> > To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> > From: "Gabriel Osorio" <gosorio@xxxxxxxxxxx>
> > Subject: RE: [xsl] Grouping / Count Issue
> > Message-ID: <EXCHANGEaeJnKWiQsEH000018fd@xxxxxxxxxxxxxxxxxxxx>
> >
> > Maybe with:
> >
> > <!-- F Fields -->
> > <xsl:apply-templates select="Field[@dataType = 'F']" />
> > <!-- other -->
> > <xsl:apply-templates select="Field[not(@dataType = 'F')]" /&gt;
> >


> Date: Thu, 1 Dec 2005 15:04:23 GMT
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> From: David Carlisle <davidc@xxxxxxxxx>
> Subject: Re: [xsl] Grouping / Count Issue
> Message-Id: <200512011504.PAA25360@xxxxxxxxxxxxxxxxx>
>
> or, if you are using xslt2
>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:key name="f" match="Field" use="@name"/>
>
> <xsl:template match="/">
>     <xsl:value-of separator=""
>
select="Report/GrandTotal/RecordValues/Record/FieldValue[key('f',@fieldName)
/@dataType='F']/
>                  ('&#10;',
>
../FieldValue[key('f',@fieldName)/@dataType='V']/string(@fieldValue),substri
ng(key('f',@fieldName)/@title,1,2),
>                   ' ',string(@fieldValue))"/>
> </xsl:template>
>
> </xsl:stylesheet>


Current Thread
Keywords