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'">
		<tr>
		<td> <xsl:value-of select="." /> </td> <td align="center"> <xsl:value-of select="../@num" /> </td>
		</tr>
	</xsl:if>
	</xsl:for-each>
</table>

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

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#
Achilles1
Achaeans2
Atreus7
Achilles7
Each name that begins with the letter "A" is displayed.