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

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

Subject: A new XSLT function: node-set createTextNodes(object,object?)
From: Miloslav Nic <nicmila@xxxxxxxxx>
Date: Mon, 18 Dec 2000 08:56:22 +0100
xslt with param node set
The following  mail I have sent to  xsl-editors@xxxxxx
with cc to "xsl-list@xxxxxxxxxxxxxxxx".


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@xxxxxxxxx    </mail>   
<support> http://www.zvon.org  </support>
<zvonMailingList> 
    http://www.zvon.org/index.php?nav_id=4 
</zvonMailingList>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.