fn: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.
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.
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.
Example
fn:translate("---aaa---","a-","A")The returned value is "AAA".
