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:



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

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

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

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

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

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

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



<firstName> Miloslav </firstName>    
<surname>   Nic      </surname>     

<mail>    nicmila@idoox.com    </mail>   
<support> http://www.zvon.org  </support>
Received on Thursday, 14 December 2000 03:16:47 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:44:21 UTC