xsl-list
[Top] [All Lists]

Re: [xsl] Grouping question

2009-05-14 08:46:33
M Balaji wrote:

Grouping is working properly. But "h4" is appear the child of "h2".
"h4" is grouped under the frist sibling of "h2". Please refer the
below output, frist "h4" element is surronded by "p" tag.  How do I
solve this?

Here is an improved version of the function:

  <xsl:function name="mf:group-heading" as="element()*">
    <xsl:param name="els" as="element()*"/>
    <xsl:param name="level" as="xsd:integer"/>
<xsl:for-each-group select="$els" group-starting-with="*[local-name() eq concat('h', $level)]">
      <xsl:choose>
        <xsl:when test="local-name() eq concat('h', $level)">
          <xsl:element name="{local-name()}">
            <xsl:apply-templates/>
<xsl:sequence select="mf:group-heading(current-group() except ., $level + 1)"/>
          </xsl:element>
        </xsl:when>
        <xsl:when test="$level lt 6">
<xsl:sequence select="mf:group-heading(current-group(), $level + 1)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy-of select="current-group()"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each-group>
  </xsl:function>

The former version did not properly handle the case when group-starting-with did not find a h[n] element.

--

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

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