xs:token

Converts $string-var (a string) to a token data type.

As part of the conversion, the following steps occur:

  1. All occurrences of tabs (#x9), line feeds (#xA) and carriage returns (#xD) are replaced with spaces (#x20).
  2. Contiguous sequences of spaces (#x20) are collapsed to a single space (#x20)
  3. Leading and trailing spaces (#x20) are removed.

Signatures

xs:token(xs:string $string-var) —> xs:token

Arguments

Data Type
Argument
Description

xs:string

$string-var

Represents the string for conversion.

Returns

Returns $string-var after conversion to the token data type.

Examples

Remove Tabs

As part of the conversion to the token data type, tabs are replaced by spaces and then all leading and trailing spaces are removed as shown in the following example query:

<result>{xf:token("	tab1	tab2	tab3	tab4")}</result> 

The preceding query, generates the following XML result:

<result>tab1 tab2 tab3 tab4</result> 

Note: The tab before the string tab1 becomes a space and then is removed. (All trailing and leading spaces are removed as part of the conversion.)

Remove Carriage Returns

As part of the conversion to the token data type, carriage returns are replaced by spaces and then all trailing and leading spaces are removed, as shown in the following example query:

<result>{xf:token("
CR1
CR2
")}</result> 

The preceding query, generates the following XML result:

<result>CR1 CR2</result> 

Note: The carriage returns before the string CR1 and after CR2, become spaces and then are removed. (All trailing and leading spaces are removed as part of the conversion.)

Collapse Spaces

As part of the conversion to the token data type, contiguous sequences of spaces (#x20) are collapsed to a single space (#x20) and leading and trailing spaces (#x20) are removed, as shown in the following example query:

<result>{xf:token("   x   y   z   ")}</result> 

The preceding query, generates the following XML result:

<result>x y z</result> 

Related Topics

W3C token data type description.