Skip to Content

how can i remove empty nodes from message mapping?

i have this result when i execute my messagge mapping, but i don't konw how i can remove the empty nodes (red color). I've been testing with various functions "Node functions" but i don't get solve it.

i have this:

<?xml version="1.0" encoding="UTF-8"?>

<ns1:Z_RFC1 xmlns:ns1="urn:sap-com:document:sap:rfc:functions">

<TABLE_1>

<item>

<FIELD1>value1</FIELD1>

<FIELD2>value2</FIELD2>

</item>

<item>

<FIELD1>value1</FIELD1>

<FIELD2>value2</FIELD2>

</item>

</item>

</item>

</item>

</item>

</ns1:Z_RFC1>

i want this:

<?xml version="1.0" encoding="UTF-8"?>

<ns1:Z_RFC1 xmlns:ns1="urn:sap-com:document:sap:rfc:functions">

<TABLE_1>

<item>

<FIELD1>value1</FIELD1>

<FIELD2>value2</FIELD2>

</item>

<item>

<FIELD1>value1</FIELD1>

<FIELD2>value2</FIELD2>

</item>

</ns1:Z_RFC1>

can anyone help me?

thanks

Add comment
10|10000 characters needed characters exceeded

4 Answers

  • Best Answer
    Posted on Sep 27, 2012 at 12:33 PM

    Hi Mariano,

    You could use this xsl, in the operation mapping (interface mapping), to remove all empty tags:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:strip-space elements="*"/>

    <xsl:template match="node()|@*">

    <xsl:copy>

    <xsl:apply-templates select="node()|@*"/>

    </xsl:copy>

    </xsl:template>

    <xsl:template match="*[not(@*) and not(*) and (not(text()) or .=-1)]"/>

    </xsl:stylesheet>

    If you have this XMLfor example:

    <?xml version="1.0" encoding="UTF-8"?>

    <table>

    <Item>

    <field1>1</field1>

    <field2/>

    <fielda>1</fielda>

    <fieldb/>

    <fieldc/>

    <fieldd/>

    <fielde/>

    <fieldf/>

    <fieldg/>

    </Item>

    </table>

    You will obtain this one:

    <?xml version="1.0" encoding="UTF-8"?>

    <table>

    <Item>

    <field1>1</field1>

    <fielda>1</fielda>

    </Item>

    </table>

    Note:

    To import the XSL you need to create an imported archive:

    And put this mapping as the last mapping in the operation mapping:

    Regards.

    Message was edited by: Iñaki Vila


    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello

      I have input file format like below :

      I am using below XSLT in my mapping:

      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

      <xsl:strip-space elements="*"/>

      <xsl:template match="node()|@*">

      <xsl:copy>

      <xsl:apply-templates select="node()|@*"/>

      </xsl:copy>

      </xsl:template>

      <xsl:template match="*[not(@*) and not(*) and (not(text()) or .=-1)]"/>

      </xsl:stylesheet>

      I am receiving output file as:

      current XSLT logic is only eliminating attributes of the empty node.

      How can I remove both empty nodes and all empty attributes from my input message.

      Thank you

      John

      Inputfile.jpg (39.8 kB)
      outputfile.jpg (52.2 kB)
  • Posted on Sep 27, 2012 at 12:56 PM

    Hi Mariano,

    did you try with CreateIf node function as below also,

    also change context also.

    if not then please that can solve ur problem i think.

    Regards

    Gagandeep


    1.jpg (146.7 kB)
    2.JPG (26.1 kB)
    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 27, 2012 at 12:59 PM

    Hi Mariano,

    Use below logic


    1.jpg (14.8 kB)
    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 27, 2012 at 01:04 PM

    Hi Mariano, Inaki's solution is good if you can work with imported functions.

    I assume you want to do this only with graphic mapping. If yes, probably use the Exists plus CreateIf node function based on Field1/2 when mapping to the item node.

    Please give more example of what you've tried, and what your logic flow is currently in the GUI mapping. Maybe post a screen shot?

    Add comment
    10|10000 characters needed characters exceeded