W3C home > Mailing lists > Public > xsl-editors@w3.org > October to December 2000

A new XSLT function: node-set createTextNodes(object,object?)

From: Miloslav Nic <nicmila@idoox.com>
Date: Thu, 14 Dec 2000 09:16:31 +0100
Message-ID: <3A3881DF.98F3A832@idoox.com>
To: xsl-editors@w3.org
CC: "xsl-list@mulberrytech.com" <xsl-list@mulberrytech.com>
node-set createTextNodes(object,object?)

Rationale: text handling is rather cumbersome in XSLT, some general
method would be very useful

The proposed function takes the first argument and converts it
into a string
The second optional object is a separator (default = whitespaces \s+)

It returns a node-set of text nodes, which can be processed in the
standard way


It would have some nice implications for functions taking a node-set as
an argument

e.g. xsl:key  (emulation of IDREFS behaviour)


A pilot example:

XML:
<aaa>AAAxxBBBxxCCC</aaa>

XSL:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 version="1.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
  <xsl:call-template name="split">
    <xsl:with-param name="text" select="/aaa"/>
    <xsl:with-param name="char" select="'xx'"/>
  </xsl:call-template>
</xsl:template>

<xsl:template match="text()" mode="WRAPTEXT">
  <AAA><xsl:value-of select="."/></AAA>
</xsl:template>

<xsl:template name="split" >
  <xsl:param name="text"/>
  <xsl:param name="char"/>

  <xsl:variable name="first">
    <xsl:choose>
      <xsl:when test="contains($text,$char)">
        <xsl:value-of select="substring-before($text,$char)"/>
      </xsl:when>
      <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="rest">
    <xsl:value-of select="substring-after($text,$char)"/>
  </xsl:variable>

  <xsl:if test="not($first='')">
    <xsl:apply-templates select="$first" mode="WRAPTEXT"/>
  </xsl:if>

  <xsl:if test="not($rest='')">
    <xsl:call-template name="split">
      <xsl:with-param name="text" select="$rest"/>
      <xsl:with-param name="char" select="$char"/>
    </xsl:call-template>
  </xsl:if>

</xsl:template>   

</xsl:stylesheet>



-- 
******************************************
<firstName> Miloslav </firstName>    
<surname>   Nic      </surname>     

<mail>    nicmila@idoox.com    </mail>   
<support> http://www.zvon.org  </support>
<zvonMailingList> 
    http://www.zvon.org/index.php?nav_id=4 
</zvonMailingList>
Received on Thursday, 14 December 2000 03:16:47 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 7 December 2009 10:59:51 GMT