XPath conditional text node selection
Posted
by
Reinderien
on Stack Overflow
See other posts from Stack Overflow
or by Reinderien
Published on 2010-12-24T08:16:47Z
Indexed on
2010/12/24
8:54 UTC
Read the original article
Hit count: 214
Hi there. I need to construct an xpath string to select all descendants of a certain table with these conditions:
- The table is a descendant of a form with a specific
action
attribute value. - The selected descendants are text nodes.
- The text node content can only contain whitespace.
It'll probably look something like:
//form[@action = "submit.html"]//table//text()[ ...? ]
Any tips would be appreciated. Thanks.
Edit: For clarity, here is my current (working) compromise:
function KillTextNodes(rootpath)
{
XPathIterate(rootpath + '//text()', function(node)
{
var tagname = node.parentNode.tagName;
if (tagname != 'OPTION' && tagname != 'TH')
Kill(node);
});
}
© Stack Overflow or respective owner