[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: grouping-problem
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: 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!
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|