01 Fahrenheit-To-Celsius. 02 Fahrenheit pic x(3) value zeros.
When exported, the untransformed XML document has the following structure:
<fahrenheit-to-celsius> <fahrenheit>0</fahrenheit> </fahrenheit-to-celsius>
However, the desired XML document for the request is:
<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”> <soapenv:Header/> <soapenv:Body> <FahrenheitToCelsius xmlns="http://tempuri.org/"> <Fahrenheit>?</Fahrenheit> </FahrenheitToCelsius> </soapenv:Body> </soapenv:Envelope>
You can create an XSLT for this transformation by adding a few XSLT processing instructions to the desired XML document. Where values are required from the input document (that is, the untransformed document shown above), the processing instruction <xsl:value-of…> is used. The resulting XSLT style sheet is as follows:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”> <soapenv:Header/> <soapenv:Body> <FahrenheitToCelsius xmlns="http://tempuri.org/"> <Fahrenheit><xsl:value-of select="fahrenheit-to-celsius/fahrenheit"/></Fahrenheit> </FahrenheitToCelsius> </soapenv:Body> </soapenv:Envelope> </xsl:template> </xsl:stylesheet>
The information shown in bold are the added lines.
Creating the XSLT to process the response is similar, but targets the XML structure derived from the COBOL record layout. The COBOL layout to receive the response is:
01 Fahrenheit-To-Celsius-Response. 02 Fahrenheit-To-Celsius-Result pic X(20).
The XML document derived from this record layout has the following structure:
<fahrenheit-to-celsius-response> <fahrenheit-to-celsius-result></fahrenheit-to-celsius-result> </fahrenheit-to-celsius-response>
The web service SOAP response is (omitting unused namespace alias declarations):
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <FahrenheitToCelsiusResponse xmlns="http://tempuri.org/"> <FahrenheitToCelsiusResult>100</FahrenheitToCelsiusResult> </FahrenheitToCelsiusResponse> </soap:Body> </soap:Envelope>
Like the request, XSLT response processing instructions must be added into the desired XML document (that is, the one derived from the COBOL record layout), and <xsl:value-of…> fetches values from the input document (the SOAP response).
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://tempuri.org/"> <xsl:output method="html" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <Fahrenheit-To-Celsius-Response> <Fahrenheit-To-Celsius-Result> <xsl:value-of select="soap:Envelope/soap:Body/a:FahrenheitToCelsiusResponse/a:FahrenheitToCelsiusResult"/> </Fahrenheit-To-Celsius-Result> </Fahrenheit-To-Celsius-Response> </xsl:template> </xsl:stylesheet>
This response style sheet is only slightly more complex than the request style sheet. A SOAP document uses XML namespaces for the SOAP envelope and the SOAP body content. Therefore, the required namespace aliases are declared in the <xsl:stylesheet> processing instruction and used in the XPath expression in the <xsl:value-of> instruction. This style sheet does not do any error processing as might be needed if the web service returned a SOAP fault.