The translate
function evaluates a string and a set of characters to translate and returns the translated string.
translate(string ,abc ,XYZ )
string
abc
XYZ
XYZ
will replace every occurance of the first character inabc
that appears instring
.The translated string.
XPath notes that the translate function is not a sufficient solution for case conversion in all languages. A future version of XPath may provide additional functions for case conversion.
However, this is the closest we have at present to a function that can convert a string to uppercase or lowercase.
Example
<xsl:value-of select="translate('The quick brown fox.', 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
Output
THE QUICK BROWN FOX.
abc
is longer than XYZ
, then every occurrence of characters in abc
that do not have a corresponding character in XYZ
will be removed.Example
<xsl:value-of select="translate('The quick brown fox.', 'brown', 'red')" />
Output
The quick red fdx.
XYZ
contains more characters than abc
, the extra characters are ignored.Supported.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/XPath/Functions/translate