|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








