Jump to content

XPath: exclude descendants of a given node?


ashouric

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...