XPath to get the maximum ID

后端 未结 3 510
遥遥无期
遥遥无期 2021-01-06 20:18

XML Source:


    
        School A
        
            Student A

        
相关标签:
3条回答
  • 2021-01-06 20:38

    Just for completeness... If you could had XPath 2.0 available, you could use max(), as in:

    /*/school[*/id = max(//id)]/name
    

    It's a little easier than in XPath 1.0.

    However AFAIK you do not have XPath 2.0 available in Python. So go with @cdhowie's or @Alejandro's answer.

    0 讨论(0)
  • 2021-01-06 20:39

    What about:

    //student[not(../../school/student/id > id)]
    

    Or, more simply:

    //student[not(//student/id > id)]
    

    To get the <school/> element with the highest student ID, I believe this will work:

    //school[student[not(//student/id > id)]]
    
    0 讨论(0)
  • 2021-01-06 20:43

    Use:

    /schools/school[student[not(../../school/student/id > id)]]/name
    

    Or shorter (just for this schema):

    /*/school[*/id[not(//id > .)]]/name
    
    0 讨论(0)
提交回复
热议问题