TonyMarston
Programmer
I am trying to extract the value of an element's position in the XML file so that I can create references to the current, previous and next element. Can anyone give a newbie some advice?
My XML file looks something like this:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="filelist.xsl"?>
<DIRECTORY>
<FILE>
<NAME>picture1.jpg</NAME>
</FILE>
<FILE>
<NAME>picture2.jpg</NAME>
</FILE>
.....
<FILE>
<NAME>picture99.jpg</NAME>
</FILE>
</DIRECTORY>
My XSL file looks like this:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="<xsl:template match="/">
<html>
<body>
<table border="0" width="100%">
<xsl:for-each select="DIRECTORY/FILE">
<tr>
<td valign="top"><a href="#imageN-1">PREV</a></td>
<td valign="top"><a href="#imageN+1">NEXT</a></td>
<td valign="top" align="center">
<a name= "imageN">
<xsl:element name="img">
<xsl:attribute name="src"><xsl:value-of select="NAME"/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="NAME"/></xsl:attribute>
</xsl:element>
</a>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
'imageN' should indicate the current element number.
'imageN-1' should indicate the previous element number.
'imageN+1' should indicate the next element number.
My XML file looks something like this:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="filelist.xsl"?>
<DIRECTORY>
<FILE>
<NAME>picture1.jpg</NAME>
</FILE>
<FILE>
<NAME>picture2.jpg</NAME>
</FILE>
.....
<FILE>
<NAME>picture99.jpg</NAME>
</FILE>
</DIRECTORY>
My XSL file looks like this:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="<xsl:template match="/">
<html>
<body>
<table border="0" width="100%">
<xsl:for-each select="DIRECTORY/FILE">
<tr>
<td valign="top"><a href="#imageN-1">PREV</a></td>
<td valign="top"><a href="#imageN+1">NEXT</a></td>
<td valign="top" align="center">
<a name= "imageN">
<xsl:element name="img">
<xsl:attribute name="src"><xsl:value-of select="NAME"/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="NAME"/></xsl:attribute>
</xsl:element>
</a>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
'imageN' should indicate the current element number.
'imageN-1' should indicate the previous element number.
'imageN+1' should indicate the next element number.