[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: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 31 Jan 2007 15:46:03 GMT
Re:  Wrap changing element sequence into container: wit
>       <!-- how to match g, h and i as well within the same
>       "for-each-group"? -->

Two ways.

I used a grouping key of exists(self::b|self::c) so it only has two
states to group or not to group so like that you can only group one
thing at a time, but that's OK as you can have more than one pass.

   <xsl:template match="flatsequence">
  <hierarchy>
    <xsl:variable name="p1">
    <xsl:for-each-group
         select="*" group-adjacent="exists(self::b|self::c)"> ...
   </xsl:variable>
    <xsl:for-each-group
         select="$p1/*"
  group-adjacent="exists(self::h|self::h|self::i)"> ... 
    </xsl:for-each-group>
     </hierarchy>
   </xsl:template>

Or you do it in one pass with a grouping key that has three states (and
an xsl:choose with three branches.


   <xsl:template match="flatsequence">
  <hierarchy>
 <xsl:for-each-group
         select="*" group-adjacent="if (exists(self::b|self::c)) then 1
                                    if (exists(self::h|self::i|self::i)) then 2
                                    else 0"> 
   <xsl:choose>
    <xsl:when test="current-grouping-key()=1">
      <group1><xsl:copy-of select="current-group()"/>...
    <xsl:when test="current-grouping-key()=2">
      <group2><xsl:copy-of select="current-group()"/>...
    <xsl:otherwise>
   <xsl:copy-of select="current-group()"/>..


David

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.