Re: [xsl] Grouping lists from flat to nested

Subject: Re: [xsl] Grouping lists from flat to nested
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Mon, 31 Jan 2011 17:28:06 +0100
Stefanie Haupt wrote:

this looks great, thank you!  - the only downside is that the input to
this grouping attempt is a variable containing the input. So I fear I
can't use<template match="text">  here. I think I would need a new
transformation document in the pipeline with this attempt - which I
would love to avoid. - Or am I mistaken?

  <xsl:template match="test">
    <xsl:copy>
      <xsl:for-each-group select="*" group-adjacent="boolean(self::item)">
        <xsl:choose>
          <xsl:when test="current-grouping-key()">
            <xsl:sequence select="mf:group(current-group(), 0)"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="current-group()"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

Instead of that template you could just apply the code to your variable e.g.


<xsl:for-each-group select="$variable/*" group-adjacent="boolean(self::item)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<xsl:sequence select="mf:group(current-group(), 0)"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>



--


	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread