This project is read-only.

XSLT transformation of data

Downloads section contains XSLT files for all three types of XML data sets returned by service.
  • LocationSearch.xsl - contains transformation for location search results
  • CurrentConditions.xsl - contains transformation for Current conditions
  • WeatherForecast.xsl - contains transformation for Weather forecast
  • Common.xsl - this file is shared between CurrentConditions.xsl and WeatherForecast.xsl

XSLT sample application

Sample application called XsltWeatherResultTransformation that can be found in the Downloads section has been developed to show how simple is to apply transformation to service XML data.
Code snippet below is an extract from the sample app showing how to transform weather conditions data in XML format to HTML file.

using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;


//Load XSLT transformation
string xsltPath = @".\XmlResponses/Xslt/CurrentConditions.xsl";
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = CredentialCache.DefaultCredentials;
XslCompiledTransform transformXmlToHtml = new XslCompiledTransform();
transformXmlToHtml.Load(new XPathDocument(xsltPath), XsltSettings.Default, resolver);
//Retrieve data
WeatherClient weatherClient = new WeatherClient("Parner Id here", "License Key here");
List<Location> locations = weatherClient.GetLocation("Paris, France");
string xml = weatherClient.GetCurrentConditionsAsXml(locations[0]);
//Transform XML into HTML
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
XmlReader reader = XmlReader.Create(new StringReader(xml));
using (XmlWriter textWriter = XmlWriter.Create("Current_Weather_Conditions_In_Paris.html", settings))
    transformXmlToHtml.Transform(reader, textWriter);

Last edited Jul 6, 2011 at 7:51 PM by mulawam, version 3


No comments yet.