Subject: RE: [xsl] grouping-problem From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Thu, 14 Jun 2007 11:33:00 +0100 |
Use group-by="(@associationName, '')[1]" so that elements with no @associationName get a grouping key of "". Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Annina.Hirschi-Wyss@xxxxxxxxxxxx > [mailto:Annina.Hirschi-Wyss@xxxxxxxxxxxx] > Sent: 14 June 2007 09:59 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] grouping-problem > > Hi, > I'm working with > XSLT 2 > Saxon 8 > And I am a newbie with XSLT... > > ---- > Here is the XML file > "stats.xml" > > <statistic> > <class name="CI_Citation" associationName="citation" > count="50"> </class> <class name="CI_Citation" > associationName="title" count="100"> </class> <class > name="MD_Metadata" count="300"> </class> <class > name="MD_Metadata" associationName="parentId" count="3"> > </class> <class name="CI_Citation" associationName="citation" > count="60"> </class> <class name="CI_Citation" > associationName="title" count="200"> </class> <class > name="MD_Metadata" count="50"> </class> <class > name="MD_Metadata" associationName="parentId" count="10"> > </class> [...] </statistic> > ---- > > Output should be a csv-textfile like: > > CI_Citation citation 110 > title 300 > MD_Metadata 350 > parentId 13 > ---- > > I managed quite well, but only did my XSLT not consider the > class MD_Metadata without the "associationName": > > "stats.xsl" > > <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet > version="2.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output encoding="ISO-8859-1"/> > <xsl:output method="text"/> > <xsl:template match="/"> > <xsl:apply-templates select="statistic"/> > </xsl:template> [...] > <xsl:for-each-group select="class" group-by="@name"> > <xsl:value-of select="current-grouping-key()"/> > <xsl:for-each-group select="current-group()" > group-by="@associationName" > > <xsl:text>;</xsl:text> > <xsl:value-of select="current-grouping-key()"/> > <xsl:text>;</xsl:text> > <xsl:value-of > select="sum(current-group()/@count)"/> > </xsl:for-each-group> > </xsl:for-each-group> > [...] > ---- > > Is there a possibility to list the class MD_Metadata even if > there is no "associationName"? Thanks for your reply!
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] grouping-problem, Annina . Hirschi-Wys | Thread | Re: [xsl] grouping-problem, David Carlisle |
Re: [xsl] Merging multiple document, David Carlisle | Date | Re: [xsl] xsl table, G. Ken Holman |
Month |