• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Impossible XPath???

 
Alan Wanwierd
Ranch Hand
Posts: 624
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys - I'm having a compelte nightmare trying to remember XPath!!

Im not sure if what I'm trying to do is possible or not...

I'm using XPath in a bit of conditional XSL to try and determine whether or not to display a bit a text.

Basically I want to establish if there are any other "Employee" nodes in my XML with the same "EmployeeCode" value, but in a different "Section" parent node.

the XPath I have at the moment doesnt work:

count(../../../Section/Employees/Employee[EmployeeCode=EmployeeCode])> 1

If I just do:

count (EmployeeCode)
- result is 1 (current node as expected)

If I do:
count(../../../Section/Employees/Employee/EmployeeCode)
- result is 6 (all employees in my sample XML file)

If I do:
count(../../../Section/Employees/Employee[EmployeeCode=EmployeeCode])
- result in unforunately not 2 (the number of Employees with EmployeeCode same as current node) - but is 6 (presumabely the number of Employee whose EmployeeCode equals itself DOH!!)

How do I get a count of all the nodes that match the current one? Obviously my crude attempt at a value match didnt work cos the 2nd "EmployeeCode" still matches ALL the EmployeeCode nodes in the system...

thanks for your help!
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like this should work:

<xsl:variable name="currentEmployeeCode" select="."/>

count (//Employee[EmployeeCode = $currentEmployeeCode])
 
Alan Wanwierd
Ranch Hand
Posts: 624
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Map - it worked a treat!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic