Reputation: 2019
If I have this XML:
<Events>
<Properties>
<Property Descriptor="100">1377349460.298</Property>
<Property Descriptor="101">1</Property>
<Property Descriptor="24000">C1234Test1</Property>
</Properties>
<Properties>
<Property Descriptor="100">1377349462.298</Property>
<Property Descriptor="101">1</Property>
<Property Descriptor="24000">C4321Test2</Property>
</Properties>
<Properties>
<Property Descriptor="100">1377349462.300</Property>
<Property Descriptor="101">1</Property>
<Property Descriptor="24000">C1234Test1</Property>
</Properties>
</Events>
How can I select only Descriptor="100"
for the FIRST occurrence of each Descriptor="24000"
considering only the first 5 characters of this property? For example, selecting only 1377349460.298 [for C1234] and 1377349462.298 [for C4321]?
Xpath 2.0
I have no idea how to try it...
Thanks in advance!
Upvotes: 3
Views: 75
Reputation: 38702
Find all matching identifiers, then for each of them, find the first result.
for $id in distinct-values(//Property[@Descriptor=24000]/substring(., 1, 4))
return
//Properties[Property[@Descriptor=24000 and starts-with(., $id)]][1]
/Property[@Descriptor=100]
Upvotes: 2