Converting the Request and Response files using XSLT

XSLT is used to convert the output from your COBOL programs (as the result of an XML OUTPUT FILE/TEXT operation) to XML. The output is dictated by the COBOL record layout; for example:
    01  Fahrenheit-To-Celsius.
        03  Fahrenheit     pic x(3) value zeros.

When exported, the untransformed XML document has the following structure:


However, the required XML document for the request is:

<soapenv:Envelope xmlns:soapenv=””>
       <FahrenheitToCelsius xmlns="">
Note: the required document has been simplified in the following ways:
  • The XML comment has been removed.
  • The XML namespace alias x is removed and a namespace declaration is moved to the <FahrenheitToCelsius> element. This simplified document is logically equivalent to the original copied from SoapUI.

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:

  1. Open TempConvertRequestF2C.xsl and update it with the lines below displayed in bold:
    <?xml version='1.0' ?>
    <xsl:stylesheet	version="1.0" xmlns:xsl="" xmlns:x="">
    	<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    	<xsl:template match="/">
        <soapenv:Envelope  xmlns:xsi="" xmlns:xsd="" xmlns:soapenv="">
                 <x:Fahrenheit><xsl:value-of select="fahrenheit-to-celsius/fahrenheit"/></x:Fahrenheit>

    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:


    The web service SOAP response is (omitting unused namespace alias declarations):

    <soap:Envelope xmlns:soap="">
          <FahrenheitToCelsiusResponse xmlns="">
  2. Open TempConvertResponseF2C.xsl and update it with the lines below displayed in bold:
    <?xml version='1.0' encoding='utf-8' ?>
    <xsl:stylesheet	version="1.0" xmlns:xsl="" xmlns:soap="" xmlns:a="">
    	<xsl:output method="html" encoding="UTF-8" indent="yes"/>
    	<xsl:template match="/">
                    <xsl:value-of select="//a:FahrenheitToCelsiusResult"/>

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.