# EXSLT - str:replace

Implementer Page: str.replace.html 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.

## Implementations

There are currently no XSLT processors that we know of that support `str:replace` natively.

There are currently no third-party implementations of the latest version of `str:replace`.

The following third-party implementations of earlier versions of `str:replace` are available:

- EXSLT Function (by Jeni Tennison)
- XSLT Template (by Jeni Tennison)

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