Displaying Current Weather Status in SharePoint

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: <?xml version="1.0" encoding="UTF-8"?>
   2: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   3:     <xsl:template match="weather">
   4:         <img>
   5:             <xsl:attribute name="src">http://openweathermap.org/img/w/<xsl:value-of select="@icon"/>.png</xsl:attribute>
   6:             <xsl:attribute name="title"><xsl:value-of select="@value"/></xsl:attribute>
   7:         </img>
   8:     </xsl:template>
   9:     <xsl:template match="temperature">
  10:         <xsl:value-of select="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

                             

5 Comments

  • Thanks for this helpful information, this is quite interesting article for displaying current weather status in SharePoint.

  • Thank you so much for your post, I was searching Internet for long time till I found your post. You are my lifesaver.

  • Can someone help me with this code, I get this code when I apply the code above.

    The output from this Web Part may contain an HTML <FORM> tag, which is not supported in this Web Part. Edit the XML or XSLT source code to remove the HTML <FORM> tag.

  • Nowadays for weather conditions, there are many Office Store SharePoint weather webparts,

    Office Store Free Weather Webpart example: https://store.office.com/en-us/app.aspx?assetid=WA104379887

    Office Store Paid Weather Webpart example: https://store.office.com/en-us/app.aspx?assetid=WA104379902

    Example, for SharePoint Weather Webpart Provider: https://www.goodpointsoftware.com/sp/apps/weather.html

  • Peter: the point of this post was not to show the weather...

Add a Comment

As it will appear on the website

Not displayed

Your website