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

Re: Copy and group XML

Subject: Re: Copy and group XML
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 26 Jan 2011 18:53:26 +0000
Re:  Copy and group XML
On 26/01/2011 18:22, Jacobus Reyneke wrote:
Good day, could someone please tell me what I'm doing wrong here.

I'm trying to copy a XML document with 'play' as route. While doing so
I need to group the 'scene' elements under 'act'. The xsl below works
(almost), but throws out anything that falls under play, but outside
of a scene. I need to preserve (copy) elements that are outside of

I would guess that the scenes for a given act are adjacent, so using group-adjacent is preferable to using group-by.

So use

<xsl:for-each-group select="*" group-adjacent="(@act, '?')[1]">
<xsl:when test="@act">
<xsl:apply-templates select="current-group()"/>
<xsl:apply-templates select="current-group()"/>

The expression (@act, '?')[1] returns the value of @act if present, or "?" otherwise.

Michael Kay
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

     <xsl:template match="play">
             <xsl:for-each-group select="scene"
                     <xsl:for-each select="current-group()">
                             <xsl:apply-templates  select="@*|node()"/>

     <xsl:template match="@*|node()">
             <xsl:apply-templates select="@*|node()"/>


Kind regards,

Current Thread


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.
First Name
Last Name
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.