EXSLT - str:replace - Implementer Page

Version: 1
Status: new
User Page: index.html
XML Definition: str.replace.xml
Function Package: str.replace.zip

Function Syntax

node-set str:replace(string, object, object)

Template Syntax

<xsl:call-template name="str:replace">
   <xsl:with-param name="string" select="string" />
   <xsl:with-param name="search" select="object" />
   <xsl:with-param name="replace" select="object" />
</xsl:call-template>

The str:replace function replaces any occurrences of search strings within a string with replacement nodes to create a node set.

The first argument gives the string within which strings are to be replaced.

The second argument is an object which specifies a search string list. If the second argument is a node set, then the search string list consists of the result of converting each of the nodes in the node set to a string as by the string() function, listed in document order. If the second argument is not a node set, then the second argument is converted to a string as by the string() function and the search string list consists of this string only.

The third argument is an object which specifies a replacement node list. If the third argument is a node set, then the replacement node list consists of the nodes in the node set in document order. If the third argument is not a node set, then the replacement node list consists of a single text node whose string value is the same as the result of converting the third argument to a string as by the string() function.

It is an error if any of the nodes in the replacement node list are attribute nodes or namespace nodes. An XSLT processor may recover from this error by treating these nodes as text nodes with an empty string value.

The str:replace function works by replacing each occurence of a string in the search string list within the first argument string by the equivalently positioned node in the replacement node list. If there is no equivalently positioned node in the replacement node list then the search string is deleted from the string.

The longest search strings are replaced first. If a search string is empty, then the equivalently positioned replacement node is inserted between every character in the string.

An implementation of this extension function in the EXSLT str namespace must conform to the behaviour described in this document.

Implementations

No XSLT processors that we know of have built-in support for str:replace.

The following implementations of str:replace are available:

LanguageImplemented VersionCreatorDateDownload
EXSLT Function1.1Jeni Tennison2001-06-08str.replace.function.xsl
XSLT Template1.1Jeni Tennison2001-06-08str.replace.template.xsl

Change History

Submitted: 2001-06-08
Creator: Jeni Tennison(http://www.jenitennison.com/)

The str:replace function replaces occurrences of strings within a string with another string or with nodes.
VersionModifiedByDetails
1.12001-11-18Jeni Tennison Indicated behaviour when one of the search nodes in the second argument is an empty string; str:replace() should insert the relevant replace nodes between each character in the original string.
1.22002-08-20Craig Stewart

Added 4XSLT implementation to the list.

1.32002-11-12Craig Stewart

Updated 4XSLT version to 0.12.0a3.

1.42002-11-12Craig Stewart

Removed 4XSLT implmentation, due to bugged support.

http://www.exslt.org/str/functions/replace/str.replace.html last modified 2002-11-12