NEWBIE: XPATH question

Discussion in 'XML' started by Victor, Feb 18, 2004.

  1. Victor

    Victor Guest

    Hallo again, just another really simple query that has taken me all
    morning to attempt to not get going.

    This is my invalid xpath expression which is what I have tried to
    write but fail.

    COMPANY/EMPLOYEE/EMPLOYEEDETAILS/count()

    What I want is to count the number of <EMPLOYEEDETAILS> for each
    <EMPLOYEE> so that my xpath for employee number 1000 calculates 1,
    employee number 1001 calculates 1, and employeenumber 1002 calculates
    2 (because there are two <EMPLOYEEDETAILS> for the same employee
    number).

    All help thank you and for everyone that thought about my problem this
    morning too. Here is the sample XML.
    Victor

    <COMPANY>

    <EMPLOYEE>
    <EMPLOYEENUMBER uknational="true">
    1000
    </EMPLOYEENUMBER>
    <EMPLOYEEDETAILS>
    <EMPLOYEENAME>Mary</EMPLOYEENAME>
    <NATIONALINSURANCENUMBER>1234567890<NATIONALINSURANCENUMBER>
    </EMPLOYEEDETAILS>
    </EMPLOYEE>

    <EMPLOYEE>
    <EMPLOYEENUMBER uknational="false">
    1001
    </EMPLOYEENUMBER>
    <EMPLOYEEDETAILS>
    <EMPLOYEENAME>Victor</EMPLOYEENAME>
    <EMPLOYEENATIONALINSURANCENUMBER/>
    </EMPLOYEEDETAILS>
    </EMPLOYEE>

    <EMPLOYEE>
    <EMPLOYEENUMBER uknational="true">
    1002
    </EMPLOYEENUMBER>
    <EMPLOYEEDETAILS>
    <EMPLOYEENAME>Mary</EMPLOYEENAME>
    <NATIONALINSURANCENUMBER>1234567890<NATIONALINSURANCENUMBER>
    </EMPLOYEEDETAILS>
    <EMPLOYEEDETAILS>
    <EMPLOYEENAME>Joanna</EMPLOYEENAME>
    <NATIONALINSURANCENUMBER>4323423423424<NATIONALINSURANCENUMBER>
    </EMPLOYEEDETAILS>
    </EMPLOYEE>

    </COMPANY>
    Victor, Feb 18, 2004
    #1
    1. Advertising

  2. Victor wrote:


    > This is my invalid xpath expression which is what I have tried to
    > write but fail.
    >
    > COMPANY/EMPLOYEE/EMPLOYEEDETAILS/count()


    count is a function to be applied to a nodeset e.g.
    count(//employyeedetails)
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 18, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,967
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,398
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    520
  4. goog
    Replies:
    0
    Views:
    506
  5. Tjerk Wolterink

    XPath: efficiency in xpath expressions

    Tjerk Wolterink, Nov 13, 2004, in forum: XML
    Replies:
    1
    Views:
    1,624
    Richard Tobin
    Nov 13, 2004
Loading...

Share This Page