13 - The string-length() function

XSLT script: iliad13.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>
	Line <xsl:value-of select="@num" /> is <xsl:value-of select="string-length(.)" /> characters long.
	</p>
	</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Using the string-length() function inside a <xsl:value-of> command, this XSL script displays the length of each line of the poem. The "." in the syntax string-length(.) refers to the current node, which is the current "line" of the for-each loop. See the RESULTS below.

RESULTS of iliad13.xsl

Line 1 is 60 characters long.

Line 2 is 64 characters long.

Line 3 is 51 characters long.

Line 4 is 40 characters long.

Line 5 is 31 characters long.

Line 6 is 55 characters long.

Line 7 is 55 characters long.