[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: Tue, 30 Jan 2007 17:37:12 GMT
Re:  Wrap changing element sequence into container: wit
> 2) I fail to see how I can repeatedly group some children, when in 
> between are some children that are not to be grouped. Do I need to apply 
> recursion when working my way through the children?

not in xslt2, no just use for-each-group

It's so much easier if you provide an example, failing that I'll provide
one:-)

If I understand you correctly you want to take

<x>
<abc>1</abc>
<foo>bbb</foo>
<abc>b</abc>
<xyz>b</xyz>
<xyz>c</xyz>
<foo>bbb</foo>
<zzz/>
<hhh/>
<xyz>d</xyz>
</x>


and group adjacent runs of abc and xyz to produce


$ saxon8 wrap.xml wrap.xsl 
<?xml version="1.0" encoding="UTF-8"?>
<x>
   <wrap>
      <abc>1</abc>
   </wrap>
   <foo>bbb</foo>
   <wrap>
      <abc>b</abc>
      <xyz>b</xyz>
      <xyz>c</xyz>
   </wrap>
   <foo>bbb</foo>
   <zzz/>
   <hhh/>
   <wrap>
      <xyz>d</xyz>
   </wrap>
</x>


(using copy-of rather than apply-templates for simplicity)


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

  <xsl:template match="x">
    <x>
      <xsl:for-each-group select="*" group-adjacent="exists(self::xyz|self::abc)">
	<xsl:choose>
	  <xsl:when test="current-grouping-key()">
	    <wrap>
	      <xsl:copy-of select="current-group()"/>
	    </wrap>
	  </xsl:when>
	  <xsl:otherwise>
	    <xsl:copy-of select="current-group()"/>
	  </xsl:otherwise>
	</xsl:choose>
      </xsl:for-each-group>
    </x>
  </xsl:template>
</xsl:stylesheet>

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.