- From: C. M. Sperberg-McQueen <cmsmcq@blackmesatech.com>
- Date: Fri, 20 Mar 2015 18:46:18 -0600
- To: Timothy W. Cook <tim@mlhim.org>
- Cc: "C. M. Sperberg-McQueen" <cmsmcq@blackmesatech.com>, XMLSchema-dev <xmlschema-dev@w3.org>
On Mar 19, 2015, at 11:15 AM, Timothy W. Cook wrote: > > I want to insure that elements in a complexType that is a restriction of a base complexType, have the same number of enumerations. (Code below) > > The sample complexType (bottom of email) should fail this assert: > > <xs:assert test="count(//xs:element[@name='id-name']//xs:enumeration) eq count(//xs:element[@name='issuer']//xs:enumeration) > and > count(//xs:element[@name='issuer']//xs:enumeration) eq count(//xs:element[@name='assignor']//xs:enumeration)"></xs:assert> > > because assignor has three enumerations and the other elements have two. Whether I put this in the base complexType or the restricted complexType it still shows the restriction as a valid schema. Assertions are predicates which are required to be true for each instance of a type; they are evaluated with the element (or attribute) being validated as the current node, not with the declaration of the type as the current node. If you could explain the motivation behind the rule, it might be easier to suggest a technique for achieving your actual goal. > ... > Sample restriction: > > <xs:complexType name='mytype' xml:lang='en-US'> > <xs:complexContent> > <xs:restriction base='myBaseType'> > <xs:sequence> > <xs:element maxOccurs='1' minOccurs='1' name='id-name'> > <xs:simpleType> > <xs:restriction base='xs:string'> > <xs:enumeration value='URI'></xs:enumeration> > <xs:enumeration value='ID Number'></xs:enumeration> > </xs:restriction> > </xs:simpleType> > </xs:element> > <xs:element maxOccurs='1' minOccurs='1' name='issuer'> > <xs:simpleType> > <xs:restriction base='xs:string'> > <xs:enumeration value='Owner'/> > <xs:enumeration value='Owner'/> > </xs:restriction> > </xs:simpleType> > </xs:element> > <xs:element maxOccurs='1' minOccurs='1' name='assignor'> > <xs:simpleType> > <xs:restriction base='xs:string'> > <xs:enumeration value='Owner'/> > <xs:enumeration value='Owner'/> > <xs:enumeration value='Owner'/> > </xs:restriction> > </xs:simpleType> > </xs:element> > </xs:sequence> > </xs:restriction> > </xs:complexContent> > </xs:complexType> One complication in this example (probably not relevant to the problem, but nevertheless a complication for anyone who wants to count enumerated values) is that the elements 'issuer' and 'assignor' here both have a single enumerated value, not two or three. If your goal is to ensure that each of the elements 'id-name', 'issuer', and 'assignor' can take any of a fixed number of values and that the cardinality of the set of legal values for each element is the same, then counting 'enumeration' elements in the declaration does not necessarily get you the correct number. The assertions you quote will count two, two, and three xs:enumeration elements in the different simple types, but the 'issuer' and 'assignor' elements have only one possible value. -- **************************************************************** * C. M. Sperberg-McQueen, Black Mesa Technologies LLC * http://www.blackmesatech.com * http://cmsmcq.com/mib * http://balisage.net ****************************************************************
Received on Saturday, 21 March 2015 00:46:43 UTC