Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2009, 06:24 AM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default how to achieve an output and receive input from a web service?

Hi again.. I don't know if this question strictly ties in with this area of the forum however I'm not sure how involved XSLT is with this and it does relate to how I would use xlink:href:

http://www.multimap.com/openapidocs/...n.htm#examples
That URL points to the multimap web service for coordinate transformation between various coordinate reference systems. It would be helpful to me if I could use this web service but I'm struggling to understand how the process works.

Lets say I have the following xml fragment:
Code:
<gml:Point gml:id="slopeBaseWGS84" srsName="WGS84">
     <gml:pos>54.439390 -3.294112</gml:pos>
</gml:Point>
And i want to convert those to OS grid latitude and longitude values using their web service and then to use the values they feed back.

They request for an 'xml output' of something like this:

Code:
http://developer.multimap.com/API/convert/1.2/OA09042217172872167?output=xml&system=osng&x_1=505658&y_1=316165&x_2=316165&y_2=505658
(where OA09042217172872167 is an example API key)

This gives the result in XML of:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Results xmlns="http://clients.multimap.com/API" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://clients.multimap.com/API http://clients.multimap.com/Schema/convert_1.2.xsd">
  <Point>
    <Lat>54.43940</Lat>
    <Lon>-3.29411</Lon>
  </Point>
</Results>
Which is correct. (To see this i simply entered the URL in to the browser directly.)

What I'd like to know is how I could implement this in to my process? Currently the user submits an XML file (according to my schema) and it produces (via XSLT's & Saxon-B) outputs such as SVG, KML and HTML pages (which all interlink to produce a 'case' page).

It would be very useful if I could set something up so that once the xml was submitted it would then, where required, translate coordinate pairs in to another coordinate reference system (CRS), return their values in to a known place within the XML (such as as a following sibling to the XML fragment shown nearer the top) so that the XSLT files could then perform translations based on the new coordinates. Maybe it works differently?

Thanks for any help
p.s. I've read up on SOAP before but don't recall this type of request and integration, but maybe I'm wrong.
 
Old April 23rd, 2009, 07:26 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It looks like this is a REST API rather than a SOAP web service, so all you need to do is to construct a URI in the form that Multimap want it, and call the doc() function with this URI as the argument. The result will be the XML response from the web service, which you can then process using XSLT in the usual way.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 23rd, 2009, 08:00 AM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

Ok these maybe seems doable in my time frame so could I just present a bit of example code and see if we can get it working. I've not worked with the doc function before but I've seen it used a fair amount.

Example XML code:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="translation.xsl"?>
<geo:slope xmlns:geo="http://www.dur.ac.uk/geo-engineering"
    xmlns:gml="http://www.opengis.net/gml">
    <geo:toe>
        <geo:location>
            <gml:Point gml:id="slopeBase" srsName="EPSG:27700">
                <gml:pos>316165 505658</gml:pos>
            </gml:Point>
        </geo:location>
    </geo:toe>
</geo:slope>
An xsl I just wrote to generate the URL from this xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:geo="http://www.dur.ac.uk/geo-engineering" xmlns:gml="http://www.opengis.net/gml"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs geo gml">

    <xsl:template match="geo:slope">
        <xsl:variable name="crest" as="xs:integer+" select="geo:point(geo:toe/geo:location)"/>
        <!-- http://developer.multimap.com/API/convert/1.2/OA09042217172872167?output=xml&system=osng&x_1=316165&y_1=505658 -->
        <xsl:text><![CDATA[http://developer.multimap.com/API/convert/1.2/OA09042217172872167?output=xml&system=osng&x_1=]]></xsl:text>
        <xsl:value-of select="$crest[1]"/>
        <xsl:text><![CDATA[&y_1=]]></xsl:text>
        <xsl:value-of select="$crest[2]"/>
    </xsl:template>

    <xsl:function name="geo:point" as="xs:integer+">
        <xsl:param name="location" as="element(geo:location)"/>
        <xsl:variable name="point" as="xs:string"
            select="$location/gml:Point[@srsName='EPSG:27700']/gml:pos"/>
        <xsl:sequence select="xs:integer(substring-before($point, ' '))"/>
        <xsl:sequence select="xs:integer(substring-after($point, ' '))"/>
    </xsl:function>

</xsl:stylesheet>
So you say that using the doc function can allow for the sending and return of the data during the one transformation process? Sorry, again I'm just trying to get my head around the process. Alot of the time the actual coding part isn't what I struggle with, it's more the practical implications of how it's used in the website process.

edit: I've just tried this xsl code
Code:
        <xsl:variable name="MM" select="doc('http://developer.multimap.com/API/convert/1.2/OA09042217172872167?output=xml&amp;system=osng&amp;x_1=316165&amp;y_1=505658')" />
        <xsl:value-of select="$MM" />
And it returns the values as expected, which is great! Now I'm just going to try and split the values to hold separately in variables

Last edited by jamesdurham; April 23rd, 2009 at 08:14 AM..
 
Old April 23rd, 2009, 08:20 AM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

Ok as I expected, I am struggling to receive the information in a broken down format so that each value can be held in a separate variable, 'Lat' and 'Long'.

Any ideas?Thanks

edit:
I would have thought that this would work:
Code:
        <xsl:variable name="MM" select="doc('http://developer.multimap.com/API/convert/1.2/OA09042217172872167?output=xml&amp;system=osng&amp;x_1=316165&amp;y_1=505658')/Results/Point/Lat" />
        <xsl:value-of select="$MM" />
However it's not giving any output and I've also tried without 'Results' in the xpath and various other xpath methods.

Last edited by jamesdurham; April 23rd, 2009 at 08:35 AM..
 
Old April 23rd, 2009, 08:51 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>So you say that using the doc function can allow for the sending and return of the data during the one transformation process? Sorry, again I'm just trying to get my head around the process.

Sounds like my grandmother, who was reluctant to turn a lightswitch on because she wanted to know how it worked. You give doc() a URI, and it goes off to the web and asks for the content at that URI, just like your web browser does. Don't worry about how it works.
<xsl:template match="geo:slope">
<xsl:variable name="crest" as="xs:integer+" select="geo:point(geo:toe/geo:location)"/>
<!-- http://developer.multimap.com/API/co...165&y_1=505658 -->
<xsl:copy-of select="doc(concat('http://developer.multimap.com/API/convert/1.2/OA09042217172872167?output=xml&amp;system=osng&amp ;x_1=',
$crest[1],'&amp;y_1=',$crest[2]))"/>
</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference

