Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Giorgos Grispos 145 posts 179 karma points
    Dec 21, 2010 @ 11:51
    Giorgos Grispos
    0

    Trying to import an external weather xml feed with no luck

    Hello,

    Trying both the umbraco.library:GetXmlDocumentByUrl(url) and the ucomponent ucomponents.xml:Parse('String xml')

    I am getting this error when using the umbdebugshowtrace=true on my url.

    XSLT compile error.
      at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)
      at System.Xml.Xsl.Xslt.XsltLoader.Load(XmlReader reader)
      at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver)
      at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil)
      at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
      at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
      at umbraco.macro.CreateXsltTransform(XmlTextReader xslReader, Boolean debugMode)
      at umbraco.macro.getXslt(String XsltFile)
      at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements)

    Any ideas? It should be something really easy. Namespaces have been added for ucomponents.

    Cheers, Giorgos

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 21, 2010 @ 21:44
    Jan Skovgaard
    0

    Hi Giorgios

    It should be fairly easy to achieve using GetXMlDocumentByUrl - but sometimes it can be easy to overlook namespaces from the imported feed, which should be added. (I've had my share :-))

    Can you perhaps provide us with your XSLT code and the format of the XML you're trying to parse.

    /Jan

  • Giorgos Grispos 145 posts 179 karma points
    Dec 21, 2010 @ 22:30
    Giorgos Grispos
    0

    Hi Jan and thanks for your response,

    Here you go

    XML Weather Feed
    http://www.worldweatheronline.com/feed/weather.ashx?q=35.51,24.01&format=xml&num_of_days=2&key=a19ab7f905210052102012

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:ucomponents.cms="urn:ucomponents.cms" xmlns:ucomponents.dates="urn:ucomponents.dates" xmlns:ucomponents.io="urn:ucomponents.io" xmlns:ucomponents.members="urn:ucomponents.members" xmlns:ucomponents.strings="urn:ucomponents.strings" xmlns:ucomponents.urls="urn:ucomponents.urls" xmlns:ucomponents.xml="urn:ucomponents.xml" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ucomponents.cms ucomponents.dates ucomponents.io ucomponents.members ucomponents.strings ucomponents.urls ucomponents.xml ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>

    <xsl:template match="/">  
      <xsl:value-of select="ucomponents.xml:Parse('http://www.worldweatheronline.com/feed/weather.ashx?q=35.52,24.02&format=xml&num_of_days=2&key=a19ab7f905210052102012')"/>
    </xsl:template>

    </xsl:stylesheet>

    Cheers, Giorgos

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 21, 2010 @ 23:26
    Jan Skovgaard
    2

    Hi Giorgios

    I don't know how to use the Parse extension to do this. I have tried but I'm getting a "value must not be null" error in the umbraco XSLT editor that I can't really make any sense of at the moment. Maybe some of the bright minds behind uComponents can show us how to use it? :-)

    However I managed to import the XML using the umbraco.library:GetXMLDocumentByUrl extension.

    The following code should work for you.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:ucomponents.xml="urn:ucomponents.xml"
      exclude-result-prefixes="msxml
    msxsl umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets ucomponents.xml "
    >


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

      <xsl:variable name="weather" select="umbraco.library:GetXmlDocumentByUrl('http://www.worldweatheronline.com/feed/weather.ashx?q=35.52,24.02&amp;format=xml&amp;num_of_days=2&amp;key=a19ab7f905210052102012')"
    />
      
      <textarea>
      <xsl:copy-of select="$weather"/>
      </textarea>

      <xsl:value-of select="$weather/data//query" />

    </xsl:template>

    </xsl:stylesheet>

    I have written the XML output in a textarea so it's easy to grab and see what to match in the XSLT. Next I have just matched the query element to see if I'm actually getting a value. And I am. So you should be ready to parse and present the data from the feed now.

    Please do also notice that I have escaped the & charachter, so it says &amp; so the XSLT parser does not fail.

    Happy coding.

    /Jan

  • Giorgos Grispos 145 posts 179 karma points
    Dec 22, 2010 @ 11:11
    Giorgos Grispos
    0

    Hi Jan,

    That's great it does work. I think the &amp; escape did the job, that was the missing thing.
    I still haven't the ucomponents function working for me with or without the escape trick, maybe someone can help us on that.

    Cheers, Giorgos

Please Sign in or register to post replies

Write your reply to:

Draft