Quantcast
Channel: Development With A Dot
Viewing all articles
Browse latest Browse all 404

Displaying Current Weather Status in SharePoint

$
0
0

OpenWeatherMap.org offers a nice service for obtaining current and forecast weather conditions. Go visit it, and search for the “weather in your city”. In the results page, by hovering the link, you will get the id for the city you are interested in; for example, for “Coimbra, Portugal”, it is 2740637 (http://openweathermap.org/city/2740637).

In a SharePoint page, add a XML Viewer Web Part and point it to the address of the OpenWeatherMap.org web service: http://api.openweathermap.org/data/2.5/weather?id=2740637&mode=xml&units=metric. Of course, do replace the id and also the unit, if you like. Documentation for the web services is available at http://openweathermap.org/api. Next, add the following XSLT transformation:

   1:<?xmlversion="1.0"encoding="UTF-8"?>
   2:<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   3:<xsl:templatematch="weather">
   4:<img>
   5:<xsl:attributename="src">http://openweathermap.org/img/w/<xsl:value-ofselect="@icon"/>.png</xsl:attribute>
   6:<xsl:attributename="title"><xsl:value-ofselect="@value"/></xsl:attribute>
   7:</img>
   8:</xsl:template>
   9:<xsl:templatematch="temperature">
  10:<xsl:value-ofselect="format-number(@value, '#,0')"/>&deg;C
  11:</xsl:template>
  12:</xsl:stylesheet>

This will add an image for the current status with description and the current temperature. Yes, I could have used a single xsl:template, but I was lazy!

After you save the page, you will get a nice status like this:

image

I will probably write a post on displaying the forecast. In the meantime, enjoy! Winking smile


Viewing all articles
Browse latest Browse all 404

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>