2

I'm quite a newbie with sharepoint and especially in XML. I would like to show this weather info in my Sharepoint. I'm using XML web part & XSLT formatting. http://api.openweathermap.org/data/2.5/find?q=Lappeenranta&mode=xml

I've read and tried few tutorials with XML & XSLT formatting, but I don't know how to handle with element attributes like

    <temperature value="273.57" min="273.15" max="274.82" unit="kelvin"/>

I'd like to display on "value" attribute. Don't mind about the units =)

http://www.w3schools.com/xml/xml_xsl.asp

BR, Simo

1

Without using the XML webpart and XSL you could use the Content Editor webpart, where you specify a file from a library in your site as source.

In this file you can write something like this:

<div id="weather-icon"></div>
<div id="weather-info"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
window.baseic = window.baseic || {};
window.baseic.FetchCurrentWeather = function()
{
    jQuery.ajax({
        url: "http://api.openweathermap.org/data/2.5/find?q=Lappeenranta&mode=json&units=metric&lang=fi",
        dataType:'jsonp',
        cache: false
    }).done(function(data){
        var city = data.name;
        var currentWeatherIcon = "http://openweathermap.org/img/w/" + data.weather[0].icon + ".png";
        var currentTemp = Math.round(data.main.temp);

        jQuery('#weather-icon').html("<img width='50' src='" + currentWeatherIcon + "' />");
        jQuery('#weather-info').html(city + ", " + currentTemp + " °C");
    }); 
}

jQuery(window.baseic.FetchCurrentWeather);

</script>

Note that this example code is highly dependent on jQuery so you would need to load it if it is not already available in your site.

Also note that I use json as mode instead of XML since it is easier to parse that in Javascript :)

7
  • Thank you for the answer! Being such a rookie I'm still stuck with this. I found "Content Editor" webpart, but I don't see any field to input code. How about the jQuery, when I'm using Office 365 P1 Sharepoint? Feb 27 '14 at 14:05
  • office.microsoft.com/en-us/sharepoint-foundation-help/… under "Adding content" you can see how to point to a file. Regarding jQuery in Office 365, you should be fine using the outcommented line above (ajax.google and so on) Feb 27 '14 at 14:08
  • Thanks! Now I got it, but webpart shows only it's title without any content? Does it matter what kind of file that script is? (txt, html..?) And how to use that googleapi script? Feeling kind a noob at the moment :D Feb 27 '14 at 14:14
  • you should use .txt You can just copy everything in my code above and place in i the .txt I guess Feb 27 '14 at 14:49
  • No success so far. I've placed that txt file in Intranet folder and pointed it for Content Editor webpart. I still cannot see any data, only default webpart subject. I found some more info and maybe I should modify the "masterpage" with Sharepoint Designer? sp365.co.uk/2011/07/adding-jquery-to-sharepoint "You will need to open your MasterPage and add the following code to the header section preferably. [code lang="js"]<script type="text/javascript" src="ajax.microsoft.com/ajax/jquery/…" Feb 28 '14 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.