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(_at_)lists(_dot_)mulberrytech(_dot_)com>
From: "Gabriel Osorio" <gosorio(_at_)tournet(_dot_)com>
Subject: RE: [xsl] Grouping / Count Issue
Message-ID:
<EXCHANGECndg5oQJgAG000005f4(_at_)Exchange(_dot_)tournet(_dot_)com>
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[(_at_)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(_at_)hotmail(_dot_)com]
Sent: Thursday, December 01, 2005 8:52 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
From: "Gabriel Osorio" <gosorio(_at_)tournet(_dot_)com>
Subject: RE: [xsl] Grouping / Count Issue
Message-ID:
<EXCHANGEaeJnKWiQsEH000018fd(_at_)Exchange(_dot_)tournet(_dot_)com>
Maybe with:
<!-- F Fields -->
<xsl:apply-templates select="Field[(_at_)dataType = 'F']" />
<!-- other -->
<xsl:apply-templates select="Field[not(@dataType = 'F')]" />
Date: Thu, 1 Dec 2005 15:04:23 GMT
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
Subject: Re: [xsl] Grouping / Count Issue
Message-Id:
<200512011504(_dot_)PAA25360(_at_)penguin(_dot_)nag(_dot_)co(_dot_)uk>
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']/
(' ',
../FieldValue[key('f',@fieldName)/@dataType='V']/string(@fieldValue),substri
ng(key('f',@fieldName)/@title,1,2),
' ',string(@fieldValue))"/>
</xsl:template>
</xsl:stylesheet>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--