|
Subject: [xsl] nested grouping problem From: Terry Ofner <tdofner@xxxxxxxxx> Date: Mon, 4 Oct 2010 11:12:54 -0400 |
I have the following incoming xml:
<summary>
<codeSum main="14" exp="A">(14) Writing:</codeSum>
<codeSum main="14" exp="A">(14) Writing:</codeSum>
<codeSum main="14" exp="C">(14) Writing:</codeSum>
<codeSum main="14" exp="C">(14) Writing:</codeSum>
<codeSum main="14" exp="C">(14) Writing:</codeSum>
<codeSum main="14" exp="C">(14) Writing:</codeSum>
<codeSum main="14" exp="D">(14) Writing:</codeSum>
<codeSum main="14" exp="D">(14) Writing:</codeSum>
<codeSum main="14" exp="D">(14) Writing:</codeSum>
<codeSum main="14" exp="D">(14) Writing:</codeSum>
<codeSum main="14" exp="E">(14) Writing:</codeSum>
<codeSum main="14" exp="E">(14) Writing:</codeSum>
<codeSum main="17" exp="A">(17) Expository:</codeSum>
<codeSum main="17" exp="A">(17) Expository:</codeSum>
<codeSum main="17" exp="A">(17) Expository:</codeSum>
<codeSum main="19" exp="A">(19) Conventions:</codeSum>
<codeSum main="19" exp="A">(19) Conventions:</codeSum>
<codeSum main="22" exp="A">(22) Research:</codeSum>
<codeSum main="22" exp="A">(22) Research:</codeSum>
<codeSum main="22" exp="A">(22) Research:</codeSum>
<codeSum main="22" exp="A">(22) Research:</codeSum>
</summary>
I am processing this with the following nested grouping template:
<xsl:template match="summary">
<summary><textBold>Areas:</textBold><xsl:for-each-group
select="codeSum" group-by="@main">
<xsl:value-of select="."/><xsl:text> </xsl:text>
<xsl:for-each-group select="current-group()" group-by="@exp">
<xsl:choose>
<xsl:when test="position()!=last()">
<xsl:value-of select="current-grouping-key()"/><xsl:text>,
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="current-grouping-key()"/><xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:for-each-group>
</summary>
</xsl:template>
with this result:
<summary><textBold>Areas:</textBold> (14) Writing: A, C, D, E (17)
Expository: A (19) Conventions: A (22) Research: A </summary>
I would like to add a semicolon after the last letter (@exp) listed after each
area except for the last area in the list:
<summary><textBold>Areas:</textBold> (14) Writing: A, C, D, E; (17)
Expository: A; (19) Conventions: A; (22) Research: A </summary>
Is this possible inside one template? I have always grouped from the outside
in, so to speak. In this case it seems that I would need to first group the
@main[@exp], then group @main.
Otherwise I will need to leave some kind of element or attribute and take
another pass through the summary to add the semicolons. Or perhaps this is a
candidate for named template call, which is an approach that I am still fuzzy
on.
Any help would be most appreciated.
Terry
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Copying all comments [xsl, pankaj . c | Thread | Re: [xsl] nested grouping problem, David Carlisle |
| Re: [xsl] Modifying a DTD with XSLT, dvint | Date | Re: [xsl] nested grouping problem, David Carlisle |
| Month |