Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting XML date in IMG tag in XSL doc 2

Status
Not open for further replies.

SWTpaul

Technical User
Nov 11, 2003
27
US
The following code returns a number. The number is the name of a picture (ie 32.gif, 33.gif, etc)

Code:
<xsl:value-of select="//yweather:condition/@code"/>

My question is, how can I insert the number in the IMG tag (see red code in the main XSL document)? So it would read like so...

Code:
<img src="[URL unfurl="true"]http://us.i1.yimg.com/us.yimg.com/i/us/we/52/[/URL][b]INSERT NUMBER HERE FROM XML[/b].gif" />

Thanks!

Code:
<?xml version="1.0" ?> 
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0" xmlns:yweather="[URL unfurl="true"]http://xml.weather.yahoo.com/ns/rss/1.0">[/URL] 
<xsl:output method="xml" encoding="iso-8859-1" omit-xml-declaration="yes" indent="yes"/> 
<xsl:template match="*"> 

  <tr><td colspan="2" align="center" class="evt"><b><xsl:value-of select="//yweather:location/@city"/></b></td></tr>
  <tr>
    <td align="center" class="evt">
	  [COLOR=red][b]<img src="[URL unfurl="true"]http://us.i1.yimg.com/us.yimg.com/i/us/we/52/32.gif"[/URL] />[/b][/color red]<br/>
	  <xsl:value-of select="//yweather:condition/@text"/><br/>
	  <xsl:value-of select="//yweather:condition/@temp"/><xsl:text disable-output-escaping="yes">&amp;deg;</xsl:text><br/>
	</td>
    <td align="right" valign="bottom" class="evt">
	  <table align="center" cellpadding="0" cellspacing="0">
	  <xsl:for-each select="//yweather:forecast">
	    <tr>
		  <td><xsl:value-of select="@day"/></td>
		  <td width="5"></td>
		  <td><xsl:value-of select="@high"/></td>
		  <td width="10" align="center">/</td>
		  <td><xsl:value-of select="@low"/></td>
		</tr>
	  </xsl:for-each>
	  </table>
	</td>
  </tr>
  <tr><td colspan="2" height="5" class="evt"></td></tr>
  <tr><td colspan="2" align="center" class="evt"><font size="-3" color="#999999">Sunset is at <xsl:value-of select="//yweather:astronomy/@sunset"/></font></td></tr>

</xsl:template> 
</xsl:stylesheet>
 
You need curly brackets:
Code:
<img src="[URL unfurl="true"]http://us.i1.yimg.com/us.yimg.com/i/us/we/52/{//yweather:condition/@code}.gif"[/URL] />
I would avoid using the double backslash '//' as it will search every node in the tree and can be very slow with large documents. Always specify the full path when you know it.

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top