I'm having trouble generating an identity constraint due to a field evaluating to a node-set within my instances.
Given a sample set of XML:
<data>
<Clusters>
<Cluster FileID="0" Function="1">
<Isotopes>
<Isotope StickID="0"/>
<Isotope StickID="1"/>
</Isotopes>
</Cluster>
<Cluster FileID="0" Function="2">
<Isotopes>
<Isotope StickID="2"/>
</Isotopes>
</Cluster>
</Clusters>
</data>
I'm trying to create a constraint such that for a given Isotope element, the each combination of @StickID combined with the @FileID and @Function of the grandparent Cluster must form a unique key.
If from the data context, I define the selector on the Cluster as so:
<xs:key name="ClusterStickRefIdentity">
<xs:selector xpath="Clusters"/>
<xs:field xpath="Cluster/Isotopes/Isotope/@StickID"/>
<xs:field xpath="@Function"/>
<xs:field xpath="@FileID"/>
</xs:key>
As expected, an error is generated when validating the instance saying the first field evaluates to a node-set with more than one member as an Isotopes element can contain an unbounded number of Isotope elements.
I'm under the impression that fields can only be applied to child contexts, which means I can't define my selector to any node deeper than Cluster, or can I? Is it possible to build the constraint I'm looking for?