Re: [xsl] nested grouping problem using group-adjacent

Subject: Re: [xsl] nested grouping problem using group-adjacent
From: Jeff Hatch <hatchjk@xxxxxxxxxxxxx>
Date: Wed, 18 Apr 2007 10:33:20 -0600
Thanks, David. This works well and provides a framework for similar tasks to come.

Jeff Hatch
Electronic Media Group
Curriculum Department
Church of Jesus Christ of Latter-day Saints
hatchjk@xxxxxxxxxxxxx



On Apr 18, 2007, at 10:22 AM, David Carlisle wrote:


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


<xsl:template match="objects" name="objects">
  <xsl:param name="o" select="object"/>
  <xsl:param name="d" select="1"/>
  <xsl:for-each-group group-adjacent="@depth&gt;$d" select="$o">
    <xsl:choose>
      <xsl:when test="current-grouping-key()">
	<xsl:element name="group-{$d}">
	  <xsl:call-template name="objects">
	    <xsl:with-param name="o" select="current-group()"/>
	    <xsl:with-param name="d" select="$d+1"/>
	  </xsl:call-template>
	</xsl:element>
      </xsl:when>
      <xsl:otherwise>
	<xsl:copy-of select="current-group()"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each-group>
</xsl:template>

</xsl:stylesheet>


$ saxon8 ob.xml ob.xsl \!indent=yes <?xml version="1.0" encoding="UTF-8"?> <object depth="1">data</object> <object depth="1">data</object> <group-1> <object depth="2">data</object> <object depth="2">data</object> <group-2> <object depth="3">data</object> <object depth="3">data</object> <object depth="3">data</object> </group-2> <object depth="2">data</object> <object depth="2">data</object> </group-1> <object depth="1">data</object> <group-1> <object depth="2">data</object> </group-1> <object depth="1">data</object>



----------------------------------------------------------------------
NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.

Current Thread