String Operations
length / size
length returns character count (Unicode code points). size returns byte count. For ASCII text these are the same; for multibyte UTF-8 they differ.
<length var="len">iXML</length>
<output>$len</output>
<!-- 4 -->
char / ord
Convert between characters and UTF-8 code points:
<output><char>65</char></output> <!-- A -->
<output><ord>A</ord></output> <!-- 65 -->
concat — Append to string
Appends a value to an existing variable. More efficient than <set var="x">$x$suffix</set> in loops:
<set var="name">i</set>
<concat var="name">XML</concat>
<output>$name</output>
<!-- iXML -->
tolower / toupper
Case conversion. toupper supports modes: chars (all), words (first letter of each word), first (first character only):
<output><tolower>iXML</tolower></output>
<!-- ixml -->
<output><toupper type="words">bill gates</toupper></output>
<!-- Bill Gates -->
trim — Strip whitespace
Strips whitespace from both ends (default), left only, or right only:
<output><trim> iXML </trim></output>
<!-- iXML -->
pos — Find position
Finds the position of a search value within a string:
<output><pos value="X">iXML</pos></output>
<!-- 1 -->
substr — Extract substring
Returns a portion of a string by offset and optional length:
<output><substr offset="6" length="2">Name: iXML</substr></output>
<!-- iX -->
pad — Pad string
Pads to a given length. Positive length pads right; negative pads left:
<output><pad length="-10" padding="0">123</pad></output>
<!-- 0000000123 -->
match — Regex match
Performs a global regex match, returning the count and match data:
<match var="count" var_matches="m" pattern="/ixml/i">My name is iXML!</match>
<output>Found $count match: $m[0][0]</output>
<!-- Found 1 match: iXML -->
replace — Search and replace
Supports both literal and regex replacement. Regex mode supports backreferences (\0 full match, \1 first capture group):
<!-- Literal replacement -->
<output>
<replace value="Bill" replacement="William">Bill Gates</replace>
</output>
<!-- William Gates -->
<!-- Regex with backreferences -->
<output>
<replace pattern="/(\w+) (\w+)/" replacement="\2, \1">Bill Gates</replace>
</output>
<!-- Gates, Bill -->
split — Split to array
Splits a string into an array by delimiter or regex pattern:
<split var="names" delimiter=", ">Bill Gates, Steve Jobs</split>
<output>$names[0]</output>
<!-- Bill Gates -->
convert — Character encoding
Converts between character encodings (e.g., UTF-8 to ISO-8859-1).