Ver Mensaje Individual
  #7 (permalink)  
Antiguo 26/02/2007, 20:45
Avatar de u_goldman
u_goldman
Moderador
 
Fecha de Ingreso: enero-2002
Mensajes: 8.031
Antigüedad: 23 años, 4 meses
Puntos: 98
Re: script lector de RSS

Bueno, lo prometido es deuda, perdon por la tardanza pero es que ha sido lunes de terror, aqui te dejo este xsl que le da estilo al xml de yahoo weather:

XML:
Código:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://weather.yahooapis.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://xml.weather.yahoo.com/forecast/94089_f.html</link>
   <description>Yahoo! Weather for Sunnyvale, CA</description>
   <language>en-us</language>
   <lastBuildDate>Tue, 29 Nov 2005 3:56 pm PST</lastBuildDate>
   <ttl>60</ttl>
   <yweather:location city="Sunnyvale" region="CA" country="US"></yweather:location>
   <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"></yweather:units>
   <yweather:wind chill="57" direction="350" speed="7"></yweather:wind>
   <yweather:atmosphere humidity="93" visibility="1609" pressure="30.12" rising="0"></yweather:atmosphere>
   <yweather:astronomy sunrise="7:02 am" sunset="4:51 pm"></yweather:astronomy>
   <image>
      <title>Yahoo! Weather</title>
      <width>142</width>
      <height>18</height>
      <link>http://weather.yahoo.com/</link>
      <url>http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
   </image>
   <item>
      <title>Conditions for Sunnyvale, CA at 3:56 pm PST</title>
      <geo:lat>37.39</geo:lat>
      <geo:long>-122.03</geo:long>
      <link>http://us.rd.yahoo.com/dailynews/rss/weather/
      <span style="font-size: 0px"> </span>Sunnyvale__CA/*
      <span style="font-size: 0px"> </span>http://xml.weather.yahoo.com/<span style="font-size: 0px"> </span>forecast/94089_f.html
      </link>
      <pubDate>Tue, 29 Nov 2005 3:56 pm PST</pubDate>
      <yweather:condition text="Mostly Cloudy" code="26" temp="57" date="Tue, 29 Nov 2005 3:56
          pm PST"></yweather:condition>
      <description><![CDATA[
 <img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/26.gif" /><br />
 <b>Current Conditions:</b><br />
 Mostly Cloudy, 57 F<p />
 <b>Forecast:</b><BR />
  Tue - Mostly Cloudy. High: 62 Low: 45<br />
  Wed - Mostly Cloudy. High: 60 Low: 52<br />
  Thu - Rain. High: 61 Low: 46<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://xml.weather.yahoo.com/forecast/94089_f.html">Full Forecast at Yahoo! Weather</a><BR/>
 (provided by The Weather Channel)<br/>]]>
      </description>
      <yweather:forecast day="Tue" date="29 Nov 2005" low="45" high="62" text="Mostly Cloudy"
          code="27"></yweather:forecast>
      <yweather:forecast day="Wed" date="30 Nov 2005" low="52" high="60" text="Mostly Cloudy"
          code="28"></yweather:forecast>
      <yweather:forecast day="Thu" date="01 Dec 2005" low="46" high="61" text="Rain" code="12"></yweather:forecast>
      <guid isPermaLink="false">94089_2005_11_29_15_56_PST</guid>
   </item>
</channel>
</rss>

Código:
<xsl:stylesheet version="1.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:param name="title"/>
	<xsl:template match="/rss/channel">
		<xsl:for-each select="item">
			<xsl:variable name="image" select="substring-before(description, '&lt;br /&gt;')"/>
			<span class="weather_icon"><xsl:value-of select="$image" disable-output-escaping="yes" /></span>
			<xsl:if test="string-length($title) &gt; 0">
				<xsl:value-of select="$title"/><br/>
			</xsl:if>
			<xsl:for-each select="yweather:condition">
				<div class="current"><xsl:value-of select="@text"/>, <xsl:value-of select="@temp"/>˚ F</div>
			</xsl:for-each>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
Esto te puede dar un ejemplo, el unico truco que tiene, que es lo mismo que tu XML, es que usa un namespace "yweather" en este caso, todo lo que veas en el XSL con un prefijo yweather es que esta accediendo a ese namespace, el cual lo tienes que declarar en tu xsl y utilizar en todos lados que quieras hacerlo, ya que tengas tu xsl solo tienes que combinarlos, esto lo puedes hacer mediante ASP, o bien directamente en tu XML.

Salud!
__________________
"El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera."
-- Ernest Hemingway