xsl-list
[Top] [All Lists]

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

2007-04-18 09:34:08
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(_at_)ldschurch(_dot_)org



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>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



----------------------------------------------------------------------
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.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>