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

Re: Grouping text nodes

Subject: Re: Grouping text nodes
From: James Cummings <cummings.james@xxxxxxxxx>
Date: Thu, 4 Aug 2005 16:38:03 +0100
xsl text nodes
David,

As always, you are a star and that works perfectly.  (Even after I put
in more stuff to deal with the various elements I didn't mention to
you....  ;-)   )

Now let's see if I understand it.  I get most of it I think and:

...
> <xsl:apply-templates
select="node()[not(self::span[@class='chapter-num'])]"/>
...
was certainly clever (never occurs to me).  But the bit that makes my
head ache is where you do most of the work:


> <xsl:template match="*[span[@class='vn']]" mode="lg">

What are the extra [ ] doing in this case?
  <snip/>

> <xsl:copy>
> <xsl:copy-of select="@*"/>
> <xsl:for-each-group select="node()"
group-adjacent="empty(self::span[@class='vn'])">

So (while in mode 'lg') make a copy of everything from
span[@class='vn'] to the next one.

> <xsl:choose>
> <xsl:when test="not(current-grouping-key())"/>

Don't put out the current span[@class='vn']

> <xsl:when test="preceding-sibling::span[1][@class='vn']">
> <xsl:text>&#10;</xsl:text>
> <xsl:variable name="i" select="preceding-sibling::span[1]/@id"/>
> <lg xml:id="{$i}" n="{substring-after($i,'_')}">

When just after the versenumber start the linegroup...

> <xsl:for-each-group select="current-group()"
group-adjacent="empty(self::br)">

And group each by the <br/> elements ... now it is in the nested
choose I get confused.

> <xsl:choose>
> <xsl:when test="current-group()/self::milestone and
not(normalize-space(string-join(current-group(),'')))">
> <xsl:copy-of select="current-group()[not(self::br)]"/>
> </xsl:when>

when  a milestone and not the current-group make a copy of it without
the br... (hrmmm, that doesn't sound right...told you I was confused.)

> <xsl:when test="current-grouping-key() and(current-group()/self::* or
normalize-space(string-join(current-group(),'')))">
> <xsl:text>&#10;</xsl:text>
> <l xml:id="{$i}-{(position()+1)div 2}">
> <xsl:copy-of select="current-group()[not(self::br)]"/>
> </l>
> </xsl:when>

For everything else make it into a line based on the current-group

> </xsl:choose>
> </xsl:for-each-group>
> <xsl:text>&#10;</xsl:text>
> </lg>
> <xsl:text>&#10;</xsl:text>
> </xsl:when>

Shut the linegroup

> <xsl:otherwise>
> <xsl:copy-of select="current-group()"/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:for-each-group>
> </xsl:copy>
> </xsl:template>

otherwise just copy the current-group...

It is all working fine (though <milestone>s are sometimes appear
immediately before </l> instead of just outside where I might suspect
would be more usual).

Many thanks,

James

--
James Cummings, Cummings dot James at GMail dot com

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.