0

I have a wired problem with DataPower now, it's not processing an XML transformation properly. With the below input:

    <response status="200"><CustomELearningVO><ClassListVO>         
    <CLASS_TAB_OBJ>
    <CLASS_TAB>
    <CLASS_OBJ>
    <ClassId>123456</ClassId>
    <ClassName>Sample Class1</ClassName>
    <Status>Not Attempted</Status>
    <Link>link</Link>
    <PlayEnable>Y</PlayEnable>
    </CLASS_OBJ>

    <CLASS_OBJ>
    <ClassId>56789</ClassId>
    <ClassName>Sample Class2</ClassName>
    <Status>Failed</Status>
    <Link>link2</Link><PlayEnable>Y</PlayEnable>
    </CLASS_OBJ>

    <CLASS_OBJ>
    <ClassId>56788</ClassId>
    <ClassName>Sample Class3</ClassName>
    <Status>Failed</Status>
    <PlayEnable>N</PlayEnable>
    <PlayMessage>"Course cannot be played as Certfication subscribed to Course has Expired"</PlayMessage>
    </CLASS_OBJ>

    </CLASS_TAB>
    </CLASS_TAB_OBJ>
    </ClassListVO><eBSErrorCode>0</eBSErrorCode><eBSErrorMessage>SUCCESS</eBSErrorMessage></CustomELearningVO></response>


When I use the below XSL, it process properly and gives me a correct output (output1). But the same gives a different output

(output2) when I put it into Datapower.

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

xmlns:wsdl="http://api.esr.nhs.uk/v1/ELearning/wsdl" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" exclude-result-prefixes="wsdl soap dp">

        <xsl:template match="/">
            <xsl:if test="/response/CustomELearningVO/ClassListVO/CLASS_TAB_OBJ/CLASS_TAB/CLASS_OBJ/ClassId">
                <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
                    <soap:Header>
                    <callerIds>
                            <userId>
                                <xsl:value-of select="1234"/>
                            </userId>
                            <responsibilityId>
                                <xsl:value-of select="576"/>
                            </responsibilityId>
                        </callerIds>
                        <requestId>
                            <xsl:value-of select="123"/>
                        </requestId>
                        <sessionToken>
                            <xsl:value-of select="8787"/>
                        </sessionToken>
                    </soap:Header>
                    <soap:Body>
                        <wsdl:getELearningClassResponse>
                                    <xsl:apply-templates select="/response/CustomELearningVO/ClassListVO/CLASS_TAB_OBJ/CLASS_TAB/CLASS_OBJ[ClassId]"/>
                        </wsdl:getELearningClassResponse>
                    </soap:Body>
                </soap:Envelope>
            </xsl:if>

            <xsl:if test="not(/response/CustomELearningVO/ClassListVO/CLASS_TAB_OBJ/CLASS_TAB/CLASS_OBJ/ClassId)">
                <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
                    <soap:Body>
                        <soap:Fault>
                            <soap:Code>
                                <soap:Value>soap:Sender</soap:Value>
                                <soap:Subcode>
                                    <soap:Value>soap:INT1001</soap:Value>
                                </soap:Subcode>
                            </soap:Code>
                            <soap:Reason>
                                <soap:Text xml:lang="en">
                                    <xsl:value-of select="/response/CustomELearningVO/eBSErrorMessage"/>
                                </soap:Text>
                            </soap:Reason>
                        </soap:Fault>
                    </soap:Body>
                </soap:Envelope>
            </xsl:if>
        </xsl:template>



    <xsl:template match="/response/CustomELearningVO/ClassListVO/CLASS_TAB_OBJ/CLASS_TAB/CLASS_OBJ">
    <learningClass>
                <classId><xsl:value-of select="ClassId"/></classId>
                <className><xsl:value-of select="ClassName"/></className>
                <status><xsl:value-of select="Status"/></status>
                <link><xsl:value-of select="Link"/></link>
                <playEnable><xsl:value-of select="PlayEnable"/></playEnable>
                <playMessage><xsl:value-of select="PlayMessage"/></playMessage>        
    </learningClass>
    </xsl:template>

    </xsl:stylesheet>

