# 22. Virtuoso Functions Guide - translate

Chapter Contents | Prev | Next
Keyword Search:
www.openlinksw.com
docs.openlinksw.com
Book Home
Contents
Preface
Virtuoso Functions Guide
Administration
Aggregate Functions
Array Manipulation
BPEL APIs
Backup
Compression
Cursor
Date & Time Manipulation
Debug
Dictionary Manipulation
Encoding & Decoding
File Manipulation
Free Text
Hashing / Cryptographic
LDAP
Locale
Mail
Miscellaneous
Number
Remote SQL Data Source
Replication
SOAP
SQL
String
Transaction
Type Mapping
UDDI
User Defined Types & The CLR
Virtuoso Java PL API
Virtuoso Server Extension Interface (VSEI)
Web Server & Internet
XML
XPATH & XQUERY
and
append
assign
avg
boolean
ceiling
concat
contains
count
create-attribute
create-comment
create-element
create-pi
current
distinct
doc
document
document-literal
empty
ends-with
every
except
false
filter
floor
fn:collection
for
format-number
function-available
generate-id
id
if
intersect
is_after()
is_before()
key
lang
last
let
list()
local-name
max
min
name
namespace-uri
normalize-space
not
number
or
position
processxquery
processxslt
processxsql
progn()
replace()
round
serialize
shallow
some
starts-with
string
string-length
substring
substring-after
substring-before
sum
system-property
text_contains()
translate
true
tuple()
union
unordered
unparsed-entity-uri
urlify
xmlview
Functions Index

## translate

Prforms char-by-char translation of given string
string translate ( strg string, search_list string, replace_list string);
Description

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".

Parameters
strg – String that must be translated.
search_list – String of characters that must be edited in the strg.
replace_list – String of characters that must be inserted in the strg.
Return Types

String

Errors

SQLState | Error Code | Error Text | Description
--- | --- | --- | ---
XP001 | XPF07 | Too long string passed as argument 1 to XPATH function translate(), the result of translation is too long | Virtuoso cannot process strings that are longer than 10M. This limit may be exceed if UTF-8 representations of the replacement characters are longer than representations of replaced characters; even if the number of encoded characters remains the same or decrements.

Examples
Trivial cases

The following expressions are true:

    	translate("abracadabra","abc","ABC") = "ABrACAdABrA".
    	translate("ab-ra-ca-dab-ra","abc-","ABC") = "ABrACAdABrA".

Sorting with collation in XSL

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','.,:;!?','      '))"/>

See Also

replace() normalize-space()