translate
The translate
function evaluates a string and a set of characters to translate and returns the translated string.
Syntax
translate(string, abc, XYZ)
Arguments
string
-
The string to evaluate.
abc
-
The string of characters that will be replaced.
XYZ
-
The string of characters used for replacement. The first character in
XYZ
will replace every occurrence of the first character inabc
that appears instring
.
Returns
The translated string.
Notes
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
xml
<xsl:value-of select="translate('The quick brown fox.', 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
Output
THE QUICK BROWN FOX.
- If
abc
is longer thanXYZ
, then every occurrence of characters inabc
that do not have a corresponding character inXYZ
will be removed.
Example
xml
<xsl:value-of select="translate('The quick brown fox.', 'brown', 'red')" />
Output
The quick red fox.
- If
XYZ
contains more characters thanabc
, the extra characters are ignored.
Defined
Gecko support
Supported.