Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2013, 04:20 PM
Registered User
 
Join Date: Sep 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Smile XSLT remove node from XML

From the below code, just wants to remove <Endpoint_Collection>
</Endpoint_Collection> nodes using XSLT... your advise really appriciated.

<?xml version="1.0" encoding="utf-8" ?>
<Endpoints>
<Endpoint_Collection>
<Endpoint>
<Settings/>
</Endpoint>
</Endpoint_Collection>
</Endpoints>
 
Old September 18th, 2013, 05:15 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Your description is not precise enough, however any such tasks start with a stylesheet with the template
Code:
<xsl:template match="@* | node()">
  <xsl:copy>
     <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>
to which you then add templates for the elements that need special treatment. For instance if you want to remove the "Endpoint_Collection" but keep its children and descendants you use
Code:
<xsl:template match="Endpoint_Collection">
  <xsl:apply-templates/>
</xsl:template>
On the other hand, if you want to delete it completely, including any children and descendants, then use
Code:
<xsl:template match="Endpoint_Collection"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old September 18th, 2013, 10:14 AM
Registered User
 
Join Date: Sep 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. I have tried your following code to remove <Endpoint_Collection>

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

It does not reflect any change on my XML file. Am I missing something?

Thanks
 
Old September 18th, 2013, 10:22 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

When I use Saxon 6.5.5 to apply the code
Code:
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
<xsl:template match="@* | node()">
  <xsl:copy>
     <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="Endpoint_Collection">
  <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>
to the input
Code:
<?xml version="1.0" encoding="utf-8" ?>
<Endpoints>
<Endpoint_Collection>
<Endpoint>
<Settings/>
</Endpoint>
</Endpoint_Collection>
</Endpoints>
I get the output
Code:
<?xml version="1.0" encoding="utf-8"?><Endpoints>

<Endpoint>
<Settings/>
</Endpoint>

</Endpoints>
Are you sure your input is as posted? Or does it have some default namespace declaration like 'xmlns="http://example.com/foo"'?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old September 18th, 2013, 11:11 AM
Registered User
 
Join Date: Sep 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. I'm using XSLT for my SSRS XML output.
I have executed exact same XSLT that you have provided but the result still showing that node.

Following is my complete code:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

<xsl:template match="Endpoint_Collection">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="/*">
<xsl:apply-templates select="node()" />
</xsl:template>

</xsl:stylesheet>
 
Old September 18th, 2013, 11:13 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I suspect your XML actually isn't as you've shown it, and has a namespace declaration in it.

You need to include this namespace in your XSLT and match the Endpoint_Collection in that namespace.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a node to an existing xml node list. codehelp C# 2008 aka C# 3.0 2 October 12th, 2009 07:41 AM
to remove namespace prefix form input xml using xslt robin_stringss XSLT 4 May 17th, 2009 06:50 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
remove node asap XSLT 1 July 30th, 2006 03:01 AM
To remove a XML node in VB.Net jkusmanto XML 4 May 23rd, 2006 09:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.