Question

I am very new in using XSL ... I have a SOAP response :-

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <insertDataResponse xmlns="http://services.test.com/schema/MainData/V1">
         <Response>Done !!!</Response>
         <Id>0</Id>
         <Age>0</Age>
      </insertDataResponse>
   </soap:Body>
</soap:Envelope>

and I am using following XSL to transform the response :-

    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <xsl:template match="/">
    <soap:Envelope>
    <soap:Body>
            <insertDataResponse xmlns="http://services.test.com/schema/MainData/V1">
                <Response>
                    <xsl:value-of select="Response" />
                </Response>
                              <Id>
                   <xsl:value-of select="Id" />
              </Id>
              <Age>
                   <xsl:value-of select="Age" />
              </Age>
            </insertDataResponse>
            </soap:Body>
    </soap:Envelope>
   </xsl:template>
 </xsl:stylesheet>

Now ... when I am trying to perform XSL transformation on the SOAP request ... I am getting the following output :-

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <insertDataResponse xmlns="http://services.test.com/schema/MainData/V1">
            <Response />
            <Id />
            <Age />
        </insertDataResponse>
    </soap:Body>
</soap:Envelope>

I am getting without any value in the attributes ... am I doing something wrong ... am I missing something ... Please Help ...

Was it helpful?

Solution

You're inside a template matching / so the

<xsl:value-of select="Response" />

and similar expressions are looking for a root-level element named Response in no namespace, which doesn't exist (the document element is named Envelope and is in the http://schemas.xmlsoap.org/soap/envelope/ namespace).

You would need to declare the http://services.test.com/schema/MainData/V1 namespace with a prefix in your stylesheet:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:md1="http://services.test.com/schema/MainData/V1"
    exclude-result-prefixes="md1">

and fix up your xpaths to match the structure:

<xsl:value-of select="soap:Envelope/soap:Body/md1:insertDataResponse/md1:Response"/>

However given how similar your inputs and outputs are you might be better off structuring things differently, basing your stylesheet on the identity transformation instead (of which there are hundreds of examples in other questions on this site).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top