10 - The substring() function

XSLT script: iliad10.xsl
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">

<xsl:for-each select="document/poem/line">
<p>
The first 10 characters of line <xsl:value-of select="@num" /> are:
<br> <b> <xsl:value-of select="substring(., 1, 10)" /> </b> </br>
</p>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>

Syntax: substring(string,offset,length)

Returns length amount of characters of string starting at offset. An offset of 1 is the beginning of the string.

This example tells the brower to display the first ten characters of the current line starting from the first character in the line.


RESULTS of iliad10.xsl

The first 10 characters of line 1 are:
Sing, oh g

The first 10 characters of line 2 are:
the accurs

The first 10 characters of line 3 are:
and sent f

The first 10 characters of line 4 are:
making the

The first 10 characters of line 5 are:
The will o

The first 10 characters of line 6 are:
when, in f

The first 10 characters of line 7 are:
the son of