[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] mixed content grouping by whitespace


Subject: Re: [xsl] mixed content grouping by whitespace
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Sun, 11 Apr 2010 21:17:28 +0200

On 11.04.2010 19:43, David Carlisle wrote:
> On 11/04/2010 17:37, James Cummings wrote:
> group-starting-with="text()">
>
>
> probably that wants to be text()[not(normalize-space(.))]
>
> David

Couldn't get the desired result like that.
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.


==========8<------------------------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
  xmlns:tei="http://www.tei-c.org/ns/1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  version="2.0"
  exclude-result-prefixes="xs tei"
  >

<xsl:output method="xml" />

  <xsl:template match="tei:seg" >
    <xsl:copy>
      <xsl:variable name="sep">
        <xsl:apply-templates mode="sep" />
      </xsl:variable>
      <xsl:for-each-group select="$sep/node()"
        group-adjacent="boolean(self::tei:seg[@type='sep'])">
        <xsl:choose>
          <xsl:when test="current-grouping-key()">
            <xsl:value-of select="current-group()" />
          </xsl:when>
          <xsl:otherwise>
            <w xmlns="http://www.tei-c.org/ns/1.0">
              <xsl:apply-templates select="current-group()"/>
            </w>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

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

  <xsl:template match="@* | *" mode="#all">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()" mode="#current"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
==========8<------------------------

Gerrit


Current Thread