[prev in list] [next in list] [prev in thread] [next in thread]
List: xsl-list
Subject: Re: [xsl] Wrap changing element sequence into container: with 'for-each-group'?
From: David Carlisle <davidc () nag ! co ! uk>
Date: 2007-01-30 17:37:12
Message-ID: 200701301737.l0UHbCBv010834 () edinburgh ! nag ! co ! uk
[Download RAW message or body]
> 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
--~------------------------------------------------------------------
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@lists.mulberrytech.com>
--~--
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic