xml - How to count preceding sibling count until certain condition is fullfilled? -
i have following xml .. want count of 'step' nodes current 'step' node preceding step has node event value 'doubleclick'.
<?xml version="1.0" encoding="utf-8"?> <gps> <step> <event>doubleclick</event> </step> <step> <event>click</event> </step> <step> <event>click</event> </step> <step> <event>click</event> </step> <step> <event>doubleclick</event> </step> <step> <event>click</event> </step> <step> <event>click</event> </step> <step> <event>click</event> </step> <step> <event>doubleclick</event> </step> </gps>
you can use following xpath when current node step
:
count(preceding-sibling::step[generate-id(preceding-sibling::step[event = 'doubleclick'][1]) = generate-id(current()/preceding-sibling::step[event = 'doubleclick'][1])])
edit: , if want count step
doubleclick, use xpath:
count(preceding-sibling::step[event = 'doubleclick'][1]) * (count(preceding-sibling::step[generate-id(preceding-sibling::step[event = 'doubleclick'][1]) = generate-id(current()/preceding-sibling::step[event = 'doubleclick'][1])]) + 1)
Comments
Post a Comment