translate function evaluates a string and a set of characters to translate and returns the translated string.
translate(string ,abc ,XYZ )
- The string to evaluate.
- The string of characters that will be replaced.
- The string of characters used for replacement. The first character in
XYZwill replace every occurance of the first character in
abcthat appears in
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.
<xsl:value-of select="translate('The quick brown fox.', 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
THE QUICK BROWN FOX.
abcis longer than
XYZ, then every occurrence of characters in
abcthat do not have a corresponding character in
XYZwill be removed.
<xsl:value-of select="translate('The quick brown fox.', 'brown', 'red')" />
The quick red fox.
XYZcontains more characters than
abc, the extra characters are ignored.