XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 7th, 2004, 05:57 PM
HarnessWT HarnessWT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 4 HarnessWT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #2  
Old June 7th, 2004, 07:59 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,569 jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 22 h 42 m 51 sec
Reputation Power: 835
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.

Reply With Quote
  #3  
Old June 7th, 2004, 08:56 PM
HarnessWT HarnessWT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 4 HarnessWT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by jharnois
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.



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...

Reply With Quote
  #4  
Old June 8th, 2004, 03:15 AM
nihaarika2002 nihaarika2002 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 49 nihaarika2002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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">
<xslutput 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

Reply With Quote
  #5  
Old June 8th, 2004, 08:47 AM
HarnessWT HarnessWT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 4 HarnessWT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #6  
Old June 8th, 2004, 04:20 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,569 jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 22 h 42 m 51 sec
Reputation Power: 835
There should be no need to create a variable.
Code:
<a href="{link}"><img src="www.mydomain.com/images/{id}.png" alt="{title}" /></a>

Reply With Quote
  #7  
Old June 8th, 2004, 08:35 PM
HarnessWT HarnessWT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 4 HarnessWT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #8  
Old June 9th, 2004, 04:34 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,569 jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 22 h 42 m 51 sec
Reputation Power: 835
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.

Reply With Quote
  #9  
Old June 9th, 2004, 09:44 PM
shape shape is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 shape User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by jharnois
There should be no need to create a variable.
Code:
<a href="{link}"><img src="www.mydomain.com/images/{id}.png" alt="{title}" /></a>


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>

Reply With Quote
  #10  
Old June 10th, 2004, 05:17 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,569 jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 22 h 42 m 51 sec
Reputation Power: 835
I have the following in an XSL template of mine and it works just fine:
Code:
<a href="http://{url}">

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > How to use images with XSL generated links?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |