0

我正在从以下 XML 中的描述标签中提取数据:

<rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" version="2.0">
<channel>
<title>Yahoo! Weather - Dubai, AE</title>
<link>
http://us.rd.yahoo.com/dailynews/rss/weather/Dubai__AE/*http://weather.yahoo.com/forecast/AEXX0004_f.html
</link>
<description>Yahoo! Weather for Dubai, AE</description>
<language>en-us</language>
<lastBuildDate>Mon, 04 Mar 2013 9:01 pm GST</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Dubai" region="" country="United Arab Emirates"/>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
<yweather:wind chill="75" direction="350" speed="6"/>
<yweather:atmosphere humidity="69" visibility="6.21" pressure="29.97" rising="0"/>
<yweather:astronomy sunrise="6:39 am" sunset="6:23 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>
http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif
</url>
</image>
<item>
<title>Conditions for Dubai, AE at 9:01 pm GST</title>
<geo:lat>25.27</geo:lat>
<geo:long>55.31</geo:long>
<link>
http://us.rd.yahoo.com/dailynews/rss/weather/Dubai__AE/*http://weather.yahoo.com/forecast/AEXX0004_f.html
</link>
<pubDate>Mon, 04 Mar 2013 9:01 pm GST</pubDate>
<yweather:condition text="Fair" code="33" temp="75" date="Mon, 04 Mar 2013 9:01 pm GST"/>
<description>
<![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/33.gif"/><br /> <b>Current Conditions:</b><br /> Fair, 75 F<BR /> <BR /><b>Forecast:</b><BR /> Mon - Clear. High: 86 Low: 67<br /> Tue - Sunny. High: 89 Low: 68<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Dubai__AE/*http://weather.yahoo.com/forecast/AEXX0004_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/> (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]>
</description>
<yweather:forecast day="Mon" date="4 Mar 2013" low="67" high="86" text="Clear" code="31"/>
<yweather:forecast day="Tue" date="5 Mar 2013" low="68" high="89" text="Sunny" code="32"/>
<guid isPermaLink="false">AEXX0004_2013_03_05_7_00_GST</guid>
</item>
</channel>
</rss>
<!--
 api3.weather.ch1.yahoo.com Mon Mar  4 17:44:49 PST 2013 
-->

使用这个 XSLT:

<xsl:template match="channel">
    <xsl:element name="div">
        <!-- This holds the image links-->
        <xsl:attribute name="id">
            <xsl:text>weatherdiv</xsl:text>
        </xsl:attribute>
        <table>
            <xsl:attribute name="class">wtab</xsl:attribute>
            <xsl:apply-templates select="item" />
        </table>
    </xsl:element>
</xsl:template>
<xsl:template match="item">
    <tr>
        <td colspan="2" >
            <xsl:attribute name="id">
                <xsl:text>titletd</xsl:text>
            </xsl:attribute>
            <xsl:value-of select="title"  />
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <xsl:attribute name="id">
                <xsl:text>descriptiontd</xsl:text>
            </xsl:attribute>
            <xsl:value-of select="description" disable-output-escaping="yes" />
        </td>
    </tr>
    <!-- ... -->
</xsl:template>

这一行:

<xsl:value-of select="description" disable-output-escaping="yes" />

获取描述中的所有内容,如何防止它获取此部分:

(provided by <a href="http://www.weather.com" >The Weather Channel</a>)
4

1 回答 1

1

您可以使用以下substring-before()功能:

<xsl:value-of select="substring-before(description, '(provided')" disable-output-escaping="yes" />
于 2013-03-04T18:48:17.460 回答