Replaces all occurrences of $string-var2 with $string-var3 in $string-var1.
If the value of $string-var1, $string-var2, or $string-var3 is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.
xf:translate(xs:string? $string-var1, xs:string? $string-var2, xs:string? $string-var3) —> xs:string?
Returns the value of $string-var1 after all occurrences of the $string-var2 in $string-var1 have been replaced with $string-var3. If the length of $string-var2 (the search string) is less than the length of $string-var3 (replacement string), then only N characters are substituted, where N is length of $string-var2. (See the third example below.)
Returns the value of $string-var1, if $string-var2 is a zero-length string ("").
Invoking translate("fghXfgh", "fgh", "yz") returns the string xyXyz as shown in the following example query:
<result>{xf:translate("fghXfgh", "fgh", "yz")}</result>
The preceding query generates the following result:
<result>yzXyz</result>
Invoking translate("abcdabc", "ab", "ABC") returns the string ABcdABc, as shown in the following example query:
<result>{xf:translate("abcdabc", "ab", "ABC")}</result>
The preceding query generates the following result:
<result>ABcdABc</result>
Note: Only the first two characters (AB) of the replacement string ABC are substituted because the length of ab (the search string) is less than the length of ABC (the replacement string). When the length of the search string is less than the length of the replacement string, the length of the search string determines the number characters substituted.
Invoking translate("abcdabc", "abc", "") returns the string d because the replacement string is a zero-length string, as shown in the following example query:
<result>{xf:translate("abcdabc", "abc", "")}</result>
The preceding query generates the following result:
<result>d</result>
Invoking translate("abcdabc", "", "AB") returns the string abcdabc because the search string is a zero-length string, as shown in the following example query:
<result>{xf:translate("abcdabc", "", "AB")}</result>
The preceding query generates the following result:
<result>abcdabc</result>
Invoking translate((), "ab", "ABC") returns the null string as shown in the following example query:
<result>{xf:translate((), "ab", "ABC")}</result>
Note: The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.
The preceding query generates the following result:
<result/>
W3C translate function description.