translate function
The fn:translate function replaces selected characters in a string with replacement characters.
Syntax
- source-string
- The string in which characters are to be converted.
source-string has the xs:string data type, or is the empty sequence.
- original-string
- A string that contains the characters that can be converted.
original-string has the xs:string data type.
- replacement-string
- A string that contains the characters that replace the characters
in original-string.
replacement-string has the xs:string data type.
If the length of replacement-string is greater than the length of original-string, the additional characters in replacement-string are ignored.
- Limitation of length
The length of original-string and replacement-string is limited to 32000 bytes.
Returned value
- For each character in source-string that appears in original-string,
replace the character in source-string with the character in replacement-string that
appears at the same position as the character in original-string.
The characters are matched using a binary comparison.
If the length of original-string is greater than the length of replacement-string, delete each character in source-string that appears in original-string, but the character position in original-string does not have a corresponding position in replacement-string.
If a character appears more than once in original-string, the position of the first occurrence of the character in original-string determines the character in replacement-string that is used.
- For each character in source-string that does not appear in original-string, leave the character as it is.
If source-string is the empty sequence, a string of length 0 is returned.
Examples
fn:translate('Test literal','el','om')
The returned value is 'Tost mitoram'.
fn:translate('Another test literal', 'Ater', 'Bfim')
The returned value is 'Bnofhim fisf lifimal'.