[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Remove an xml element from an xml

Posted on 2011-05-10
3
Medium Priority
?
302 Views
Last Modified: 2013-11-18
Hi,
I have an xml document. But i dont want to have a element "/CustReq/CustomerRequest/DummyKey".  How to create the same xml without the above element?

Here is the xml:



<?xml version="1.0" encoding="UTF-8"?>
<CustReq>
<ControlHeader>
<NameValuePair>
<FieldName>IDDNAME</FieldName>
<FieldValue>BL20714</FieldValue>
</NameValuePair>
<NameValuePair>
<FieldName> BODID</FieldName>
<FieldValue>BL12345</FieldValue>
</NameValuePair>
<NameValuePair>
<FieldName>DOMAIN</FieldName>
<FieldValue>A2A</FieldValue>
</NameValuePair>
<NameValuePair>
<FieldName>IDDAREFNUM</FieldName>
<FieldValue>14042010</FieldValue>
</NameValuePair>
</ControlHeader>
<CustomerRequest>
<CorrelationId>1</CorrelationId>
<CustomerNumber>ABC07298</CustomerNumber>
<CustomerNumberType>ABC</CustomerNumberType>
<NameValuePair><FieldName>CC</FieldName><FieldValue>CN</FieldValue></NameValuePair>
<ResponseParameters>
<FieldName>ABCCC</FieldName></ResponseParameters>
<DummyKey>1_ABC07298</DummyKey>
</CustomerRequest>
<CustomerRequest>
<CorrelationId>2</CorrelationId>
<CustomerNumber>ABC07298</CustomerNumber>
<CustomerNumberType>ABC</CustomerNumberType>
<NameValuePair><FieldName>CC</FieldName><FieldValue>CN</FieldValue></NameValuePair>
<ResponseParameters><FieldName>ABCCC</FieldName></ResponseParameters>
<DummyKey>2_ABC07298</DummyKey>
</CustomerRequest>
</CustReq>


Thanks
sunshine

0
Comment
Question by:sunshine737
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 35732695
You can use an identity copy with one extra template for not copying the unwanted node
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes"/>
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="/CustReq/CustomerRequest/DummyKey"/>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:sunshine737
ID: 35734241
Thanks.
Could you please explain what the below code is doing:

<xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>


Thanks
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35735202
That is an identity copy template

for all nodes (except for the ones that have a more specific template)
it
<xsl:copy> copies the tags
<xsl:copy-of select="@*"/> copies all attributes
<xsl:apply-templates/> pushes all child nodes to the templates for further processing
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question