---
title: "XSLT string functions: complete reference with examples"
description: "Complete guide to XSLT and XPath string functions: substring, contains, replace, tokenize, normalize-space and more. With practical examples."
date: 2025-03-28T00:00:00Z
tags: ["xslt", "xpath", "strings", "functions"]
---
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](https://xsltplayground.com).
## Basic string functions (XSLT 1.0+)
### string-length
Returns the number of characters in a string.
```xml
```
### substring
Extracts a portion of a string. Arguments: string, start position (1-based), optional length.
```xml
```
### substring-before and substring-after
Split a string on a delimiter.
```xml
```
### contains, starts-with, ends-with
Test membership without extracting.
```xml
...
...
...
```
### concat
Joins strings together. Takes any number of arguments.
```xml
```
### normalize-space
Strips leading and trailing whitespace, and collapses internal whitespace to single spaces. Essential for cleaning values from XML sources.
```xml
```
### translate
Replaces characters one-for-one. Useful for simple case conversion or character removal.
```xml
```
## Advanced string functions (XSLT 2.0+)
### upper-case and lower-case
No longer need `translate` for case conversion.
```xml
```
### replace
Regex-based substitution. Much more powerful than `translate`.
```xml
```
### matches
Tests a string against a regex.
```xml
```
### tokenize
Splits a string into a sequence using a regex delimiter. Returns a sequence of strings.
```xml
```
### string-join
The inverse of `tokenize`. Joins a sequence with a separator.
```xml
```
### format-number
Formats a number as a string with a picture pattern.
```xml
```
### format-date and format-dateTime
Format xs:date and xs:dateTime values using picture strings.
```xml
```
## Practical patterns
**Extract domain from URL:**
```xml
```
**Pad a number with leading zeros:**
```xml
```
**Check if a node text is numeric:**
```xml
```
All of these work in [XSLT Playground](https://xsltplayground.com). Set the version to 2.0 or 3.0 for the functions that require it.