xml - Xpath2.0 selecting first and last occurance of string with iteration -
i have tree:
<events> <properties> <property descriptor=100>1378314022</property> <property descriptor=200>abc1234</property> </properties> <properties> <property descriptor=100>1378314023</property> <property descriptor=200>abc1234</property> </properties> <properties> <property descriptor=100>1378314024</property> <property descriptor=200>abc1234</property> </properties> <properties> <property descriptor=100>1378314022</property> <property descriptor=200>123456</property> </properties> <properties> <property descriptor=100>1378314023</property> <property descriptor=200>123456</property> </properties> <properties> <property descriptor=100>1378314024</property> <property descriptor=200>123456</property> </properties> </events>
i'm iterating @ level: events/properties
how can have first , last occurrence of each property descriptor = 200
, respective property descriptor = 100
?
i've tried far:
- iteration:
events/properties
- select:
property[@descriptor=200])[last()] or property[@descriptor=200])[first()]
but no success.
output should [i'm showing in html, iterating in row level]:
p100 | p200 1378314022 | abc1234 1378314024 | abc1234 1378314022 | 123456 1378314024 | 123456
in xslt 2.0 easy for-each-group
, grouping 200 value , taking first , last members of each group. in pure xpath (not xslt) need think laterally.
if groups contiguous you've shown here (i.e. abc1234
entries adjacent 1 another, , 123456
entries adjacent 1 another) boils down wanting every properties
element p not have preceding and following sibling properties
element same 200
value p. i.e. want iterate over
events/properties[not( ( property[@descriptor="200"] = preceding-sibling::properties[1]/property[@descriptor="200"] ) , ( property[@descriptor="200"] = following-sibling::properties[1]/property[@descriptor="200"] ) )]
and select property[@descriptor="100"]
, property[@descriptor="200"]
each of resulting properties
elements.
you've tagged question "xpath-2.0" expression valid in xpath 1.0.
Comments
Post a Comment