Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using XPath how to select elements with absent attribute

Tags:

xml

xpath

I would like to select all elements that have certain attribute or don't have it at all:

//job[@salary<"100" or !@salary]

This code is not valid. Which one is? Thanks!

like image 749
yegor256 Avatar asked Mar 31 '10 15:03

yegor256


People also ask

What is the meaning of '/' in XPath?

0 votes. Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.

What is attribute and value in XPath?

XPath Tutorial from basic to advance level. This attribute can be easily retrieved and checked by using the @attribute-name of the element. @name − get the value of attribute "name". <td><xsl:value-of select = "@rollno"/></td> Attribute can be used to compared using operators.


3 Answers

//job[@salary<"100" or not(@salary)] 

There isn't a not operator in xpath. See http://www.w3schools.com/xpath/xpath_operators.asp

like image 51
Krab Avatar answered Oct 24 '22 12:10

Krab


//job[@salary<"100" or count(@salary)=0]

Tested it here and works fine.

like image 34
AdmSteck Avatar answered Oct 24 '22 12:10

AdmSteck


//job[count(@salary) = 0]

I think :)

like image 1
remi bourgarel Avatar answered Oct 24 '22 11:10

remi bourgarel