Great Mr.Hermann! I am able to get the output after your suggestion. Thanks
Original Message:
Sent: Mon March 18, 2024 03:43 AM
From: Hermann Stamm-Wilbrandt
Subject: Filtering SOAP response in Datapower Gateway
What you want is some kind of element removal.
I always start with this Wikipedia example for such kind of task:
https://en.wikipedia.org/wiki/Identity_transform#Using_XSLT_3
This would just remove all CheckResult entries:
<xsl:template match="CheckResult"/>
Since you want to keep the 1st one, this is what you want:
<xsl:template match="CheckResult[position() > 1]"/>
This might work as for simple example. But in case you only want to remove all but 1st CheckResult children of CheckResponse and keep them elsewhere, you need to adjust the XPath expression accordingly.
DataPower has XSLT 1.0 compiler with XPath 1.0, here is spec on XPath position()
function used:
https://www.w3.org/TR/1999/REC-xpath-19991116/#function-position
P.S:
xsltproc is an old command line XSLT 1.0 processor and can be used for this example:
$ xsltproc soa.xsl inp.xml
<SoapEnv>
<SoapBody>
<CheckResponse>
<CheckResult>
<Message>abc</Message>
<Result>NO</Result>
</CheckResult>
</CheckResponse>
</SoapBody>
</SoapEnv>
$
------------------------------
Hermann Stamm-Wilbrandt
Compiler Level 3 support, IBM DataPower Gateways
IBM
Boeblingen Germany
Original Message:
Sent: Sun March 17, 2024 09:29 AM
From: Ashok Beshra
Subject: Filtering SOAP response in Datapower Gateway
Hi Team...
My Datapower Web service proxy backend is receiving the below response from backend web service. However, the response returned is having repeatitive complex type elements. I wanted to basically always filter only the first instance of complex type in XSLT and send it to the front end as below. Please advise how it can be easily achieved in Datapower XSLT
<SoapEnv>
....
<SoapBody>
<CheckResponse>
<CheckResult>
<Message>abc</Message>
<Result>NO</Result>
</CheckResult>
<CheckResult>
<Message>def</Message>
<Result>YES</Result>
</CheckResult>
<CheckResult>
<Message>ghi</Message>
<Result>NO</Result>
</CheckResult>
<CheckResult>
<Message>lmn</Message>
<Result>YES</Result>
</CheckResult>
..........
</CheckResponse>
</SoapBody>
</SoapEnv>
The output after striping the first complex should be as below,
<SoapEnv>
....
<SoapBody>
<CheckResponse>
<CheckResult>
<Message>abc</Message>
<Result>NO</Result>
</CheckResult>
</CheckResponse>
</SoapBody>
</SoapEnv>
------------------------------
Ashok Beshra
------------------------------