• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Impossible XPath???

 
Ranch Hand
Posts: 624
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Map - it worked a treat!

 
reply
    Bookmark Topic Watch Topic
  • New Topic