cancel
Showing results for 
Search instead for 
Did you mean: 

Need help in xslt mapping to remove a field from payload

0 Kudos

Hi All,

I am having the following xml . I need to remove one field from the payload rest of the structure needs to be same.

Input

<Parent>

       <Child1>

            <Field1></Field1>

            <Field2></Field2>

       </Child1>

       <Child2>

            <Field3></Field3>

            <Field4></Field4>

       </Child2>

       <Child3>

            <Field5></Field5>

            <Field6></Field6>

            <Item1>

                 <Field7></Field7>

            </Item1>

            <Item2>

                 <Field8></Field8>

                 <Field9></Field9>

            </Item2>

            <Item3>

                 <Field10></Field10>

            </Item3>

       </Child3>

</Parent>

In the above XML i need to remove "<Field9>". So my output should be as below


OutPut

<Parent>

       <Child1>

            <Field1></Field1>

            <Field2></Field2>

       </Child1>

       <Child2>

            <Field3></Field3>

            <Field4></Field4>

       </Child2>

       <Child3>

            <Field5></Field5>

            <Field6></Field6>

            <Item1>

                 <Field7></Field7>

            </Item1>

            <Item2>

                 <Field8></Field8>

                

            </Item2>

            <Item3>

                 <Field10></Field10>

            </Item3>

       </Child3>

</Parent>

Kindly let me know how can we do it using XSLT mapping.

Thanks,

Sudha

Accepted Solutions (1)

Accepted Solutions (1)

iaki_vila
Active Contributor
0 Kudos

Hi Sudharee,

With your XML, if you try with this XSL:


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

    <xsl:output omit-xml-declaration="yes" indent="yes"/>

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

        <xsl:copy>

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

        </xsl:copy>

    </xsl:template>

    <xsl:template match="Field9"/>

</xsl:stylesheet>

You will get this:


<Parent>

    <Child1>

        <Field1/>

        <Field2/>

    </Child1>

    <Child2>

        <Field3/>

        <Field4/>

    </Child2>

    <Child3>

        <Field5/>

        <Field6/>

        <Item1>

            <Field7/>

        </Item1>

        <Item2>

            <Field8/>

        </Item2>

        <Item3>

            <Field10/>

        </Item3>

    </Child3>

</Parent>

Regards.

0 Kudos

Hi Iñaki Vila,

Thanks for the reply.

But i am having prefix for the field as given in below xml. Can you pls let me know how to handle the same. I tried replacing Field9 with ns0:Field9 in above code but it did not work.

Input

<ns0:Parent xmlns:ns0="http://abc/def">

       <Child1>

            <Field1></Field1>

            <Field2></Field2>

       </Child1>

       <Child2>

            <Field3></Field3>

            <Field4></Field4>

       </Child2>

       <ns0:Child3>

            <ns0:Field5></ns0:Field5>

            <ns0:Field6></ns0:Field6>

            <ns0:Item1>

                 <ns0:Field7></ns0:Field7>

            </ns0:Item1>

            <ns0:Item2>

                 <ns0:Field8></ns0:Field8>

                 <ns0:Field9></ns0:Field9>

            </ns0:Item2>

            <ns0:Item3>

                 <ns0:Field10></ns0:Field10>

            </ns0:Item3>

       </ns0:Child3>

</ns0:Parent>

Thanks in Advance

Sudha

Former Member
0 Kudos

Replace these two lines:

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

<xsl:template match="Field9"/>

with

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

<xsl:template match="ns0:Field9"/> respectively.

Answers (1)

Answers (1)

Former Member
0 Kudos