I have an XML file which I'm trying to transform into XHTML using a XSLT file. I was wondering if it's possible to get a count of the number of times a template has been invoked. This is my XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" encoding="UTF-8" href="car.xslt" version="1.0"?>
<vehicle>
<car>
<make>Honda</make>
<color>blue</color>
</car>
<car>
<make>Saab</make>
<color>red</color>
</car>
</vehicle>
And this is my XSLT:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<table cellpadding="5" border="1">
<tr><td>number</td><td>make</td><td>color</td></tr>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="car">
<tr>
<td>#</td><td><xsl:value-of select="make"/></td><td><xsl:value-of select="color"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
I want to print the number of times a car has been printed in the place of #, so it would look like this:
number make color 1 Honda blue 2 Saab red
instead of:
number make color # Honda blue # Saab red
Anybody have any ideas? I was hoping this could be done with just xsl:value-of and XPath