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] stringtranslate(
string
,$mapString as string
,$transString as string
)
[2.0] xs:stringtranslate(
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')
returnsHER
. Going through the characters of the first string in order,C
is the third character in the mapping string, so it is replaced withH
, 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 withE
, 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 ...
Get XSLT, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.