Skip to main content
added 299 characters in body
Source Link
Tomalak
  • 339.4k
  • 68
  • 547
  • 635
//B//*[starts-with(normalize-space(), 'history')] 

looks like it would do what you intend.

It selects "any descendant element of <B> whose text content starts with 'history'".

Manual iteration to find further nodes is not typically necessary. XPath does that for you. If you must iterate for some other reason, use the context node . to select.

nodes.forEach(function (node) { var history = select(node, "./*[starts-with(.,'history')]"); }); 

If you are actually looking for "any text node..."

//B//text()[starts-with(normalize-space(), 'history')] 

Or "any element node that has no further child elements..."

//B//*[not(*) and starts-with(normalize-space(), 'history')] 
//B//*[starts-with(normalize-space(), 'history')] 

looks like it would do what you intend.

It selects "any descendant element of <B> whose text content starts with 'history'".

If you are actually looking for "any text node..."

//B//text()[starts-with(normalize-space(), 'history')] 

Or "any element node that has no further child elements..."

//B//*[not(*) and starts-with(normalize-space(), 'history')] 
//B//*[starts-with(normalize-space(), 'history')] 

looks like it would do what you intend.

It selects "any descendant element of <B> whose text content starts with 'history'".

Manual iteration to find further nodes is not typically necessary. XPath does that for you. If you must iterate for some other reason, use the context node . to select.

nodes.forEach(function (node) { var history = select(node, "./*[starts-with(.,'history')]"); }); 

If you are actually looking for "any text node..."

//B//text()[starts-with(normalize-space(), 'history')] 

Or "any element node that has no further child elements..."

//B//*[not(*) and starts-with(normalize-space(), 'history')] 
Source Link
Tomalak
  • 339.4k
  • 68
  • 547
  • 635

//B//*[starts-with(normalize-space(), 'history')] 

looks like it would do what you intend.

It selects "any descendant element of <B> whose text content starts with 'history'".

If you are actually looking for "any text node..."

//B//text()[starts-with(normalize-space(), 'history')] 

Or "any element node that has no further child elements..."

//B//*[not(*) and starts-with(normalize-space(), 'history')]