ashouric Posted June 28, 2007 Share Posted June 28, 2007 Dear all,Using XPath, I need to get all document nodes excluding a given node (and its children). A typical example would be something like: <html> <body> <div id="div1">some value</div> <noscript> <div id="div2">another value</div> </noscript> <body></html> How to get all nodes except <noscript> and its descendants?Many thanks for your help. Link to comment Share on other sites More sharing options...
boen_robot Posted June 28, 2007 Share Posted June 28, 2007 Most of the time, it would depend on the environment, but in general, I think something like that should work: //*[not(name() = 'noscript')] Link to comment Share on other sites More sharing options...
ashouric Posted June 30, 2007 Author Share Posted June 30, 2007 Dear boen_robot,Thanks for your reply,But that returns the descendants, they need to be excluded as well.Any hints? Link to comment Share on other sites More sharing options...
boen_robot Posted June 30, 2007 Share Posted June 30, 2007 What environment are you working in? If you're working in a DOM based environment, you could do /descendant-or-self::noscript to select all noscript elements and their descendants, and then remove them with something like the removeChild() method or something.If you use XSLT, you could use something like: <?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="node()"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="noscript"/></xsl:stylesheet> I can't really figure out how to select everything but that right now. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.