[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: mixed content grouping by whitespace

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.