WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-19-2008, 04:41 PM
4bidden 4bidden is offline
WebProWorld New Member
 

Join Date: Oct 2005
Location: Tempe, AZ
Posts: 17
4bidden RepRank 0
Default How to access XML item through XSL issue

I'm working with a Yahoo weather XML feed, and I can't for the life of me figure out how to access the item I need.

Here is the XML file

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
 <channel>
 <title>Yahoo! Weather - Sunnyvale, CA</title>
 <link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/94089_f.html</link>
 <description>Yahoo! Weather for Sunnyvale, CA</description>
 <language>en-us</language>
 <lastBuildDate>Wed, 19 Mar 2008 12:27 pm PDT</lastBuildDate>
 <ttl>60</ttl>
 <yweather:location city="Sunnyvale" region="CA" country="US" />
 <yweather:units temperature="F" distance="mi" pressure="in" speed="mph" />
 <yweather:wind chill="59" direction="20" speed="8" />
 <yweather:atmosphere humidity="67" visibility="1609" pressure="30.23" rising="0" />
  <yweather:astronomy sunrise="7:12 am" sunset="7:20 pm" />
  <image>
 <title>Yahoo! Weather</title>
 <width>142</width>
 <height>18</height>
 <link>http://weather.yahoo.com/</link>
 <url>http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
 </image>
 <item>
 <title>Conditions for Sunnyvale, CA at 12:27 pm PDT</title>
  <geo:lat>37.39</geo:lat>
 <geo:long>-122.03</geo:long>
  <link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/94089_f.html</link>
 <pubDate>Wed, 19 Mar 2008 12:27 pm PDT</pubDate>
 <yweather:condition text="Partly Cloudy" code="30" temp="59" date="Wed, 19 Mar 2008 12:27 pm PDT" />
 <description><![CDATA[
<img src="http://l.yimg.com/us.yimg.com/i/us/we/52/30.gif" /><br />
 <b>Current Conditions:</b><br />
 Partly Cloudy, 59 F<BR /><BR />
 <b>Forecast:</b><BR />
  Wed - Partly Cloudy. High: 61 Low: 45<br />
  Thu - Sunny. High: 62 Low: 45<br />
 <br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/94089_f.html">Full Forecast at Yahoo! Weather</a><BR/>
 (provided by The Weather Channel)<br/>
 ]]></description>
 <yweather:forecast day="Wed" date="19 Mar 2008" low="45" high="61" text="Partly Cloudy" code="30" />
<yweather:forecast day="Thu" date="20 Mar 2008" low="45" high="62" text="Sunny" code="32" />
  <guid isPermaLink="false">94089_2008_03_19_12_27_PDT</guid>
 </item>
</channel>
</rss><!-- p4.weather.sp1.yahoo.com compressed/chunked Wed Mar 19 12:51:32 PDT 2008 -->


What I need is the text and temp pulled out of the yweather:condition item above. In my XSL document I can access everything fine using <xsl:value-of select="rss/channel/item/title" /> for example, but whenever I try and reference the yweather item, I don't know how to pull the attributes from inside it. I read about using the @ sign, so <xsl:value-of select="rss/channel/item/yweather:condition/@text" /> should work, but errors the application. I think it has something to do with references the item with a title such as this, yweather:condition

Its got to be something small I'm missing. Any help???

Last edited by 4bidden : 03-19-2008 at 04:47 PM.
Reply With Quote
  #2 (permalink)  
Old 03-19-2008, 08:59 PM
incrediblehelp's Avatar
incrediblehelp incrediblehelp is offline
Moderator
WebProWorld Moderator
 

Join Date: Jan 2004
Location: Live in Cincy Now
Posts: 7,444
incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4
Default Re: How to access XML item through XSL issue

Do you have to use this one? Why not try another like weather.com?
Reply With Quote
  #3 (permalink)  
Old 03-20-2008, 09:51 AM
wige's Avatar
wige wige is offline
Moderator
WebProWorld Moderator
 

Join Date: Jun 2006
Location: United States
Posts: 1,648
wige RepRank 4wige RepRank 4wige RepRank 4
Default Re: How to access XML item through XSL issue

The "yweather" portion is not part of the element name, rather it is the namespace for that element, just as in your XSLT document "xslt" is the namespace for the XSLT elements. Try
Code:
<xsl:value-of select="condition@text" />
Also, I don't think there should be a slash between condition and @text in your code, that may be the problem.
__________________
The best way to learn anything, is to question everything.
Interestingly Average Security Blog
Reply With Quote
  #4 (permalink)  
Old 03-20-2008, 02:12 PM
4bidden 4bidden is offline
WebProWorld New Member
 

Join Date: Oct 2005
Location: Tempe, AZ
Posts: 17
4bidden RepRank 0
Default Re: How to access XML item through XSL issue

Quote:
Originally Posted by incrediblehelp View Post
Do you have to use this one? Why not try another like weather.com?
Weather.com's feed does not contain items that have ONLY the condition and ONLY the temp. Yahoo's does if I could just figure out how to use it! Grrrr

EDIT: I found a fix from another web board. Here is what needed changed. I'm not familiar enough with this to know exactly why this was needed or what it did.

1. Change the yweather namespace declaration on your XSLT to xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
2. Remove the rss namespace declaration on your XSLT, it's not necessary
3. Change your parameter's XPath to: rss/channel/item/yweather:condition/@text
Reply With Quote
  #5 (permalink)  
Old 06-10-2008, 03:57 PM
jrc1313 jrc1313 is offline
WebProWorld New Member
 

Join Date: Jun 2008
Posts: 1
jrc1313 RepRank 0
Smile Re: How to access XML item through XSL issue

Hi 4bidden,


I am trying to do the same thing with teh Yahoo Weather feed but was not sure with your recommendations:

Change the yweather namespace declaration on your XSLT to xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
2. Remove the rss namespace declaration on your XSLT, it's not necessary
3. Change your parameter's XPath to: rss/channel/item/yweather:condition/@text

I am using php 5, and can access item fine like this


$xml = @file_get_contents("Yahoo! Weather - Allentown, PA");
$xml = new SimpleXMLElement($xml);
$a = $xml->channel->item->title;

But if I am trying to access the yweather:condition and put in
$a = $xml->channel->item->yweather:condition->text I get errors on the :

Thansk for any help!
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble getting latest record for a given item MOON Database Discussion Forum 1 11-07-2007 08:00 AM
MSN Item Search EliteAF MSN Search Discussion Forum 1 08-14-2007 02:02 PM
Interesting item I found on ebay countryjoe Breakroom (General: Any Topic) 0 11-10-2006 01:46 PM
Credit Card Processing for 1 item saylor eCommerce Discussion Forum 2 01-12-2006 05:49 AM
MS Access 2000 issue ADAM Web Design IT Discussion Forum 6 07-07-2005 12:08 AM


Search Engine Friendly URLs by vBSEO 3.0.0