I’m trying to format a weather feed on my site via an RSS XML, which is easily acheived. The trouble is that it renders cascading down the page, and I want to have it running across the page.
From what I can gather, it looks as though I need to get rid of the <br /><br /> tags so they will align next to each other.
The XML source looks like this:
<description>
<![CDATA[ <b>Wednesday</b>
<br />
<img src="/images/icons/fcast_30/mostly_cloudy.gif">
<br /> Mostly cloudy<br /> -1°C - 14°C
<br /><br />
<b>Thursday</b>
<br />
<img src="/icons/fcast_30/frost_then_sunny.gif">
<br /> Frost then sunny<br /> 1°C - 13°C
<br /><br />
<b>Friday</b>
<br />
<img src="/images/icons/fcast_30/rain.gif">
<br /> Rain<br /> 2°C - 11°C
<br /><br />
<b>Saturday</b>
<br />
<img src="/images/icons/fcast_30/clearing_shower.gif">
<br /> Clearing shower<br /> 0°C - 12°C
<br /><br /> ]]>
</description>
My output XSL code look a little like this:
<xsl:for-each select="rss/channel">
<xsl:value-of select="(item/title)[2]"/>
<xsl:value-of select="substring((item/description)[1],30,15)" disable-output-escaping="yes"/>
<xsl:value-of select="(item/description)[2]" disable-output-escaping="yes"/>
</xsl:for-each>
And the output renders to look like this:
Wednesday
IMG.gif
Mostly cloudy
-1°C – 14°C
Thursday
IMG.gif
Frost then sunny
1°C – 13°C
Friday
IMG.gif
Rain
2°C – 11°C
Saturday
IMG.gif
Clearing shower
0°C – 12°C
How would I go about removing the <br /><br /> tags after each day so they align next to each other, but leaving the other singular <br> tags?
As already noted by others, the wanted transformation is impossible, unless the CDATA section (that makes the markup just regular, plain, one-dimensional text) is removed.
This complete transformation:
when applied on the XML document obtained after removing the CDATA section and correcting numerous malformedness errors:
produces the wanted, correct result:
Explanation:
The identity rule copies “as-is” every matched node, for which it is selected for execution.
There is a single template overriding the identity template. It matches any
brwhose first sibling (either preceding-sibling or following-sibling) that isn’t a whitespace-only text node, is also abr.This overriding template has empty body, which effectively “deletes” any matched
brelement from the output.