output1 (Processed in Notepad++)

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header>
    <callerIds>
      <userId>1234</userId>
      <responsibilityId>576</responsibilityId>
    </callerIds>
    <requestId>123</requestId>
    <sessionToken>8787</sessionToken>
  </soap:Header>
  <soap:Body>
    <wsdl:getELearningClassResponse xmlns:wsdl="http://api.esr.nhs.uk/v1/ELearning/wsdl">
      <learningClass>
        <classId>123456</classId>
        <className>Sample Class1</className>
        <status>Not Attempted</status>
        <link>link</link>
        <playEnable>Y</playEnable>
        <playMessage/>
      </learningClass>
      <learningClass>
        <classId>56789</classId>
        <className>Sample Class2</className>
        <status>Failed</status>
        <link>link2</link>
        <playEnable>Y</playEnable>
        <playMessage/>
      </learningClass>
      <learningClass>
        <classId>56788</classId>
        <className>Sample Class3</className>
        <status>Failed</status>
        <link/>
        <playEnable>N</playEnable>
        <playMessage>"Course cannot be played as Certfication subscribed to Course has Expired"</playMessage>
      </learningClass>
    </wsdl:getELearningClassResponse>
  </soap:Body>
</soap:Envelope>

output2 (Processed in DP)

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
   <soap:Body>
      <soap:Fault>
         <soap:Code>
            <soap:Value>soap:Sender</soap:Value>
            <soap:Subcode>
               <soap:Value>soap:INT1001</soap:Value>
            </soap:Subcode>
         </soap:Code>
         <soap:Reason>
            <soap:Text xml:lang="en">SUCCESS</soap:Text>
         </soap:Reason>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

Can anyone suggest, what the problem here? Or am I making any mistakes?

PartII

Updated the XSL a bit:


<xsl:template match="/">
    <xsl:if test="(/response/CustomELearningVO/ClassListVO)">
        <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
            <soap:Header>
            <callerIds>
                    <userId>
                        <xsl:value-of select="1234"/>
                    </userId>
                    <responsibilityId>
                        <xsl:value-of select="576"/>
                    </responsibilityId>
                </callerIds>
                <requestId>
                    <xsl:value-of select="123"/>
                </requestId>
                <sessionToken>
                    <xsl:value-of select="8787"/>
                </sessionToken>
            </soap:Header>
            <soap:Body>
                <wsdl:getELearningClassResponse>
                            <xsl:apply-templates select="/response/CustomELearningVO/ClassListVO/CLASS_TAB_OBJ/CLASS_TAB/CLASS_OBJ[ClassId]"/>
                </wsdl:getELearningClassResponse>
            </soap:Body>
        </soap:Envelope>
    </xsl:if>

    <xsl:if test="not(/response/CustomELearningVO)">
        <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
            <soap:Body>
                <soap:Fault>
                    <soap:Code>
                        <soap:Value>soap:Sender</soap:Value>
                        <soap:Subcode>
                            <soap:Value>soap:INT1001</soap:Value>
                        </soap:Subcode>
                    </soap:Code>
                    <soap:Reason>
                        <soap:Text xml:lang="en">
                            <xsl:value-of select="/response/CustomELearningVO/eBSErrorMessage"/>
                        </soap:Text>
                    </soap:Reason>
                </soap:Fault>
            </soap:Body>
        </soap:Envelope>
    </xsl:if>

</xsl:template>

But now its printing upto the apply template part:

 <soap:Envelope
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    >

        <soap:Header>
            <callerIds>
                <userId>1234</userId>
                <responsibilityId>576</responsibilityId>
            </callerIds>
            <requestId>123</requestId>
            <sessionToken>8787</sessionToken>
        </soap:Header>
        <soap:Body>
            <wsdl:getELearningClassResponse
            xmlns:wsdl="http://api.esr.nhs.uk/v1/ELearning/wsdl"
            />
        </soap:Body>

    </soap:Envelope>

Which means its not understanding this part:

<xsl:apply-templates select="/response/CustomELearningVO/ClassListVO/CLASS_TAB_OBJ/CLASS_TAB/CLASS_OBJ[ClassId]"/>

Can anyone help me to understand how can I print the rest of the message?

Sammy
  • 121
  • 4
  • 12
  • We probably must see how you put the xslt into the datapower. You probably do not output the result of the xslt transform. – Stefan Hegny Jul 28 '16 at 14:32
  • 1
    I an getting the output after the transform as output2 above. Which means it goes to the 2nd condition from the xsl "". But in notepad it gives the output as output1. – Sammy Jul 28 '16 at 14:39
  • I see, sorry, tldr - so the question boils down to that it seems that dp evaluates the long xpath check `/response/Cus..._OBJ/ClassId` different? - btw I would suggest to make a xsl:choose/xsl:when/xsl:otherwise out of that, coz this way it is it looks like it might generate two root elements in the output if the two xsl:if's aren't exactly exclusive. – Stefan Hegny Jul 28 '16 at 14:47
  • Tried that as well, but no luck. – Sammy Jul 28 '16 at 16:31
  • This is quite long, you *might* have more chance to get an answer by boiling it down to a [Minimum Complete Verifyable Example](https://stackoverflow.com/help/mcve) (sometimes in this process the error is even found yourself) – Stefan Hegny Jul 29 '16 at 09:59

0 Answers0