Reputation: 5
My XML File:
<Company>
<Employee name="Rutu" Emp_id="E001">
<Age>22</Age>
<Gender>Female</Gender>
<Address>M/3,hului</Address>
<Department Deptid="D1">Production</Department>
<Join_date>10/9/2012</Join_date>
<Salary>50000</Salary>
</Employee>
<Employee name="Meera" Emp_id="E004">
<Age>21</Age>
<Gender>Female</Gender>
<Address>Behind Raj palace</Address>
<Department Deptid="D1">Production</Department>
<Join_date>3/4/2014</Join_date>
<Salary>80000</Salary>
</Employee>
</Company>
My Question is: Select all the employee detail who’s joining date is before year 2013. I tried the following Xpath but I am not getting the desired output: //Employee[substring(Join_date, 1, 4)<'2013']
Upvotes: 0
Views: 139
Reputation: 5419
Here it is what you need.
//Employee[number(substring(Join_date, string-length(Join_date) - 3, 4))<2014]
Just few explanation in case if you wonder what is going on.
that returns a position to the first number of year. Since you can't know for sure how many characters will be used in a year, f.x: 10/12/2015 vs 1/1/2015.
string-length(Join_date) - 3
In order to use < > you should have a number, so you need to cast result to number
number('2015')
Upvotes: 1