API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  XSLT XML Read Error

    Posted Sun May 21, 2023 03:12 AM
    Edited by Fahad Hassan Mon May 22, 2023 06:11 AM

    HI Team,

    I am sending XML Request to my API and just adding request in my output payload but only values of xml request are added to new payload and xml tags are not there in new Paylaod in Response. As you can see in output XML Tags are missing.I am attaching the API Also . I am using APIC 2018 Version

    @Steve Linn @Ashok Beshra 

    XML Input : 

    <SaveContactResponse xmlns="">
        <ContactId>1168255</ContactId>
        <HasErrors>false</HasErrors>
    </SaveContactResponse>


    XML Output:

    <?xml version="1.0" encoding="UTF-8"?>
    <Response xmlns:apigw="http://www.ibm.com/xmlns/datapower/2017/11/apigateway">
        1168255
        false
    </Response>



    ------------------------------
    Fahad Hassan
    ------------------------------



  • 2.  RE: XSLT XML Read Error

    Posted Mon May 22, 2023 09:00 AM

    Hi Fahad,

    I'd need to see your API to be 100% certain, but the symptom you're describing is of a xslt that is doing a <xsl:value-of instead of a <xsl:copy-of  when adding your  payload to the Response element.  The stylesheet that is doing this should also specify the apigw prefix in the xsl:stylesheet's exclude-result-prefixes attribute as the Response element doesn't need that namespace uri for any of its children elements.

    Best Regards,

    Steve



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------



  • 3.  RE: XSLT XML Read Error

    Posted Tue May 23, 2023 08:40 AM

    I have same issue with me that I am sending XML Request to my API and just adding request. can anyone help me.



    ------------------------------
    Interior designs
    ------------------------------



  • 4.  RE: XSLT XML Read Error

    Posted Tue May 23, 2023 03:43 PM
      |   view attached

    Hi @Steve Linn ,

    I was able to resolve the issue by using <xsl:copy-of instead of <xsl:value-of tag. However i was doing AES Encryption Decryption in my API but i can see that while decrypting that same issue has appeared in which xml tags are gone after decryption. Can you please help me on this. Attached is API Yaml.

    BR

    Fahad



    ------------------------------
    Fahad Hassan
    ------------------------------

    Attachment(s)

    yaml
    EncryDecryptAPI.yaml   6 KB 1 version


  • 5.  RE: XSLT XML Read Error

    Posted Thu May 25, 2023 05:08 PM

    Hi Fahad, 

    It took me a while looking at your code and I eventually took your api and placed it in my test environment.  At issue is the statement in the encrypt xsl

     <xsl:value-of select="dp:encrypt-string($vAlgorithm,$vKey,$currentPayload)"/>
    

    https://www.ibm.com/docs/en/datapower-gateway/10.5.0?topic=functions-dpencrypt-string notes that the third argument is a string, so when passing in an input payload of <hello>world</hello> and you pass in an XML nodeset, it is converted to a string, yes like a xsl:value-of, and encrypts that string.  When you decrypt, you get a decrypted value of world.  To resolve you should instead use the function dp:encrypt-data, see https://www.ibm.com/docs/en/datapower-gateway/10.5.0?topic=functions-dpencrypt-data where the third argument is expected to be a nodeset.  Changing your code to use this function resulted in 

    <?xml version="1.0" encoding="UTF-8"?>
    <decryptedResponse>
        <decryptedText>&lt;hello
            xmlns="">world&lt;/hello>
        </decryptedText>
    </decryptedResponse>

    Note that the dp:decrypt-data returns a string, so your value of the decryptedText element will effectively look like the result of a dp:serialize where the < characters are escaped to a &lt;, If you wish your results to look like XML, I changed your code to

        <xsl:variable name="vDecrypt">
          <xsl:copy-of select="dp:parse(dp:decrypt-data($vAlgorithm,$vKey,$vEncryptedText))"/>
        </xsl:variable>

    By parsing that resulting string and then doing a xsl:copy-of that nodeset result, variable vDecrypt will have a XML document/nodeset value, then your xsl:copy when creating your final result will copy that nodeset's elements and you'll get the result you probably want

    <?xml version="1.0" encoding="UTF-8"?>
    <decryptedResponse>
        <decryptedText>
            <hello>world</hello>
        </decryptedText>
    </decryptedResponse>

    Best Regards,

    Steve



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------



  • 6.  RE: XSLT XML Read Error

    Posted Fri May 26, 2023 01:33 AM

    HI @Steve Linn ,

    Thank so much for your support. After applying above changes it did worked out as expected.

    BR

    Fahad



    ------------------------------
    Fahad Hassan
    ------------------------------