analyze-string_1-input.xml
<?xml version="1.0"?>
<book>
<title>once upon a time in mexico</title>
</book>
analyze-string_1-stylesheet.xsl
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output
indent="yes"/>
<xsl:template
match="/">
<xsl:variable
name="x">
<xsl:analyze-string
select="book/title" regex="\w+">
<xsl:matching-substring>
<xsl:value-of
select="concat(upper-case(substring(., 1, 1)), substring(., 2))"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of
select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<book>
<title>
<xsl:value-of
select="$x"/>
</title>
</book>
</xsl:template>
</xsl:stylesheet>
analyze-string_1-output.xml
<?xml version="1.0" encoding="UTF-8"?>
<book>
<title>Once Upon A Time In Mexico</title>
</book>
We need at least one xsl:matching-substring or one xsl:non-matching-substring. Inside xsl:matching-substring and xsl:non-matching-substring we can have a new xsl:analyze-string, etc. In the example xsl:matching-substring finds all words and make the first letter into upper-case. The xsl:non-matching-substring finds the rest that is the spaces betweeen the words.
Updated 2009-03-19