Export (0) Print
Expand All
1 out of 3 rated this helpful - Rate this topic

translate Function

Returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string.

          string translate(string, string, string)

This function provides a mapping of characters on the first argument. The second and third arguments describe the scheme of the mapping.

The following function call returns "BAr":


If there is a character in the second argument string with no character at a corresponding position in the third argument string (because the second argument string is longer than the third argument string), occurrences of that character in the first argument string are removed.

The following function call returns "AAA":


If a character occurs more than once in the second argument string, the first occurrence determines the replacement character. If the third argument string is longer than the second argument string, excess characters are ignored.

If an argument is not of type string, it is first converted to a string using the string() function and then the result of that conversion is evaluated.

Stringconversions for node sets that are passed as arguments to this function may yield unexpected results. For more information, see string Function.

This function is case-sensitive.

This example demonstrates the preceding translate() expressions.

XML File

None; the XSLT file calls itself.

XSLT File (translate.xsl)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="translate.xsl"?>
<xsl:stylesheet version="1.0"

<xsl:template match="/">
   translate("bar","abc","ABC") = 
      <xsl:value-of select='translate("bar","abc","ABC")'/>
   <br/>translate("--aaa--","abc-","ABC") = 
      <xsl:value-of select='translate("--aaa--","abc-","ABC")'/>


Formatted Output

translate("bar","abc","ABC") = BAr translate("--aaa--","abc-","ABC") = AAA

Processor Output

<?xml version="1.0" encoding="UTF-16"?>   translate("bar","abc","ABC") =       BAr<br />translate("--aaa--","abc-","ABC") =       AAA

Build Date:

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.