|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to use images with XSL generated links?
Forgive me if this is a stupid question, but this is my first foray into XML/XSL programming.
I am trying to loop through a list of links of nodes, generating a link, along with an image for each. Basically, this is supposed to generate a navagation bar. This is the code that I've come up with to generate the nav bar: Code:
<xsl:for-each select="nav">
<td>
<a href="{link}" class="navlink"><xsl:value-of select='concat("img src=http://www.mydomain.com/images/",id,".png")' /></a>
</td>
</xsl:for-each>
In the code above, each link's text is just the actual URL of the image I want to use for that link. I put that in there to ensure the images would be referenced correctly, which they are. However, when I try to use an IMG tag with the link, I get a processor error. The output I am hoping for is a series of <a href="URL"><img src="url_to_image" /></a> How should I be doing this? Is this something that is commonly done? Thanks! |
|
#2
|
||||
|
||||
|
You can do this the same way you put the "link" as the value of the href attribute. Begin your image tag as normal, add your attributes, then do {id} where you need the dynamic part. If you're still stuck, show some of the XML file.
__________________
# Jeremy Explain your problem instead of asking how to do what you decided was the solution. |
|
#3
|
|||
|
|||
|
Quote:
hhhmmm..I'm trying different things, but nothing seems to work. Here is a snippet of my XML: Code:
<nav> <id>hL66gE</id> <link>/services</link> <title>Services</title> </nav> <nav> <id>iQLZWU</id> <link>/hosting</link> <title>Hosting</title> </nav> <nav> <id>jWrTDa</id> <link>/portfolio</link> <title>Portfolio</title> </nav> The output I am looking for is: Code:
<A href="myURL1"><img src="www.mydomain.com/images/hL66gE.png" /></a> <A href="myURL2"><img src="www.mydomain.com/images/iQLZWU.png" /></a> <A href="myURL3"><img src="www.mydomain.com/images/jWrTDa.png" /></a> I've tried just about every combination I can think of... |
|
#4
|
|||
|
|||
|
imglink
hi
may this what u r looking for..hope this code helps... ============= <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl utput method="html" indent="yes" encoding="utf-8" omit-xml-declaration="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/><xsl:template match="/"> <xsl:for-each select="/root/nav"> <xsl:variable name="imgSrc" select="concat(concat('www.mydomain.com/images/',id),'.png')"/> <a href="myURL1"> <img src="{imgSrc}"/><xsl:value-of select="$imgSrc"/> </a> <br/> </xsl:for-each> </xsl:template> </xsl:stylesheet> ================== with regards niha |
|
#5
|
|||
|
|||
|
That did the trick niha!
As I figured, it was pretty basic, but this leads me to a question. I had been told that once you set a variable, you cannot change its value. Is that true? And if so, how is this working, considering that every time it goes through the loop, imgSrc is changing? Thanks for the help! |
|
#6
|
||||
|
||||
|
There should be no need to create a variable.
Code:
<a href="{link}"><img src="www.mydomain.com/images/{id}.png" alt="{title}" /></a>
|
|
#7
|
|||
|
|||
|
That is exactly what I had tried, and the output I was getting was:
www.mydomain.com/images/{id}.png Every time. This is what's got me so confused! |
|
#8
|
||||
|
||||
|
Well that's strange. I think it should work. I can't remember exactly and I haven't used XSL in a while. I guess you'll have to go with the other solution.
|
|
#9
|
|||
|
|||
|
Quote:
It won't work that way! Code:
<a> <xsl:attribute name="href"> <xsl:value-of select="link"/> </xsl:attribute> <img> <xsl:attribute name="src">www.mydomain.com/images/<xsl:value-of select="id"/>.png </xsl:attribute> <xsl:attribute name="alt"><xsl:value-of select="title"/> </xsl:attribute> </img> </a> |
|
#10
|
||||
|
||||
|
I have the following in an XSL template of mine and it works just fine:
Code:
<a href="http://{url}">
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > How to use images with XSL generated links? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|