This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
A new XSLT function: node-set createTextNodes(object,object?)
- To: "xsl-list at lists dot mulberrytech dot com" <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] A new XSLT function: node-set createTextNodes(object,object?)
- From: Miloslav Nic <nicmila at idoox dot com>
- Date: Mon, 18 Dec 2000 08:56:22 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
The following mail I have sent to xsl-editors@w3.org
with cc to "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>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list