On Sun, Apr 11, 2010 at 20:17, Imsieke, Gerrit, le-tex
<gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de> wrote:
I applied a two-step process:
1. Mark up whitespace using intermediate <seg @type="sep"> </seg>;
2. group adjacent WS (and non-WS) nodes, put the non-WS groups in a newly
created w element.
Two solutions from Gerrit and Ken... but I've got some questions to
help my understanding...
<xsl:template match="tei:seg" >
<xsl:copy>
This is taking place in an xsl:copy to copy the surrounding tei:seg
element, right?
<xsl:variable name="sep">
<xsl:apply-templates mode="sep" />
</xsl:variable>
This is the first pass, it goes and creates the whitespace
seg/@type='sep' with a matching string and just puts out the text
content with a non-matching string. Elements being copied with a
copy-all template
<xsl:for-each-group select="$sep/node()"
group-adjacent="boolean(self::tei:seg[(_at_)type='sep'])">
This groups the nodes in the variable you've created by the boolean
(so the truth or falsehood of whether the pattern matches? I didn't
know you could do that in a group-* pattern) of the existence of the
segs you've created on tei:seg/text() which mark the whitespace.
<xsl:choose>
<xsl:when test="current-grouping-key()">
<xsl:value-of select="current-group()" />
</xsl:when>
When it is one of those whitespace segs, then just put out the value
of the whitespace, temporary element vanishes.
<xsl:otherwise>
<w xmlns="http://www.tei-c.org/ns/1.0">
<xsl:apply-templates select="current-group()"/>
</w>
</xsl:otherwise>
Otherwise, wrap it in a word element.
<xsl:template match="tei:seg/text()" mode="sep">
<xsl:analyze-string select="." regex="\s+">
<xsl:matching-substring>
<seg type="sep" xmlns="http://www.tei-c.org/ns/1.0">
<xsl:value-of select="."/>
</seg>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
analyze-string on whitespace on text nodes inside tei:seg, when it is
a match wrap it in a new seg, otherwise, just put it out. This is in
mode 'sep' and is only applied inside the sep variable above.
Cool! Thanks Gerrit, I certainly learned something new!
-James
--~------------------------------------------------------------------
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>
--~--