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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -