Triggers

Revision History
Revision 0.12007-03-19ZDave Pawson
Initial Issue

Triggers are a way of reaching back from a fully namespaced environment to elements which, although in the same namespace, require validation using a different schema. The standard provides a clear use case, that of an XHTML instance with embedded content from the XForms schema, but in the XHTML namespace. The requirement there is to validate the ancestors of XForms element against the XHTML schema, yet take the single element (and its children) and validate against the XForms schema, suitable amended to allow the given root element. Example 5.1 provides a very simple xml instance, Example 5.2 shows the NVDL script, and Example 5.3 shows the Schema which is used in all 3 sections generated.

Example 5.1. A simple trigger example - the XML instance

    <doc xmlns="http://doc">          1
  <section>                           2
    <title>Section A</title>
    <para>Para in A</para>
  </section>
  
  <sect>                              3
    <head>Section B</head>
    <para>para in B</para>
  </sect>
  
</doc>
   
  
1

The root element, a simple namespaced container

2

Element section, in the same namespace

3

And element sect, also in the same namespace


The requirement is to validate the section element (and children) separately from the sect element and its children. These are two similar structures, the only variable being that one has a title child, the other a head child.

Example 5.2. A simple trigger example - the script

<rules  xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0">

  <trigger ns="http://doc" nameList="section sect"/>     1
  
  <namespace ns="http://doc">
    <validate schema="trigger.rng"/>                     2
  </namespace>
</rules>
   
  
1

The trigger generates a section for both section and sect

2

The schema to use for all validation


A trigger is specified, with the single namespace used throughout and naming the two elements which will trigger the generation of a new section as a validation candidate.

Example 5.3. A simple trigger example - the schema used

<grammar xmlns="http://relaxng.org/ns/structure/1.0"
	 ns="http://doc">

  <start>                                               1
    <choice>
      <ref name="doc"/>
      <ref name="section"/>
      <ref name="sect"/>
    </choice>
  </start>
  

  <define name="doc">                                   2
    <element name="doc">
      <empty/>
    </element>
  </define>
  
  
  <define name="section">                               3
    <element name="section">
      <element name="title"><text/></element>
      <oneOrMore><element name="para"><text/></element></oneOrMore>
    </element>
  </define>
  
  <define name="sect">                                  4
    <element name="sect">
      <element name="head"><text/></element>
      <oneOrMore><element name="para"><text/></element></oneOrMore>
    </element>
  </define>
  
</grammar>
    
   
  
1

Any of the 3 elements may be used as the start element

2

The root element is defined as being empty

3

The section element contains a title child

4

The sect element contains a head child


The schema has the 3 entry points, doc, section and sect. With just the document element defined, the validation would fail. Two more validation candidates are passed to the validator with this schema, the section element and the sect element. The section is valid to the schema in both cases.