String manipulation is one of the most common tasks in XSLT. Whether you are formatting output, parsing codes, or normalising values from external systems, XPath provides a rich set of string functions. This reference covers the most useful ones with examples you can run in XSLT Playground.
Basic string functions (XSLT 1.0+)
string-length
Returns the number of characters in a string.
substring
Extracts a portion of a string. Arguments: string, start position (1-based), optional length.
substring-before and substring-after
Split a string on a delimiter.
contains, starts-with, ends-with
Test membership without extracting.
...
...
...
concat
Joins strings together. Takes any number of arguments.
normalize-space
Strips leading and trailing whitespace, and collapses internal whitespace to single spaces. Essential for cleaning values from XML sources.
translate
Replaces characters one-for-one. Useful for simple case conversion or character removal.
Advanced string functions (XSLT 2.0+)
upper-case and lower-case
No longer need translate for case conversion.
replace
Regex-based substitution. Much more powerful than translate.
matches
Tests a string against a regex.
tokenize
Splits a string into a sequence using a regex delimiter. Returns a sequence of strings.
string-join
The inverse of tokenize. Joins a sequence with a separator.
format-number
Formats a number as a string with a picture pattern.
format-date and format-dateTime
Format xs:date and xs:dateTime values using picture strings.
Practical patterns
Extract domain from URL:
Pad a number with leading zeros:
Check if a node text is numeric:
All of these work in XSLT Playground. Set the version to 2.0 or 3.0 for the functions that require it.
Top comments (0)