• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

[XSLT] remove a particular node

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic