aspose file tools*
The moose likes XML and Related Technologies and the fly likes [XSLT] remove a particular node Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "[XSLT] remove a particular node" Watch "[XSLT] remove a particular node" New topic
Author

[XSLT] remove a particular node

Brian Grey
Ranch Hand

Joined: Nov 15, 2002
Posts: 43
It's a long time I haven't worked with XSLT/XPath. I'm trying to remove a particular node from an XML.

Here is an example:

<wap-provisioningdoc>
<characteristic type="PXLOGICAL">
<parm name="NAME" value="Prov_NAME"/>
<parm name="PROV-PIN" value="Prov_PIN"/>
<parm name="NAMEPAGE" value="Homepage_NAME"/>
<parm name="STARTPAGE" value="Homepage_URL"/>
</characteristic>
<characteristic type="NAPDEF">
<parm name="NAPID" value="NAP1"/>
<parm name="NAP-ADDRESS" value="Bearer_ACCESSPOINT"/>
</characteristic>
</wap-provisioningdoc>

I'd like to remove the node characteristic that has a type "NAPDEF".

the result should be:

<wap-provisioningdoc>
<characteristic type="PXLOGICAL">
<parm name="NAME" value="Prov_NAME"/>
<parm name="PROV-PIN" value="Prov_PIN"/>
<parm name="NAMEPAGE" value="Homepage_NAME"/>
<parm name="STARTPAGE" value="Homepage_URL"/>
</characteristic>
</wap-provisioningdoc>


So I wrote this:

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*[not(type='NAPDEF')]|node()"/>
</xsl:copy>
</xsl:template>
But it doesn't work. How can I select the nodes that have no characteristic node of type NAPDEF?

[ March 15, 2005: Message edited by: Brian Grey ]
[ March 15, 2005: Message edited by: Brian Grey ]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Try

I find the exclusion pattern where things I don't want go into their own template much more readable than putting the stuff inline.
Hope that helps
[ March 16, 2005: Message edited by: Stephan H. Wissel ]
Brian Grey
Ranch Hand

Joined: Nov 15, 2002
Posts: 43
I found my mistake. The command [not(@type='NAPDEF')] was in the wrong place.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl utput method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()[not(@type='NAPDEF')]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [XSLT] remove a particular node
 
Similar Threads
removing duplicate elements
[XSL] sort element
[XSL] add attribute into existing XML
Adding a new element to xml using xslt
[XSD] complexType conditional