xsl-list
[Top] [All Lists]

Re: [xsl] help in xslt2 grouping

2007-07-06 07:21:43
alex v. wrote:

<root>
<elem>
<title>row1</title>
<content>row2</content>
</elem>
<elem>
<title>row3</title>
<content>row4</content>
<content>row5</content>
<content>row6</content>
</elem>
</root>

This stylesheet does what you describe:

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

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

  <xsl:template match="root">
    <xsl:copy>
<xsl:for-each-group select="*" group-starting-with="elem[title][preceding-sibling::*[1][not(self::elem[title])]]">
        <xsl:copy>
          <xsl:copy-of select="title"/>
          <xsl:for-each select="current-group()[position() &gt; 1]">
            <content><xsl:value-of select="."/></content>
          </xsl:for-each>
        </xsl:copy>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>


--

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

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