Original Message:
Sent: Thu May 25, 2023 05:07 PM
From: Steve Linn
Subject: XSLT XML Read Error
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><hello xmlns="">world</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 <
, 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
Original Message:
Sent: Tue May 23, 2023 03:43 PM
From: Fahad Hassan
Subject: XSLT XML Read Error
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
Original Message:
Sent: Mon May 22, 2023 09:00 AM
From: Steve Linn
Subject: XSLT XML Read Error
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
Original Message:
Sent: Sun May 21, 2023 03:11 AM
From: Fahad Hassan
Subject: XSLT XML Read Error
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
------------------------------