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!

Pulling data from a namespace? 1

Status
Not open for further replies.

SWTpaul

Technical User
Nov 11, 2003
27
US
I am pretty much new to XML and all that goes with it. I want to put the current weather on our local intranet. The following XML file contains all the data I need, and then some:
The following contains what I want to extract:
Code:
<yweather:condition text="Clear" code="34" temp="71" date="Tue, 27 Sep 2005 2:51 pm PDT" />

How can I extract text, code, and temp in my XLS file?

Thanks.
 
you will need to post the whole xml tree for an accurate answer, but this should do it:

Code:
Text: <xsl:value-of select="//yweather:condition/@text"/><br/>
Code: <xsl:value-of select="//yweather:condition/@code"/><br/>
Temp: <xsl:value-of select="//yweather:condition/@temp"/>

hth

simon
 
Link to code:

Code:
  <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
- <rss version="2.0" xmlns:yweather="[URL unfurl="true"]http://xml.weather.yahoo.com/ns/rss/1.0"[/URL] xmlns:geo="[URL unfurl="true"]http://www.w3.org/2003/01/geo/wgs84_pos#">[/URL]
- <channel>
  <title>Yahoo! Weather - Culver City, CA</title> 
  <link>[URL unfurl="true"]http://us.rd.yahoo.com/dailynews/rss/weather/Culver_City__CA/*http://xml.weather.yahoo.com/forecast/90230_f.html</link>[/URL] 
  <description>Yahoo! Weather for Culver City, CA</description> 
  <language>en-us</language> 
  <lastBuildDate>Tue, 04 Oct 2005 9:51 am PDT</lastBuildDate> 
  <ttl>60</ttl> 
  <yweather:location city="Culver City" region="CA" country="US" /> 
  <yweather:units temperature="F" /> 
  <yweather:astronomy sunrise="6:51 am" sunset="6:34 pm" /> 
- <image>
  <title>Yahoo! Weather</title> 
  <width>142</width> 
  <height>18</height> 
  <link>[URL unfurl="true"]http://weather.yahoo.com/</link>[/URL] 
  <url>[URL unfurl="true"]http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>[/URL] 
  </image>
- <item>
  <title>Conditions for Culver City, CA at 9:51 am PDT</title> 
  <geo:lat>34.01</geo:lat> 
  <geo:long>-118.4</geo:long> 
  <link>[URL unfurl="true"]http://us.rd.yahoo.com/dailynews/rss/weather/Culver_City__CA/*http://xml.weather.yahoo.com/forecast/90230_f.html</link>[/URL] 
  <pubDate>Tue, 04 Oct 2005 9:51 am PDT</pubDate> 
  <yweather:condition text="Sunny" code="34" temp="73" date="Tue, 04 Oct 2005 9:51 am PDT" /> 
- <description>
- <![CDATA[ 
 
<img src="[URL unfurl="true"]http://us.i1.yimg.com/us.yimg.com/i/us/we/52/34.gif"[/URL] /><br />
 <b>Current Conditions:</b><br />
 Sunny, 73 F<p />
 <b>Forecast:</b><BR />
  Tue - Sunny. High: 75 Low: 59<br />
  Wed - Sunny. High: 78 Low: 62<br />
  Thu - Sunny. High: 78 Low: 60<br />
  Fri - Sunny. High: 75 Low: 58<br />
  Sat - Partly Cloudy. High: 69 Low: 56<br />
 <br />
<a href="[URL unfurl="true"]http://us.rd.yahoo.com/dailynews/rss/weather/Culver_City__CA/*http://xml.weather.yahoo.com/forecast/90230_f.html">Full[/URL] Forecast at Yahoo! Weather</a><BR/>
 (provided by The Weather Channel)<br/>
 

  ]]> 
  </description>
  <yweather:forecast day="Tue" date="04 Oct 2005" low="59" high="75" text="Sunny" code="32" /> 
  <yweather:forecast day="Wed" date="05 Oct 2005" low="62" high="78" text="Sunny" code="32" /> 
  <yweather:forecast day="Thu" date="06 Oct 2005" low="60" high="78" text="Sunny" code="32" /> 
  <yweather:forecast day="Fri" date="07 Oct 2005" low="58" high="75" text="Sunny" code="32" /> 
  <yweather:forecast day="Sat" date="08 Oct 2005" low="56" high="69" text="Partly Cloudy" code="30" /> 
  <guid isPermaLink="false">90230_2005_10_04_9_51_PDT</guid> 
  </item>
  </channel>
  </rss>

Simon I tried the code you gave me and I got an error I ran into the other day.

"Reference to undeclared namespace prefix: 'yweather'.
 
don't forget to add the namespace reference within your xsl document:

xmlns:yweather="
eg:

Code:
<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]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top