Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Schema to validate each value in an NMTOKENS attribute list

Tags:

xml

xsd

relaxng

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?

like image 638
Phrogz Avatar asked Nov 29 '11 17:11

Phrogz


1 Answers

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"/>
like image 168
Michael Kay Avatar answered Sep 28 '22 05:09

Michael Kay