The function returns the strg with occurrences of characters in the search_list replaced by the character at the corresponding position in the replace_list. If there is a character in the search_list with no character at a corresponding position in the replace_list (because the replace_list is longer than the replace_list), then occurrences of that character in strg string are removed.
If a character occurs more than once in the search_list, then the first occurrence determines the replacement character. If the replace_list is longer than the search_list, then excess characters are ignored.
Two popular use cases for this function are case conversion and sorting with collation. For "to-upper" case conversion, the search_list consists of all lowercase characters of some language and the replace_list consists of all uppercase characters of that language. For "to-lower" case conversion, uppercase chars are in the search_list and lowercase are in the replace_list. For sorting with collation, the function must be used in "select" string expression attribute of <xsl:sort> element; the search_list consists of all characters reordered by collation and the replace_list consists of corresponding characters from "collation string".
String
The following expressions are true:
translate("abracadabra","abc","ABC") = "ABrACAdABrA". translate("ab-ra-ca-dab-ra","abc-","ABC") = "ABrACAdABrA".
The following <xsl:sort> will sort records by its titles, making no difference between spaces and punctiation marks. In addition, spaces will be normalized after the collation processing.
<xsl:key select="normalize-space(translate('@title','.,:;!?',' '))"/>