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

RE: Positional grouping with exceptions

Subject: RE: Positional grouping with exceptions
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 22 Dec 2006 09:27:03 -0000
RE:  Positional grouping with exceptions
> However, Micheal Kay's solution isn't working, Saxon reports 
> that you cannot start with self:: in a group-starting-with 
> attribute. (Axis in pattern must be child or attribute).

Yes, sorry, replace match="self::a[....]" with match="a[.....]".

Michael Kay
http://www.saxonica.com/

> 
> The solution of Andrew Welch seemed to work better, until I 
> discovered that when I have a node containing a childnode and 
> some text, only the childnode remains in the resulting document.
> I've tried to modify the stylesheet, but no such luck.
> 
> --
> Fredrik Geers
> 
> > -----Original Message-----
> > Date: Wed, 20 Dec 2006 15:11:12 -0000
> > To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> > From: "Michael Kay" <mike@xxxxxxxxxxxx>
> > Subject: RE:  Positional grouping with exceptions
> > Message-ID: <01c701c72449$161cb0a0$6401a8c0@turtle>
> > 
> > Try
> > 
> > <xsl:template match="book">
> >   <book>
> >     <xsl:for-each-group select="*"
> >       group-starting-with="self::a[not(child::text())] |
> >
> self::a[not(preceding-sibling::*[1][self::a])] | 
> >                            *[not(self::a)]">
> >       <xsl:choose>
> >         <xsl:when test="self::a[not(child::text())]">
> >           <a1><xsl:copy-of select="remove(current-group(),1)"/></a1>
> >         </xsl:when>
> >         <xsl:when test="self::a">
> >           <a1><xsl:copy-of select="current-group()"/></a1>
> >         </xsl:when>
> >         <xsl:otherwise> 
> >           <xsl:copy-of select="current-group()"/>
> > 
> > Not tested.
> > 
> > Michael Kay
> > http://www.saxonica.com/
> 
> > -----Original Message-----
> > Date: Wed, 20 Dec 2006 15:28:15 +0000
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
> > Subject: Re:  Positional grouping with exceptions
> > Message-ID:
> <74a894af0612200728o791232f5t915f97e8b0faf43@xxxxxxxxxxxxxx>
> > 
> > I think you need a modified identity transform for this one.  The 
> > following stylesheet walks the tree along the 
> following-sibling axis, 
> > allowing you to group <a>'s with text as you come across them:
> > 
> > <xsl:stylesheet version="2.0"
> > 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> > 
> > <xsl:template match="node()">
> > 	<xsl:copy>
> > 		<xsl:copy-of select="@*"/>
> > 		<xsl:apply-templates select="node()[1]"/>
> > 	</xsl:copy>
> > 	<xsl:apply-templates select="following-sibling::*[1]"/>
> > </xsl:template>
> > 
> > <xsl:template match="a[text()]">
> > 	<al>
> > 		<xsl:apply-templates select="." mode="fill"/>
> > 	</al>
> > 	<xsl:apply-templates
> select="following-sibling::*[not(self::a[text()])][1]"/>
> > </xsl:template>
> > 
> > <xsl:template match="a[text()]" mode="fill">
> > 	<xsl:copy-of select="."/>
> > 	<xsl:apply-templates
> > select="following-sibling::*[1][self::a[text()]]" mode="fill"/> 
> > </xsl:template>
> > 
> > </xsl:stylesheet>
> > 
> > The output generated is:
> > 
> > <book>
> > 	<header>title</header>
> > 	<al>
> > 		<a>text</a>
> > 		<a>text</a>
> > 	</al>
> > 	<otherelement>title</otherelement>
> > 	<al>
> > 		<a>text</a>
> > 		<a>text</a>
> > 	</al>
> > 	<a/>
> > 	<al>
> > 		<a>text</a>
> > 	</al>
> > </book>
> > 
> > Notice the <a/> which wasnt present in your example - easy 
> to suppress 
> > if that really is the case.
> > 
> > By the way, Saxon 8.8 is available now.
> > 
> > cheers
> > andrew

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.