XML Schema to validate each value in an NMTOKENS attribute list
Given this XML file:
<users blessed="phrogz alians"> <user name="phrogz" id="42" /> <user name="lachtok" id="3" /> <user name="vielee" id="5" /> <user name="alians" id="17" /> </users>
...is it possible to create an XSD key/keyref style validation that ensures that each value in the the blessed list matches against an existing user/@name?
If this is not possible with XSD, is it possible with RelaxNG?
No, it's not possible with XSD 1.0. It's straightforward in XSD 1.1, of course, using assertions:
Uniqueness (if defined at the level of the users element):
<xsl:assert test="count(@blessed) = count(distinct-values(@blessed))"/>
Referential integrity (if defined at the level of the users element):
<xsl:assert test="every $t in data(@blessed) satisfies $t = user/@name"/>