on 2019 Oct 14 3:49 PM
Hi Experts,
Condition to remove particular null fields from source payload before mapping through Groovy or XSLT in SAP CPI.
For example,
if <Employee_address> and <Employee_PhoneNumber> are Null then remove these fields and send remaining fields in payload.
Please suggest me the code.
Thanks and Regards,
Surya.
Hello Surya,
Below will remove all the nodes which doesn't have any values.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml"/>
<xsl:template match="*[not(child::node())]"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Regards,
Sriprasad Shivaram Bhat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="node()|@*"> <xsl:if test="normalize-space(string(.)) != ''"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:if> </xsl:template> </xsl:stylesheet>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Prasad. All of your solutions helps a lot in our designs. I wanted to know if this is possible - in the xml structure if any one of the tag is empty, then remove the entire node. Here is the example
Input
<root>
<row>
<Order>12027</Order>
<OrderDescription>12027</OrderDescription>
<Item>A63466</Item>
<ItemDescription>Korean Sauce</ItemDescription>
<Component>A63466</Component>
<ComponentDescription>Korean Sauce</ComponentDescription>
<Plant>500</Plant> <WorkOrderStatus>3</WorkOrderStatus> </row> <row> <Order>12028</Order> <OrderDescription>12028</OrderDescription> <Item></Item> <ItemDescription/> <Component>A63466</Component> <ComponentDescription>Korean Sauce</ComponentDescription> <Plant>500</Plant> <WorkOrderStatus>3</WorkOrderStatus> </row> <row> <Order>12029</Order> <OrderDescription>12029</OrderDescription> <Item></Item> <ItemDescription/> <Component>A63466</Component> <ComponentDescription>Korean Sauce</ComponentDescription> <Plant>500</Plant> <WorkOrderStatus>3</WorkOrderStatus> </row> </root>
expected output - Since the second and third row have the item tag empty, we need to remove those 2 nodes and have the output as below
<root> <row> <Order>12027</Order> <OrderDescription>12027</OrderDescription> <Item>A63466</Item> <ItemDescription>Korean Sauce</ItemDescription> <Component>A63466</Component> <ComponentDescription>Korean Sauce</ComponentDescription> <Plant>500</Plant> <WorkOrderStatus>3</WorkOrderStatus> </row> </root>.
Please help us on this concern
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
68 | |
10 | |
10 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.