[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: Wed, 20 Dec 2006 15:11:12 -0000
RE:  Positional grouping with exceptions
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-----
> From: Fredrik Geers [mailto:fredrik@xxxxxxxxxx] 
> Sent: 20 December 2006 14:48
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Positional grouping with exceptions
> 
> I have the following xml:
>  
> <book>
>   <header>title</header>
>   <a>text</a>
>   <a>text</a>
>   <otherelement>title</otherelement>
>   <a>text</a>
>   <a>text</a>
>   <a/>
>   <a>text</a>
> </book>
>  
> I want to group each block of consecutive <a> tags inside an 
> <al> tag, like this:
>  
> <book>
>   <header>title</header>
>   <al>
>     <a>text</a>
>     <a>text</a>
>   </al>
>   <otherelement>title</otherelement>
>   <al>
>     <a>text</a>
>     <a>text</a>
>   </al>
>   <al>
>     <a>text</a>
>   </al>
> </book>
> 
> And like you can see in the example, I want to start a new 
> <al> block when an empty <a> tag is found. That's the hard 
> part. Well, the other part also isn't that easy...
> 
> I can't use the technique described on
> http://www.dpawson.co.uk/xsl/sect2/N4486.html#d5280e424, 
> because the <a> nodes are not always preceded by an element 
> that marks a new group.
> 
> What would be the best technique to solve this? I'm using 
> Saxon 8.7.1 and XSLT 2.0.
> 
> --
> Fredrik Geers

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.