xsl-list
[Top] [All Lists]

Re: Grouping text nodes

2005-08-04 08:38:03
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[(_at_)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[(_at_)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[(_at_)class='vn'])">

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

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

Don't put out the current span[(_at_)class='vn']

<xsl:when test="preceding-sibling::span[1][(_at_)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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--