The function string() transforms the argument into a string. This function is not
been usualy directly used in the stylesheets as in most cases called by a default.
XSL stylesheet 1 shows the examples of the number into string conversion. Notice the
results of the zero divisions.
A starts-with function do returns true if first argument string starts with
a second argument string, otherwise it will return false. Contains function do returns
true if first argument string do contains second argument string, otherwise
it will return false.
XML Source
<source>
<text>Welcome to XSL world.</text>
<string>Welcome</string>
<string>XSL</string>
<string>XML</string>
</source>
Substring-before function do return an substring of first argument string which
precedes the substring-after the function which follows first occurrence of
a second argument string in first argument string. Substring function returns
a substring of first argument starting at a position specified in second
argument with the length specified in third argument. If third argument is not
been specified, it does returns the substring starting at a position specified in
a second argument and continuing till the end of a string. The Counting do starts with 1.
XML Source
<source>
<text>Welcome to XSL world.</text>
<string>XSL</string>
<start>4</start>
<end>10</end>
</source>
Output
<DIV>
<B>Text: </B>Welcome to XSL world.</DIV>
<B>Text before XSL: </B>Welcome to <DIV>
<B>Text after XSL: </B> world.</DIV>
<DIV>
<B>Text from position 4: </B>come to XSL world.</DIV>
<DIV>
<B>Text from position 4 of length 10: </B>come to XS</DIV>
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<DIV>
<B>
<xsl:text>Text: </xsl:text>
</B>
<xsl:value-of select="//text"/>
</DIV>
<B>
<xsl:text>Text before </xsl:text>
<xsl:value-of select="//string"/>
<xsl:text>: </xsl:text>
</B>
<xsl:value-of select="substring-before(//text,//string)"/>
<DIV>
<B>
<xsl:text>Text after </xsl:text>
<xsl:value-of select="//string"/>
<xsl:text>: </xsl:text>
</B>
<xsl:value-of select="substring-after(//text,//string)"/>
</DIV>
<DIV>
<B>
<xsl:text>Text from position </xsl:text>
<xsl:value-of select="//start"/>
<xsl:text>: </xsl:text>
</B>
<xsl:value-of select="substring(//text,//start)"/>
</DIV>
<DIV>
<B>
<xsl:text>Text from position </xsl:text>
<xsl:value-of select="//start"/>
<xsl:text> of length </xsl:text>
<xsl:value-of select="//end"/>
<xsl:text>: </xsl:text>
</B>
<xsl:value-of select="substring(//text,//start,//end)"/>
</DIV>
</xsl:template>
</xsl:stylesheet>
String-Length Function
"string-length" function does return number of characters in a string.
"normalize-space" function does return the argument string with a white space
normalized by the stripping leading and trailing a whitespace and replacing the
sequences of whitespace characters by the single white space.
XML Source
<source>
<P>
<text>Normalized text</text>
<text>Sequences of whitespace characters</text>
<text> Leading and trailing whitespace. </text>
</P>
</source>