I've included below a fragment of an XML Schema (XSD). Note the
'localize' complexType used in three situations (twice in the 'site'
element, and once in the 'page' element). The specifications require
that there be unique @language text nodes within each 'localize'.
I was able to describe the constraint as shown, i.e., including key in
each localize type element. Is there an elegant way of specifying this
constraint just once without resorting to this repetitive text?
To my second question I have not found an answer. The 'site' element
is a root element, it has the @homepage attribute whose value should
be the unique @id of a 'page' element (note the homepageFK keyref.)
The XML validates correctly even if the homepage does not exist!
<xs:complexType name="localize">
<xs:sequence maxOccurs="unbounded">
<xs:element name="text">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="language" type="xs:language" use="required"
/>
<xs:attribute name="modified" type="xs:dateTime" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="site">
<xs:complexType>
<xs:sequence>
<xs:element name="description" type="localize" minOccurs="0">
<xs:key name="siteDescriptionPK">
<xs:selector xpath="./text" />
<xs:field xpath="@language" />
</xs:key>
</xs:element>
<xs:element name="keywords" type="localize" minOccurs="0" >
<xs:key name="siteKeywordsPK">
<xs:selector xpath="./text" />
<xs:field xpath="@language" />
</xs:key>
</xs:element>
<xs:element ref="page" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="homepage" type="xs:NCName" use="required" />
<xs:key name="pagePK">
<xs:selector xpath=".//page" />
<xs:field xpath="@id" />
</xs:key>
<xs:keyref name="homepageFK" refer="pagePK">
<xs:selector xpath="." />
<xs:field xpath="@homepage" />
</xs:keyref>
</xs:complexType>
<xs:element name="page">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="localize" >
<xs:key name="pageTitlePK">
<xs:selector xpath="./text" />
<xs:field xpath="@language" />
</xs:key>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:NCName" use="required" />
</xs:complexType>
</xs:element>
<site homepage="myhomepage">
<description>
<text language="en">bla bla bla</text>
<text language="fr">blu blu blu</text>
<text language="it">bli bli bli</text>
</description>
<page id="home" />
<page id="photos" />
<page id="download" />
</site>