group

Table of Contents

Declaration
Related GitHub issue(s)
Sample usage
Commentary

This element has the same content model as element pattern. Patterns and groups may be combined in a schema.

Clause 5.4.5 (group element)

The group element has the same structure and semantics as element pattern [...], except that the if-then-else behaviour of evaluating rules within a pattern shall not apply (see 6.6).

Clause 6.6 Order and side-effects

A rule element acts as an if-then-else statement within each pattern. In the context of a group element (5.4.5), this behaviour shall not apply and a match shall be attempted instead against all the rule contexts it contains.

Declaration

element schema {
        attribute id { xsd:ID }?,
        rich,
        attribute schemaVersion { non-empty-string }?,
        attribute schematronEdition { non-empty-string }?,
        attribute defaultPhase { xsd:IDREF }?,
        attribute queryBinding { non-empty-string }?,
        (foreign
         & (inclusion | extends)*
         & (title?, ns*, p*, param*, let*, phase*, abstract-rules*, (rule-set|pattern)+, p*, diagnostics?, properties?))
    }
element library {
        attribute id { xsd:ID }?,
        rich,
        (foreign
         & (inclusion | extends)*
         & (title?, p*, param*, let*, abstract-rules*, (rule-set|pattern)*, p*, diagnostics?, properties?))
    }
rule-set = 
    element group {
        rule-set-or-pattern    
    }

Related GitHub issue(s)

Option to turn off if-then-else behaviour within patterns

Sample usage

Example 12. group element

Given this instance document:

<foo/>

and this schema:

<sch:schema>
  <sch:group>
    <sch:rule context='*'>
      <sch:assert test='name() eq "bar"'>root element is <sch:name/></sch:assert>
    </sch:rule>
    <sch:rule context='foo'>
      <sch:report test='.'>should reach here</sch:report>
    </sch:rule>
  </sch:group>
</sch:schema>

both rules will fire and their assertions will be evaluated, because within the context of a group, all rules are evaluated. Contrast this with pattern: in this instance, only the first rule would fire (if a child of pattern), because the context has already been matched when the second rule's context is evaluated.


Commentary

This element gives the option to have all rules evaluated regardless, addressing one of the commonest issues faced by schema authors.