Fixed occurrence count

From W3C Wiki

Fixed Occurrence Count (a co-constraint use case)

An attribute with an integer value sets the exact number of child elements that must be present.

Cf. Dynamic minOccurs (in which only minOccurs is controlled, and the control is indirect through a conditional controlled by a Boolean).

source: Noah Mendelsohn


Other use cases: Co-constraint Use Cases

Description

An attribute with an integer value sets the exact number of child elements that must be present.


    <items count="3">
        <!-- Item 1 -->
        <item>
           ...
        </item>
        <!-- Item 2 -->
        <item>
           ...
        </item>
        <!-- Item 3 -->
        <item>
           ...
        </item>
    </items>


Note that this use case is intentionally silent on whether the attribute needs to have some specific schema type, such as xsd:integer. I could see it working either way, and I think we should consider both options if we decide the use case is otherwise important.

The use case is also intentionally silent on the nature of the group (or particles within that group) that are the content model for the children. So, we need to think about both <sequences> and <all> groups, and decide whether both should be supported.

Analysis

(Add your analysis here; see your name in pixels!)

Possible solutions

Relax NG

Schematron

Check clause

A simple solution using the check-clause notation of the 31 August draft:

  <xsd:assert test="count(./item) eq @count"/>


Note that the comparator used is "eq", not "=".

(Solution proposed by CMSMcQ; not checked.)

SchemaPath

Conditional Type