Last edited by mhkay; April 23rd, 2009 at 08:53 AM.. Reason: correct the code
 
Old April 23rd, 2009, 08:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Ok as I expected, I am struggling to receive the information in a broken down format so that each value can be held in a separate variable, 'Lat' and 'Long'.

I thought you said it came back as XML?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 23rd, 2009, 08:59 AM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

It's what it says on this page: http://www.multimap.com/openapidocs/...sformation.htm

edit: ok, your code seems to handle it far better! nice and neat solution and provides the feedback of:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Results xmlns="http://clients.multimap.com/API" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://clients.multimap.com/API http://clients.multimap.com/Schema/convert_1.2.xsd">
  <Point>
    <Lat>54.43940</Lat>
    <Lon>-3.29411</Lon>
  </Point>
</Results>
Thanks a lot for that, it should be a useful function for me in opening up some more possibilites in the future, especially in relation to KML. i.e. for my slope cross-section SVG image I project nearby slope points (taken in eastings/northings because they are 'flat' metre values) on to a common line between the toe and crest of the slope. In google earth though it is required to use latitude and longitude for point positioning and therefore these newly calculated 'projected' eastings and northing couldnt be shown. Now I can convert these values in to lat/long equivalents and then display the cross section just as well in google earth!

Last edited by jamesdurham; April 23rd, 2009 at 09:05 AM..
 
Old April 23rd, 2009, 09:13 AM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

ahh now I'm definitely sounding stupid!

Your code supplies the correct output from the web service which is great - the problem for me is still to hold these values in separate variables as I can't seem to access them still. Sorry about this!
 
Old April 23rd, 2009, 09:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Well, you can capture the result in a variable like this:

<xsl:variable name="result" select="doc(......)"/>

and then index into it using XPath like this, for example:

<xsl:for-each select="$result/r:Results/r:Point"
xmlns:r="http://developer.multimap.com/API"/>
<xsl:value-of select="r:x"/>
</xsl:for-each>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 23rd, 2009, 10:08 AM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

I might be mis-interpreting what goes in doc(...) but the following code is producing no output:

Code:
    <xsl:template match="geo:slope">
        <xsl:variable name="toe" as="xs:integer+" select="geo:point(geo:toe/geo:location)"/>
        
        <xsl:variable name="result" select="doc(concat('http://developer.multimap.com/API/convert/1.2/OA09042217172872167?output=xml&amp;system=osng&amp;x_1=',
        $toe[1],'&amp;y_1=',$toe[2]))"/>

        <xsl:for-each select="$result/r:Results/r:Point"
            xmlns:r="http://developer.multimap.com/API">
        <xsl:value-of select="r:x"/>
        </xsl:for-each>
    </xsl:template>
Or do i include the xsl:copy-of as before and then make reference to that in the 'result' variable? If so (which seems to perhaps be the only way), how can I do that?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying DOCTYPE in input to the output xml mrame XSLT 3 July 31st, 2008 04:26 PM
XSLT with output very similar to input sindrit XSLT 2 July 30th, 2007 08:38 AM
jsp - input/output - html?? tra77 JSP Basics 0 April 14th, 2006 04:35 AM
input:output file ct ASP.NET 1.0 and 1.1 Basics 1 September 27th, 2005 09:43 AM
Web Service HTML Output km0ti0n .NET Web Services 1 April 6th, 2004 11:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.