Grouping an XPath function reference within an arbitrary set of elements



I have XML such as



<doc>
<Object id="x">
<Attributes>
<MATERIAL>PLA</MATERIAL>
<METHOD>Inserted</METHOD>
<PRESSURE>HP</PRESSURE>
</Attributes>
</Object>
<Object id="y">
<Attributes>
<MATERIAL>P</MATERIAL>
<METHOD>Unknown</METHOD>
<PRESSURE>HP</PRESSURE>
</Attributes>
</Object>
.
.
.
</doc>


where the Object element appears an a priori unknown number of times, and I want to have an XPath expression that returns a 0 or 1, if a condition holds true within any (at least 1) of the Objects.


Doing something like



number(boolean(//Object/Attributes[(MATERIAL="PLA")])) * number(boolean(//Object/Attributes[(METHOD="Unknown")]))


returns 1 because both are true somewhere, but I want a 0 because nowhere within any single Object are they both true.


I am restricted to XML 1.0.


I was hoping for a slick solution perhaps involving some kind of predicate on Object that I have not been able to discover.


Each Object attribute is unique, if that can be leveraged.


Drawing on a parallel to SQL, I want to somehow group by the Object when applying the condition of interest.


While I can programmatically extract the Objects and process them individually, I would really rather not!


TIA, Dave


No comments:

Post a Comment