01 Fahrenheit-To-Celsius. 03 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 required 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 the following XSLT processing instructions and code amendments (both in bold) to the XSL documents that you created in the previous step. 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:
<?xml version='1.0' ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="https://www.w3schools.com/xml/"> <xsl:output method="xml" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header/> <soapenv:Body> <x:FahrenheitToCelsius> <x:Fahrenheit><xsl:value-of select="fahrenheit-to-celsius/fahrenheit"/></x:Fahrenheit> </x:FahrenheitToCelsius> </soapenv:Body> </soapenv:Envelope> </xsl:template> </xsl:stylesheet>
Creating the XSLT for the response process 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>
<?xml version='1.0' encoding='utf-8' ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="https://www.w3schools.com/xml/"> <xsl:output method="html" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <Fahrenheit-To-Celsius-Response> <Fahrenheit-To-Celsius-Result> <xsl:value-of select="//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.