4

Remove particular null field before message mappin... - SAP Community

 7 months ago
source link: https://community.sap.com/t5/technology-q-a/remove-particular-null-field-before-message-mapping-through-xslt-or-groovy/qaq-p/12052543
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Remove particular null field before message mapping through XSLT or Groovy in SAP CPI

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.

Accepted Solutions (0)

Answers (3)

Sriprasadsbhat

Sriprasadsbhat

Active Contributor

‎10-14-2019

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

RAAMS

RAAMS

Explorer

‎03-30-2021

<?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>

deepika11

deepika11

Discoverer

‎09-11-2020

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK