9 - The starts-with() function

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

<table border="1" cellpadding="5">
<th>Name</th> <th>Line #</th>
	<xsl:for-each select="document/poem/line/name">
	<xsl:if test="starts-with(., 'A') = 'true'">
		<td> <xsl:value-of select="." /> </td> <td align="center"> <xsl:value-of select="../@num" /> </td>


Syntax: starts-with(string1, 'string2')

Returns the value 'true' if string1 starts with string2.

This example loops through each <name> tag and using an xsl:if command, tests to find out whether or not the name begins with the letter "A". If it does, it displays the name along with the line number in which it is found.

RESULTS of iliad09.xsl
Name Line#
Each name that begins with the letter "A" is displayed.