Re: [xsl] two-level grouping xslt 2.0

Subject: Re: [xsl] two-level grouping xslt 2.0
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Fri, 29 Feb 2008 14:28:51 +0100
Terry Ofner wrote:
Your two template rules work well. However, I think I have managed to misrepresent the problem--one of the main pitfalls of submitting queries, it seems.

The problem is this: The <story-title> element is the opening element of a "story" (as opposed the <story> element which is courtesy of the xhtml export from InDesign). At any rate, each "story" is composed of multiple elements such as <story>, <page>, and <imggroup>. That is why I am trying to execute a two-level grouping rule. The outer for-each-group should structure the <level1 class="unit"> hierarchy; the inner for-each-group should structure the <level2 class="selection">.

This stylesheet should do:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="2.0">

<xsl:output method="xml" indent="yes"/>

<xsl:strip-space elements="*"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

<xsl:template match="bodymatter">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each-group
select="*"
group-starting-with="story[cluster_num]">
<level1 class="unit" unitnum="{position()}">
<xsl:for-each-group
select="current-group()"
group-starting-with="story[story-title]">
<xsl:choose>
<xsl:when test="current-group()[1][self::story[story-title]]">
<level2 class="selection">
<xsl:apply-templates select="current-group()"/>
</level2>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</level1>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>


</xsl:stylesheet>

--

	Martin Honnen
	http://JavaScript.FAQTs.com/

Current Thread