Copied to clipboard

Flag this post as spam?

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


  • Malte Baden Hansen 61 posts 158 karma points
    Aug 18, 2010 @ 16:47
    Malte Baden Hansen
    0

    Parsing external XML from a API

    Hi

    I have the following piece of XSLT in a xslt template

        <xsl:variable name="weatherUrl" select="'http://www.google.com/ig/api?weather=aalborg,denmark'" />
        <xsl:variable name="xmlnodes" select="umbraco.library:GetXmlDocumentByUrl($weatherUrl)"/>

        <xsl:value-of select="$xmlnodes//xml_api_reply/weather[1]/current_conditions/condition" />

    http://www.google.com/ig/api?weather=aalborg,denmark

    I just cant seem to get any output? I tried alot of different ways now, i also had it in a for each, but that didn't seem logic since im only getting one single "current_condition" element.

    Thanks in advance =)

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 18, 2010 @ 17:30
    Ismail Mayat
    0

    Malte,

    You have to do something like

    /*[local-name()='xml_api_reply']/*[local-name()='Weather'][1] etc etc

    Regards

    Ismail

  • Malte Baden Hansen 61 posts 158 karma points
    Aug 18, 2010 @ 17:54
    Malte Baden Hansen
    0

    I tried doing it the way Warren did in his twitter package. And from what i can see it should work?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 18, 2010 @ 18:03
    Ismail Mayat
    0

    Malte,

    I worked on something ages ago where i was pulling down google kml and the only way i could xpath into it was using local-name()= 

    Regards

    Ismail

  • Malte Baden Hansen 61 posts 158 karma points
    Aug 18, 2010 @ 18:05
    Malte Baden Hansen
    0

    Okay, thank you =)

  • Malte Baden Hansen 61 posts 158 karma points
    Aug 18, 2010 @ 18:44
    Malte Baden Hansen
    0

    The following "works"

      <xsl:for-each select="$xmlnodes/xml_api_reply//weather">
        <xsl:value-of select="@mobile_zipped" />
    </xsl:for-each>

    It outputs the value of the attribute "mobile_zipped" from the weather node which is 1
    But when i try this

    <xsl:value-of select="/current_conditions/condition" />
    .. Nothing

  • Malte Baden Hansen 61 posts 158 karma points
    Aug 18, 2010 @ 18:55
    Malte Baden Hansen
    1

    Banging my head against the door....

    I got it working.

        <xsl:variable name="weatherUrl" select="'http://www.google.com/ig/api?weather=aalborg,denmark'" />
        <xsl:variable name="xmlnodes" select="umbraco.library:GetXmlDocumentByUrl($weatherUrl)"/>

        <xsl:for-each select="$xmlnodes/xml_api_reply/weather/current_conditions">
          <xsl:value-of select="condition/@data" /> <br />
      </xsl:for-each>

    I missed the fact that it was an attribute, and not a value inside the node.. =)

  • Niels Kristiansen 166 posts 382 karma points
    Feb 16, 2011 @ 11:53
    Niels Kristiansen
    0

    I tried this and got myself a funny error coming up. When you change the city to ex. hilleroed,denmark I get an error, but no error in aalborg,denmark. How's that possilbe? It's just a url-string.

    Here is the xslt:

    <?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"
    exclude-result-prefixes="msxml umbraco.library xsl">

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

    <xsl:variable name="feedAlias" select="/macro/feedAlias"/>
    <xsl:variable name="feed" select="umbraco.library:GetXmlDocumentByUrl('http://www.google.com/ig/api?weather=aalborg,denmark')"/>
    <xsl:variable name="maxitems" select="/macro/maxItem" />

    <xsl:template match="/">
    <xsl:for-each select="$feed/xml_api_reply/weather/current_conditions">
    <img>
    <xsl:attribute name="src">http://www.google.com<xsl:value-of select="icon/@data" /></xsl:attribute>
    </img><xsl:value-of select="condition/@data" />: <xsl:value-of select="temp_c/@data" /> grader<br />
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    It's the version with aalborg that works fine, but try to change it with another city. An error occure saying System.Xml.XmlException: An error occurred while parsing EntityName. Line 5, position 62.

    Is it something some of you guy's have tried also?

     

    /Niels

Please Sign in or register to post replies

Write your reply to:

Draft