fn:translate
Returns the value of $arg
modified by replacing or removing individual
characters.
Signature
fn:translate(
$arg as xs:string?,
$mapString as xs:string,
$transString as xs:string
) as xs:string
Properties
This function is deterministic, context-independent, and focus-independent.
Rules
If the value of $arg
is the empty sequence, the function returns the
zero-length string.
Otherwise, the function returns a result string constructed by processing each character in the value of $arg
, in order,
according to the following rules:
-
If the character does not appear in the value of
$mapString
then it is added to the result string unchanged. -
If the character first appears in the value of
$mapString
at some position M, where the value of$transString
is M or more characters in length, then the character at position M in$transString
is added to the result string. -
If the character first appears in the value of
$mapString
at some position M, where the value of$transString
is less than M characters in length, then the character is omitted from the result string.
Notes
If $mapString
is the zero-length string then the function returns
$arg
unchanged.
If a character occurs more than once in $mapString
, then the first
occurrence determines the action taken.
If $transString
is longer than $mapString
, the excess
characters are ignored.
Examples
The expression fn:translate("bar","abc","ABC")
returns "BAr"
.
The expression fn:translate("--aaa--","abc-","ABC")
returns "AAA"
.
The expression fn:translate("abcdabc", "abc", "AB")
returns "ABdAB"
.