Skip to content

Instantly share code, notes, and snippets.

@hacklschorsch
Created December 19, 2011 23:29
Show Gist options
  • Save hacklschorsch/1499418 to your computer and use it in GitHub Desktop.
Save hacklschorsch/1499418 to your computer and use it in GitHub Desktop.
XSL transform the Google Weather Feed into HTML (sorry, the annotations are in German)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/strict">
<credit>Florian Sesser für CoSeTrain</credit>
<credit_URL>http://www.cosetrain.com/</credit_URL>
<xsl:output method="html" indent="yes" encoding="UTF-8" media-type="text/html"/>
<xsl:template match="/">
<xsl:element name = "div">
<xsl:attribute name = "id">XSLTWetter</xsl:attribute>
<xsl:element name = "ul">
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match = "forecast_information">
<xsl:element name = "li">
<xsl:attribute name = "id">header</xsl:attribute>
<xsl:element name = "span">
<xsl:attribute name = "class">WeFu</xsl:attribute>
<xsl:text>Wetter für </xsl:text>
</xsl:element>
<xsl:element name = "span">
<xsl:attribute name = "class">city</xsl:attribute>
<xsl:value-of select = "postal_code/@data"/>
</xsl:element>
<xsl:comment>
<xsl:text>TS: </xsl:text>
<xsl:value-of select = "current_date_time/@data"/>
</xsl:comment>
</xsl:element>
</xsl:template>
<xsl:template match = "forecast_conditions">
<xsl:element name = "li">
<xsl:attribute name = "class">forecast</xsl:attribute>
<xsl:element name = "img">
<xsl:attribute name = "class">icon</xsl:attribute>
<xsl:attribute name = "src">/static/XSLTwetter/img/<xsl:value-of select = "substring-after(icon/@data, 'weather/')"/>
</xsl:attribute>
<xsl:attribute name = "alt">
<xsl:value-of select = "condition/@data"/>
</xsl:attribute>
<xsl:attribute name = "title">
<xsl:value-of select = "condition/@data"/>
</xsl:attribute>
</xsl:element>
<xsl:element name = "span">
<xsl:attribute name = "class">DOW</xsl:attribute>
<xsl:value-of select = "day_of_week/@data"/>
<xsl:text> </xsl:text>
</xsl:element>
<xsl:element name = "span">
<xsl:attribute name = "class">cond</xsl:attribute>
<xsl:value-of select = "condition/@data"/>
</xsl:element>
<xsl:element name = "span">
<xsl:attribute name = "class">temps</xsl:attribute>
<xsl:element name = "span">
<xsl:attribute name = "class">low</xsl:attribute>
<xsl:value-of select = "low/@data"/>
<xsl:text>°</xsl:text>
</xsl:element>
<xsl:text> bis </xsl:text>
<xsl:element name = "span">
<xsl:attribute name = "class">high</xsl:attribute>
<xsl:value-of select = "high/@data"/>
<xsl:text>°</xsl:text>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:transform>
@hacklschorsch
Copy link
Author

This needs to be fed into an XSLT processor (we use Xalan). We use cron line to d/l the weather info from Google every 4 hours or so and embed them into our site:

wget --quiet 'http://www.google.com/ig/api?weather=Heroldsbach&hl=de' --output-document=- | iconv --from-code=ISO-8859-1 --to-code=UTF-8 | xalan -xsl xslt_google_wetter_3.xslt -out /public_html/static/XSLTwetter/heroldsbach.html 2>/dev/null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment