I need to apply constraints in a large XML file, like this:
<library>
<book>
<bookAuthor ID="1" nameAlias="PeerBR jr"/>
</book>
<book>
<bookAuthor ID="1"/>
</book>
</library>
<authorCatalogue>
<author ID="1" name="PeerBr"/>
</authorCatalogue>
I need each bookAuthor's ID to refer to a valid author.
I am finding the "restricted XPath" very clumsy to work with, but maybe overlooking something. Am I right to define the constraint this way:
<xs:keyref name="bookAuthor" refer="author">
<xs:selector xpath="library/book/bookauthor"/>
<xs:field xpath="@ID"/>
</xs:keyref>
<xs:key name="author">
<xs:selector xpath="authorCatalogue/author"/>
<xs:field xpath="@ID"/>
</xs:key>
It works, but my file is actually more nested, so it gets really messy. Plus I have to write a new constraint for "library/book/CoAuthor". Is there nothing more elegant I can do? Can't I abbreviate the selector?
Can I restrict the application of the constraint ("bookauthor[@nameAlias]")?
Thanks in advance for your help.