|
Subject: Re: [xsl] Grouping text nodes From: James Cummings <cummings.james@xxxxxxxxx> Date: Thu, 4 Aug 2005 16:38:03 +0100 |
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> </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> </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> </xsl:text>
> </lg>
> <xsl:text> </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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Grouping text nodes, David Carlisle | Thread | Re: [xsl] Grouping text nodes, David Carlisle |
| RE: [xsl] Using Saxon 8.5 and colle, Michael Kay | Date | [xsl] defining nodes to apply templ, ADAM PATRICK |
| Month |