I'm using SAP CPI platform and I want to remove the parent node (payload) based on its grandchild nodes (localeId and translation). The input XML provided is like this:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<payload>
<title>Doc1</title>
<localizedTitle>
<localeID>es</localeID>
<translation>Type 1</translation>
</localizedTitle>
<localizedTitle>
<localeID>en</localeID>
<translation>Type 1</translation>
</localizedTitle>
</payload>
<payload>
<title>Doc3</title>
<localizedTitle>
<localeID>es</localeID>
<translation>Type 3</translation>
</localizedTitle>
<localizedTitle>
<localeID>en</localeID>
<translation>Type 3</translation>
</localizedTitle>
</payload>
<payload>
<title>Doc4</title>
<localizedTitle>
<localeID>es</localeID>
<translation>Type 1</translation>
</localizedTitle>
<localizedTitle>
<localeID>en</localeID>
<translation>Type 1</translation>
</localizedTitle>
</payload>
</root>
I want to remove the payload nodes that its localeId != "es" and translation!= "Type 1" using Groovy.
The result will be like this (only Doc1 and Doc4 are correct):
<?xml version="1.0" encoding="UTF-8"?>
<root>
<payload>
<title>Doc1</title>
<localizedTitle>
<localeID>es</localeID>
<translation>Type 1</translation>
</localizedTitle>
<localizedTitle>
<localeID>en</localeID>
<translation>Type 1</translation>
</localizedTitle>
</payload>
<payload>
<title>Doc4</title>
<localizedTitle>
<localeID>es</localeID>
<translation>Type 1</translation>
</localizedTitle>
<localizedTitle>
<localeID>en</localeID>
<translation>Type 1</translation>
</localizedTitle>
</payload>
</root>
Please try the following XSLT.
It is using a so called Identity Transform pattern.
Input XML
XSLT
Output XML