XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Chris YoullSubject: Reformat SOAP Response
Author: Chris Youll
Date: 18 Jul 2007 10:09 AM
I am working with a COTS application that allows jobs to be exposed as Web services and accessed with a SOAP request. Using Perl I am able to loop through the arrays and produce the results that I need in an HTML page. I think it could be done more efficiently by reformatting the SOAP response with XSLT which would also make it easier for other application to consume Web service.

The SOAP response returns back the field definitions for each element then the actual data. Below is a sample of the SOAP response and an example of what I am trying to accomplish.

A few questions I have about this are:
1. Is it possible to loop through the arrays, (field definitions and data values) and to create the results I am looking for using XSLT?

2. Does this even make sense to do this step to help other applications consume the Web service?

3. Can someone help me get started on the XSLT to do this?

Thank you for any assistance.


What I would like to do is to take the data in the <fieldName> </fieldName> tags and convert them to tags, then put the data within the <value></value> tags inside the corresponding tag.

--- Sample SOAP Response ------

<SOAP-ENV:Body>
<archxsd:GetArchitectServiceResponse>
<status>0</status>

<fieldDefinitions>
<fieldName>Address_Line_1</fieldName>
<fieldType>STRING</fieldType>
<fieldLength>100</fieldLength>
</fieldDefinitions>

<fieldDefinitions>
<fieldName>Address_Line_2</fieldName>
<fieldType>STRING</fieldType>
<fieldLength>100</fieldLength>
</fieldDefinitions>

<fieldDefinitions>
<fieldName>City</fieldName>
<fieldType>STRING</fieldType>
<fieldLength>100</fieldLength>
</fieldDefinitions>

<fieldDefinitions>
<fieldName>State</fieldName>
<fieldType>STRING</fieldType>
<fieldLength>40</fieldLength>
</fieldDefinitions>

<fieldDefinitions>
<fieldName>Postal_Code</fieldName>
<fieldType>STRING</fieldType>
<fieldLength>40</fieldLength>
</fieldDefinitions>

<fieldDefinitions>
<fieldName>Country_Stnd</fieldName>
<fieldType>STRING</fieldType>
<fieldLength>255</fieldLength>
</fieldDefinitions>

<fieldDefinitions>
<fieldName>Return_Code</fieldName>
<fieldType>INTEGER</fieldType>
<fieldLength>0</fieldLength>
</fieldDefinitions>

<dataRows>
<value>240 UNION BLVD</value>
<value />
<value>LAKEWOOD</value>
<value>CO</value>
<value>80228-1806</value>
<value>US</value>
<value>0</value>
<reserved>0</reserved>

</dataRows>

</archxsd:GetArchitectServiceResponse>
</SOAP-ENV:Body>

<SOAP-ENV:Body>
<archxsd:GetArchitectServiceResponse>
<status>0</status>


---- Desired Transformation Results ----

<SOAP-ENV:Body>
<archxsd:GetArchitectServiceResponse>
<status>0</status>

<Address_Line_1>240 UNION BLVD</Address_Line_1>
<Address_Line_2></Address_Line_2>
<City>LAKEWOOD</City>
<State>CO</State>
<Postal_Code>80228-1806</Postal_Code>
<Country_Stnd>US</Country_Stnd>
<Return_Code>0</Return_Code>
<reserved>0</reserved>

</archxsd:GetArchitectServiceResponse>
</SOAP-ENV:Body>

Postnext
Alberto MassariSubject: Reformat SOAP Response
Author: Alberto Massari
Date: 18 Jul 2007 11:48 AM
Hi Chris,
this could be a starting point (namespace declarations are fake, as you didn't include them in your post):

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<SOAP-ENV:Body xmlns:SOAP-ENV="aa">
<archxsd:GetArchitectServiceResponse xmlns:archxsd="bb">
<status>0</status>

<xsl:for-each select="/SOAP-ENV:Body/archxsd:GetArchitectServiceResponse/dataRows/value">
<xsl:variable name="pos" select="position()"/>
<xsl:element name="{/SOAP-ENV:Body/archxsd:GetArchitectServiceResponse/fieldDefinitions[position()=$pos]/fieldName}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</archxsd:GetArchitectServiceResponse>
</SOAP-ENV:Body>
</xsl:template>

</xsl:stylesheet>

Posttop
Chris YoullSubject: Reformat SOAP Response
Author: Chris Youll
Date: 18 Jul 2007 10:28 PM
Alberto,
Thanks for the help. After adding the name spaces your solution works great!!!

Chris

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.