Copied to clipboard

Flag this post as spam?

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


  • Kasper Dyrvig 246 posts 379 karma points
    Jul 26, 2011 @ 15:39
    Kasper Dyrvig
    0

    How to get xml data from webservice

    Hi all - thanks for a great CG11!

    I have a strange issue here... I have this webservice that generate its result as xml. I can see I get the data I want, but I can't get my xslt to dig into it!?

    My basic xslt:

    <xsl:variable name="cheap1" select="umbraco.library:GetXmlDocumentByUrl('http://domain.dk/webservices/flight.asmx/GetFlightSuggestions?departureLocation=CPH&amp;arrivalLocation=LON&amp;maxNumberOfAlternatives=1')"/>
    <a href="{$cheap1//BookingUrl}">KBH til London <b><xsl:value-of select="$cheap1//Price"/>,-</b></a>

    The data from the webservice:

    <arrayofflightsuggestiondc 
    xmlns="http://webservices.domain.se/partners/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"><flightsuggestiondc><departuredate>2011-08-09T00:00:00</departuredate><price>646</price><currency>DKK</currency><carriername>Norwegian</carriername><bookingurl>http://domain.dk/booking/flights.aspx?adt=1&amp;toDate=2011-08-09&amp;toLocation=LON&amp;toHour=0&amp;carrierCode=&amp;chdAge=&amp;cityCode=0&amp;fromDate=2011-08-09&amp;fromLocation=CPH&amp;departureId=&amp;fromHour=0&amp;flightDirect=False&amp;agencyNumber=&amp;flightOneway=False&amp;package=False&amp;rooms=&amp;surroundingDays=False&amp;toCity=&amp;fromCity=</bookingurl></flightsuggestiondc></arrayofflightsuggestiondc>;

    Please help

  • aghy 129 posts 308 karma points
    Jul 26, 2011 @ 15:45
    aghy
    0

    Hi Kasper,

    Just a guess but I think by using double / in {$cheap1//BookingUrl} means that BookingUrl is directly under the root node, which it isn't. So I think you could either use a single / like {$cheap1/BookingUrl} or write the full path like {$cheap1/FlightSuggestionDC/BookingUrl}

    Ben

  • Kasper Dyrvig 246 posts 379 karma points
    Jul 27, 2011 @ 08:16
    Kasper Dyrvig
    0

    Hi Ben

    I have tried you suggestion in multiple ways, but no sign of success. According to my understading of XSLT double slash "//" tells to go deeper into the dataset find whatever comes after //. (See here: http://w3schools.com/xpath/xpath_syntax.asp)

  • Paul Blair 466 posts 731 karma points
    Jul 27, 2011 @ 22:33
    Paul Blair
    0

    Is it case sensitive i.e. $cheap1/BookingUrl vs $cheap1/bookingurl

    Also try doinf <xsl:copy select="$cheap1" /> to inspect the XML to see if there are clues there.

     

  • Kasper Dyrvig 246 posts 379 karma points
    Jul 28, 2011 @ 09:51
    Kasper Dyrvig
    0

    Hi Poul,

    Yes, it is case sensitive - but I have copied the tag names from the source code, so I'm pretty sure I have it currect. To be honest I already have tried with lowercase etc.

    The copy-of methot I have also tried. The "data from the webservice"-code i posted in my question is from a copy-of the $cheap1.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jul 29, 2011 @ 00:00
    Chriztian Steinmeier
    0

    Hi Kasper,

    Welcome to the namespaces section of the XSLT manual :-)

    The XML you're receiving has a default namespace associated with it (the xmlns="http://webservices.domain.se/partners/" part) which means that every element in the file is "scoped" to that namespace; In order for your XSLT file to be able to select those elements, it needs to do two things:

    1. Define a prefix and associate it with the namespace-URI (case-sensitive!) of the XML file
    2. Use that prefix to select the elements

    First of all, make sure that you did the copy-of inside a <textarea> element in the Visualizer (otherwise, it lowercases all the tags - and your XML looks suspiciously like it was mangled with by the visualizer :-) 

    Now, define the namespace (I guess you changed it for obvious reasons, so I'm using the one you supplied):

    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umbraco.library="urn:umbraco.library"
        xmlns:data="http://webservices.domain.se/partners/"
        exclude-result-prefixes="umbraco.library data"
    >
    

    (I'm using "data" as the prefix, but you can use pretty much whatever you want)

    Then, use the prefix when accessing data from the document:

    <a href="{$cheap1//data:BookingUrl}">KBH til London <b><xsl:value-of select="$cheap1//data:Price"/>,-</b></a>

    Yay - done!

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Jul 29, 2011 @ 10:39
    Kasper Dyrvig
    0

    Thanks to Chriztian - the xslt guru of all xslt gurus. It works like charm!

    Thanks for very valuable information!

Please Sign in or register to post replies

Write your reply to:

Draft