In my schema, I have a colorName enum list, a <color name="one_of_colorName"/> element, and a <colorsUsed/> element with a unique list of <color/>s used, thus:
<!-- color name list -->
<xs:simpleType name="colorName">
<xs:restriction base="xs:string">
<xs:enumeration value="red"/>
<xs:enumeration value="green" /> <!-- etc. -->
</xs:restriction>
</xs:simpleType>
<!-- color element, just go with the col: namespace -->
<xs:element name="color">
<xs:complexType>
<xs:attribute name="name" type="col:colorName" use="required"/>
</xs:complexType>
</xs:element>
<!-- unique list of colors used -->
<xs:element name="colorsUsed">
<xs:complexType>
<xs:sequence>
<!-- let's hold off on max which must be the length of the color name list -->
<xs:element ref="col:color" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<!-- enforce unique color name in the list -->
<xs:unique name="uniqueColorName">
<xs:selector xpath="col:color"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
Question 1: I would like to have the <colorChoices/> menu populated with all the colors in the color name list, without repeating them, either in the schema or the XML file, along these lines:
<xs:element name="colorChoices">
<xs:complexType>
<xs:all> <!-- need the name list, one each -->
<xs:element ref="col:color"/> <!-- ?? what how ?? -->
</xs:all>
</xs:complexType>
</xs:element>
Question 2: I have a working solution, but would be nice to have: In <colorsUsed/> element, can I restrict maxOccurs=length_of_colorName_list?
Thanks for the answer or the link to an existing answer, which I can't seem to find.
List all
<color>choices whose type isxs:string, in the menu element<colorChoices/>and get rid of the enum list. Then enforce uniqueness of<color name="???"/>in both<colorChoices/>and<colorsUsed/>. If you know of a better answer, please update. Thanks.