[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Wrap changing element sequence into container: wit

Subject: Re: Wrap changing element sequence into container: with 'for-each-group'?
From: Yves Forkl <Y.Forkl@xxxxxx>
Date: Wed, 31 Jan 2007 17:26:26 +0100
Re:  Wrap changing element sequence into container: wit
Thank you very much for both suggestions. So if I understand right I either have to resort to something which looks to me like "recursion into groups", applying xsl:for-each-group to the result of all previous groupings, or I have to set up a kind of table of grouping keys on which to branch.

A third approach came to my mind. When the order of elements in the flat sequence is fixed, the series of xsl:apply-templates instructions that process the remaining elements may be interrupted by the necessary xsl:for-each-group instructions, which then can immediately select the elements they have to group. Like this:

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

<xsl:output indent="yes"/>

  <xsl:template match="root">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="flatsequence">
    <hierarchy>

<xsl:apply-templates select="a"/>

      <xsl:for-each-group
        select="b|c" group-adjacent="1">
        <container1>
          <xsl:copy-of select="current-group()"/>
        </container1>
      </xsl:for-each-group>

<xsl:apply-templates select="d|e|f"/>

      <xsl:for-each-group
        select="g|h|i" group-adjacent="1">
        <container2>
          <xsl:copy-of select="current-group()"/>
        </container2>
      </xsl:for-each-group>

<xsl:apply-templates select="j"/>

    </hierarchy>
  </xsl:template>

  <xsl:template match="a|d|e|f|g|h|i|j">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>


That seems to work, but perhaps I am missing something?
(If it's OK as it is: any idea how to specify the grouping criterion, which just has to evaluate as permanently true, more elegantly than using 'group-adjacent="1"'?)


Yves

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.