O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

translate()

Allows you to convert individual characters in a string from one value to another. In many languages, this function is powerful enough to convert characters from one case to another. ([2.0] For case conversions, XQuery 1.0 and XPath 2.0 provide the more powerful lower-case() and upper-case() functions.)

Syntax

[1.0] string translate(string, $mapString as string, $transString as string)
[2.0] xs:string translate(xs:string?, $mapString as xs:string, 
                          $transString as xs:string)

Inputs

Three strings. The first is the original, untranslated string, and the second and third strings define the characters to be converted.

Output

The original string, translated as follows:

  • If a character in the original string appears in the second argument string (the mapping string), it is replaced with the corresponding character in the third argument string (the translation string).

    In other words, translate('CAR', 'ABCDE', 'EXHQF') returns HER. Going through the characters of the first string in order, C is the third character in the mapping string, so it is replaced with H, the third character in the translation string. The next character of the first string, A, is the first character in the mapping string, so it is replaced with E, the first character in the translation string. Finally, the last character of the first string, R, doesn’t appear in the second string, so it is not modified at all.

  • If a character in the original string appears in the second argument string and there is no corresponding ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required