home contribute faq download

FunctX XSLT Functions

fn:translate

Replaces individual characters

Google
Webdatypic.com

Description

The fn:translate function replaces individual characters of a string with other individual characters. The $mapString argument is a list of characters to be changed, and $transString is the list of replacement characters. Each character in $mapString is replaced by the character in the same position in $transString. If $mapString is longer than $transString, the characters in $mapString that have no corresponding character in $transString are not included in the result. Characters in the original string that do not appear in $mapString are copied to the result unchanged.

Note that this function is only for replacing individual characters with other individual characters, or removing individual characters. If you want to replace sequences of characters, you should use the fn:replace function instead. This function is sometimes used for translating strings between lowercase and uppercase, but the fn:upper-case and fn:lower-case functions do this more robustly based on Unicode mappings.

This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book.

Arguments and Return Type

NameTypeDescription
$arg xs:string? the string to translate
$mapString xs:string the string of "from" characters
$transString xs:string the string of "to" characters
return value xs:string

Examples

XPath ExampleResults
translate('1999/01/02', '/', '-')
1999-01-02
translate('xml query', 'qlmx', 'QLMX')
XML Query
translate('xml query', 'qlmx ', 'Q')
Query
translate('xml query', 'qlmx ', '')
uery
translate('xml query', 'abcd', 'ABCD')
xml query
translate('', 'qlmx ', 'Q')
zero-length string
translate((), 'qlmx ', 'Q')
zero-length string

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/
Datypic XSLT Services

Recommended Reading:

XQuery