Forum Moderators: open
my xml file
<?xml version="1.0" encoding="windows-1252"?>
<?xml-stylesheet type="text/xml" href="album_ns.xsl"?>
<root>
<album name="Album 1">
<image id="1">
<titre>avec le frère et la soeur</titre>
<date>21 juillet 2005</date>
<source>images/yzl.gif</source>
<taille largeur="400" longueur ="602"/>
</image>
</album>
.......
</root>
my xsl file
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<html>
<head>
<title>Album Photo</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<table width="500" align="center">
<xsl:for-each select="./album">
<tr>
<td class="big" colspan="4"><br></br><i><xsl:apply-templates select="@name"/></i><br></br></td>
</tr>
<tr>
<xsl:for-each select="./image">
<td align="center" width="125" valign="top">
<a href="album_ns.xml?imageID={@id}"><img src="{./source}" width="{./taille/@largeur}" height="{./taille/@longueur}" border="0"/></a></td>
</xsl:for-each>
</tr>
<!--
<read url.imageID to get more image info>
-->
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
so simply all i need is to pass the image id in the url to display other elements of the clicked image.
----
It looks like what you are trying to do is read values in the XML file and insert them into the url of the linked image. If that is the case, I think the problem here are simply some syntax errors. You have an open <xsl:for-each>, and I don't believe "./" is a valid XPath. It's also unclear what you intend <xsl:apply-templates select="@name"/> to do.
Also, I personally avoid using <xsl:for-each> as using <xsl:apply-templates> results in an easier-to-read and more modular stylesheet. But that is a matter of coding style.
Try this code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<html>
<head>
<title>Album Photo</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<table width="500" align="center">
<xsl:apply-templates select="album">
</table>
</body>
</html>
</xsl:template>
<xsl:template select="album">
<tr>
<td class="big" colspan="4"><br></br><i><xsl:value-of select="@name"/></i><br></br></td>
</tr>
<tr>
<xsl:apply-templates select="image"
</tr>
</xsl:template>
<xsl:template match="image">
<td align="center" width="125" valign="top">
<a href="album_ns.xml?imageID={@id}"><img src="{source}" width="{taille/@largeur}" height="{taille/@longueur}" border="0" /></a></td>
</xsl:template>
</xsl:stylesheet>
-----
That said, in case somebody comes across this thread in a search, I have an answer too :).
In our system (Xalan/Xerces), we can pass CGI variables into global stylesheet parameters. To provide a heavily simplified example, for the XML
<myxml>
<message id="1">Hello, world</message>
<message id="2">Hello, Mars</message>
</myxml>
we would write a stylesheet such as
<xsl:stylesheet>
<xsl:param name="mymessge" />
<xsl:template match="myxml">
<p><xsl:value-of select="message[@id=$mymessage]" /></p>
</xsl:template>
</xsl:stylesheet>
so that when we call www.example.net/transform.jsp?mymessage=2 the output will be
<p>Hello, Mars</p>