Re: [xsl] Grouping text nodes

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

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
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?

> <xsl:copy>
> <xsl:copy-of select="@*"/>
> <xsl:for-each-group select="node()"

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()"

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
> <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
> <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 Cummings, Cummings dot James at GMail dot com

Current Thread