<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <include href="isodoc.rng">
    <start>
      <ref name="iso-standard"/>
    </start>
    <define name="language">
      <element name="language">
        <choice>
          <value>en</value>
          <value>fr</value>
        </choice>
      </element>
    </define>
    <define name="script">
      <element name="script">
        <value>Latn</value>
      </element>
    </define>
    <!-- add type to docidentifier in isodoc? -->
    <define name="docidentifier">
      <element name="docidentifier">
        <optional>
          <attribute name="type"/>
        </optional>
        <choice>
          <text/>
          <group>
            <ref name="documentnumber"/>
            <optional>
              <ref name="tc-documentnumber"/>
            </optional>
          </group>
        </choice>
      </element>
    </define>
    <define name="organization">
      <element name="organization">
        <ref name="orgname"/>
        <optional>
          <ref name="abbreviation"/>
        </optional>
        <optional>
          <ref name="uri"/>
        </optional>
        <zeroOrMore>
          <ref name="org-identifier"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="contact"/>
        </zeroOrMore>
        <optional>
          <ref name="technical-committee"/>
        </optional>
        <optional>
          <ref name="subcommittee"/>
        </optional>
        <optional>
          <ref name="workgroup"/>
        </optional>
        <optional>
          <ref name="secretariat"/>
        </optional>
      </element>
    </define>
    <define name="BibliographicItem">
      <optional>
        <attribute name="type">
          <ref name="BibItemType"/>
        </attribute>
      </optional>
      <optional>
        <ref name="fetched"/>
      </optional>
      <choice>
        <oneOrMore>
          <ref name="btitle"/>
        </oneOrMore>
        <ref name="formattedref"/>
      </choice>
      <zeroOrMore>
        <ref name="bsource"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="docidentifier"/>
      </zeroOrMore>
      <optional>
        <ref name="docnumber"/>
      </optional>
      <zeroOrMore>
        <ref name="bdate"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="contributor"/>
      </zeroOrMore>
      <optional>
        <ref name="edition"/>
      </optional>
      <zeroOrMore>
        <ref name="biblionote"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="language"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="script"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="abstract"/>
      </zeroOrMore>
      <optional>
        <ref name="status"/>
      </optional>
      <optional>
        <ref name="copyright"/>
      </optional>
      <zeroOrMore>
        <ref name="docrelation"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="series"/>
      </zeroOrMore>
      <optional>
        <ref name="medium"/>
      </optional>
      <zeroOrMore>
        <ref name="bplace"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="extent"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="accesslocation"/>
      </zeroOrMore>
      <optional>
        <ref name="bclassification"/>
      </optional>
      <optional>
        <ref name="validity"/>
      </optional>
      <optional>
        <ref name="editorialgroup"/>
      </optional>
      <zeroOrMore>
        <ref name="ics"/>
      </zeroOrMore>
      <optional>
        <ref name="allParts"/>
      </optional>
    </define>
    <define name="BibData">
      <optional>
        <attribute name="type">
          <ref name="BibItemType"/>
        </attribute>
      </optional>
      <oneOrMore>
        <ref name="btitle"/>
      </oneOrMore>
      <optional>
        <ref name="formattedref"/>
      </optional>
      <zeroOrMore>
        <ref name="bsource"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="docidentifier"/>
      </zeroOrMore>
      <optional>
        <ref name="docnumber"/>
      </optional>
      <zeroOrMore>
        <ref name="bdate"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="contributor"/>
      </zeroOrMore>
      <optional>
        <ref name="edition"/>
      </optional>
      <zeroOrMore>
        <ref name="biblionote"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="language"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="script"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="abstract"/>
      </zeroOrMore>
      <optional>
        <ref name="status"/>
      </optional>
      <ref name="copyright"/>
      <zeroOrMore>
        <ref name="docrelation"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="series"/>
      </zeroOrMore>
      <optional>
        <ref name="medium"/>
      </optional>
      <zeroOrMore>
        <ref name="bplace"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="extent"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="accesslocation"/>
      </zeroOrMore>
      <optional>
        <ref name="bclassification"/>
      </optional>
      <optional>
        <ref name="validity"/>
      </optional>
      <ref name="editorialgroup"/>
      <zeroOrMore>
        <ref name="ics"/>
      </zeroOrMore>
      <optional>
        <ref name="allParts"/>
      </optional>
    </define>
    <define name="bdate">
      <element name="date">
        <attribute name="type">
          <choice>
            <value>published</value>
            <value>accessed</value>
            <value>created</value>
            <value>implemented</value>
            <value>obsoleted</value>
            <value>confirmed</value>
            <value>updated</value>
            <value>issued</value>
          </choice>
        </attribute>
        <!-- ( ( bfrom, bto? ) | date_on ) -->
        <choice>
          <group>
            <element name="from">
              <choice>
                <data type="gYear"/>
                <data type="date"/>
              </choice>
            </element>
            <optional>
              <element name="to">
                <choice>
                  <data type="gYear"/>
                  <data type="date"/>
                </choice>
              </element>
            </optional>
          </group>
          <element name="on">
            <choice>
              <data type="gYear"/>
              <data type="date"/>
              <value>--</value>
            </choice>
          </element>
        </choice>
      </element>
    </define>
    <define name="biblionote">
      <element name="note">
        <optional>
          <!-- Biblio date notes can be footnoted -->
          <attribute name="reference"/>
        </optional>
        <ref name="FormattedString"/>
      </element>
    </define>
    <define name="status">
      <element name="status">
        <choice>
          <ref name="FormattedString"/>
          <group>
            <ref name="stage"/>
            <optional>
              <ref name="substage"/>
            </optional>
            <optional>
              <ref name="iteration"/>
            </optional>
          </group>
        </choice>
      </element>
    </define>
    <define name="btitle">
      <element name="title">
        <choice>
          <ref name="FormattedString"/>
          <group>
            <optional>
              <ref name="title-intro"/>
            </optional>
            <ref name="title-main"/>
            <optional>
              <ref name="title-part"/>
            </optional>
          </group>
        </choice>
      </element>
    </define>
    <define name="sections">
      <element name="sections">
        <ref name="clause"/>
        <choice>
          <ref name="term-clause"/>
          <ref name="terms"/>
        </choice>
        <optional>
          <ref name="definitions"/>
        </optional>
        <oneOrMore>
          <ref name="clause"/>
        </oneOrMore>
      </element>
    </define>
    <define name="Basic-Section">
      <optional>
        <attribute name="id">
          <data type="ID"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="obligation">
          <choice>
            <value>normative</value>
            <value>informative</value>
          </choice>
        </attribute>
      </optional>
      <optional>
        <ref name="section-title"/>
      </optional>
      <group>
        <oneOrMore>
          <ref name="BasicBlock"/>
        </oneOrMore>
        <zeroOrMore>
          <ref name="note"/>
        </zeroOrMore>
      </group>
    </define>
    <define name="Content-Section">
      <optional>
        <attribute name="id">
          <data type="ID"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="obligation">
          <choice>
            <value>normative</value>
            <value>informative</value>
          </choice>
        </attribute>
      </optional>
      <optional>
        <ref name="section-title"/>
      </optional>
      <choice>
        <group>
          <oneOrMore>
            <ref name="BasicBlock"/>
          </oneOrMore>
          <zeroOrMore>
            <ref name="note"/>
          </zeroOrMore>
        </group>
        <oneOrMore>
          <ref name="content-subsection"/>
        </oneOrMore>
      </choice>
    </define>
    <define name="Clause-Section">
      <optional>
        <attribute name="id">
          <data type="ID"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="inline-header">
          <data type="boolean"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="obligation">
          <choice>
            <value>normative</value>
            <value>informative</value>
          </choice>
        </attribute>
      </optional>
      <optional>
        <ref name="section-title"/>
      </optional>
      <choice>
        <group>
          <oneOrMore>
            <ref name="BasicBlock"/>
          </oneOrMore>
          <zeroOrMore>
            <ref name="note"/>
          </zeroOrMore>
        </group>
        <oneOrMore>
          <ref name="clause-subsection"/>
        </oneOrMore>
      </choice>
    </define>
    <define name="references">
      <element name="references">
        <optional>
          <attribute name="id">
            <data type="ID"/>
          </attribute>
        </optional>
        <optional>
          <attribute name="obligation">
            <choice>
              <value>normative</value>
              <value>informative</value>
            </choice>
          </attribute>
        </optional>
        <optional>
          <ref name="section-title"/>
        </optional>
        <zeroOrMore>
          <ref name="bibitem"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="references"/>
        </zeroOrMore>
      </element>
    </define>
    <define name="definitions">
      <element name="definitions">
        <optional>
          <attribute name="id">
            <data type="ID"/>
          </attribute>
        </optional>
        <optional>
          <attribute name="obligation">
            <choice>
              <value>normative</value>
              <value>informative</value>
            </choice>
          </attribute>
        </optional>
        <ref name="dl"/>
      </element>
    </define>
    <define name="terms">
      <element name="terms">
        <optional>
          <attribute name="id">
            <data type="ID"/>
          </attribute>
        </optional>
        <optional>
          <attribute name="obligation">
            <choice>
              <value>normative</value>
              <value>informative</value>
            </choice>
          </attribute>
        </optional>
        <optional>
          <ref name="section-title"/>
        </optional>
        <choice>
          <oneOrMore>
            <ref name="term"/>
          </oneOrMore>
          <group>
            <zeroOrMore>
              <ref name="terms"/>
            </zeroOrMore>
            <optional>
              <ref name="definitions"/>
            </optional>
          </group>
        </choice>
      </element>
    </define>
    <define name="term">
      <element name="term">
        <optional>
          <attribute name="id">
            <data type="ID"/>
          </attribute>
        </optional>
        <ref name="preferred"/>
        <zeroOrMore>
          <ref name="admitted"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="deprecates"/>
        </zeroOrMore>
        <optional>
          <ref name="termdomain"/>
        </optional>
        <ref name="definition"/>
        <zeroOrMore>
          <ref name="termnote"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="termexample"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="termsource"/>
        </zeroOrMore>
      </element>
    </define>
    <define name="definition">
      <element name="definition">
        <oneOrMore>
          <choice>
            <ref name="paragraph"/>
            <ref name="figure"/>
            <ref name="formula"/>
          </choice>
        </oneOrMore>
      </element>
    </define>
    <define name="annex">
      <element name="annex">
        <optional>
          <attribute name="id">
            <data type="ID"/>
          </attribute>
        </optional>
        <optional>
          <attribute name="inline-header">
            <data type="boolean"/>
          </attribute>
        </optional>
        <optional>
          <attribute name="obligation">
            <choice>
              <value>normative</value>
              <value>informative</value>
            </choice>
          </attribute>
        </optional>
        <optional>
          <ref name="section-title"/>
        </optional>
        <zeroOrMore>
          <!--
            allow hanging paragraps in annexes: they introduce lists
            ( paragraph-with-footnote | table | note | formula | admonition | ol | ul | dl | figure | quote | sourcecode | review | example )*,
          -->
          <ref name="BasicBlock"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="note"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="clause-hanging-paragraph-with-footnote"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="annex-appendix"/>
        </zeroOrMore>
      </element>
    </define>
    <define name="figure">
      <element name="figure">
        <attribute name="id">
          <data type="ID"/>
        </attribute>
        <optional>
          <ref name="tname"/>
        </optional>
        <choice>
          <ref name="image"/>
          <oneOrMore>
            <ref name="subfigure"/>
          </oneOrMore>
        </choice>
        <zeroOrMore>
          <ref name="fn"/>
        </zeroOrMore>
        <optional>
          <ref name="dl"/>
        </optional>
        <zeroOrMore>
          <ref name="note"/>
        </zeroOrMore>
      </element>
    </define>
    <define name="li">
      <element name="li">
        <group>
          <optional>
            <!-- ( paragraph-with-footnote | table | note | formula | admonition | ol | ul | dl | quote | sourcecode | review | example )+ -->
            <attribute name="id">
              <data type="ID"/>
            </attribute>
          </optional>
          <oneOrMore>
            <ref name="BasicBlock"/>
          </oneOrMore>
        </group>
        <!-- exclude figures? -->
      </element>
    </define>
    <define name="dd">
      <element name="dd">
        <zeroOrMore>
          <!--
            ( paragraph-with-footnote | table | note | formula | admonition | ol | ul | dl | quote | sourcecode | review | example )*
            exclude figures?
          -->
          <ref name="BasicBlock"/>
        </zeroOrMore>
      </element>
    </define>
    <define name="admonition">
      <element name="admonition">
        <attribute name="id">
          <data type="ID"/>
        </attribute>
        <attribute name="type">
          <choice>
            <value>danger</value>
            <value>caution</value>
            <value>warning</value>
            <value>important</value>
            <value>safety precautions</value>
          </choice>
        </attribute>
        <oneOrMore>
          <ref name="paragraph-with-footnote"/>
        </oneOrMore>
        <zeroOrMore>
          <ref name="note"/>
        </zeroOrMore>
      </element>
    </define>
    <define name="xref">
      <element name="xref">
        <attribute name="target">
          <data type="IDREF"/>
        </attribute>
        <text/>
      </element>
    </define>
    <define name="hyperlink">
      <element name="link">
        <attribute name="target">
          <data type="anyURI"/>
        </attribute>
        <text/>
      </element>
    </define>
    <define name="thead">
      <element name="thead">
        <oneOrMore>
          <ref name="tr"/>
        </oneOrMore>
      </element>
    </define>
    <define name="td">
      <element name="td">
        <optional>
          <attribute name="colspan"/>
        </optional>
        <optional>
          <attribute name="rowspan"/>
        </optional>
        <optional>
          <attribute name="align">
            <choice>
              <value>left</value>
              <value>right</value>
              <value>center</value>
            </choice>
          </attribute>
        </optional>
        <choice>
          <zeroOrMore>
            <choice>
              <ref name="TextElement"/>
              <ref name="fn"/>
            </choice>
          </zeroOrMore>
          <oneOrMore>
            <ref name="paragraph-with-footnote"/>
          </oneOrMore>
        </choice>
      </element>
    </define>
    <define name="th">
      <element name="th">
        <optional>
          <attribute name="colspan"/>
        </optional>
        <optional>
          <attribute name="rowspan"/>
        </optional>
        <optional>
          <attribute name="align">
            <choice>
              <value>left</value>
              <value>right</value>
              <value>center</value>
            </choice>
          </attribute>
        </optional>
        <choice>
          <zeroOrMore>
            <choice>
              <ref name="TextElement"/>
              <ref name="fn"/>
            </choice>
          </zeroOrMore>
          <oneOrMore>
            <ref name="paragraph-with-footnote"/>
          </oneOrMore>
        </choice>
      </element>
    </define>
    <define name="table-note">
      <element name="note">
        <optional>
          <attribute name="id">
            <data type="ID"/>
          </attribute>
        </optional>
        <ref name="paragraph"/>
      </element>
    </define>
    <define name="preface">
      <element name="preface">
        <optional>
          <ref name="preface_abstract"/>
        </optional>
        <ref name="foreword"/>
        <optional>
          <ref name="introduction"/>
        </optional>
      </element>
    </define>
  </include>
  <!-- end overrides -->
  <!--
    We display the Normative References between scope and terms; but to keep the
    grammar simple, we keep the references together
  -->
  <define name="iso-standard">
    <element name="iso-standard">
      <ref name="bibdata"/>
      <optional>
        <ref name="version"/>
      </optional>
      <zeroOrMore>
        <ref name="termdocsource"/>
      </zeroOrMore>
      <ref name="preface"/>
      <oneOrMore>
        <ref name="sections"/>
      </oneOrMore>
      <zeroOrMore>
        <ref name="annex"/>
      </zeroOrMore>
      <ref name="bibliography"/>
    </element>
  </define>
  <define name="bibliography">
    <element name="bibliography">
      <oneOrMore>
        <choice>
          <ref name="references"/>
          <ref name="reference-clause"/>
        </choice>
      </oneOrMore>
    </element>
  </define>
  <define name="BibItemType" combine="choice">
    <choice>
      <value>international-standard</value>
      <value>technical-specification</value>
      <value>technical-report</value>
      <value>publicly-available-specification</value>
      <value>international-workshop-agreement</value>
      <value>guide</value>
    </choice>
  </define>
  <define name="editorialgroup">
    <element name="editorialgroup">
      <oneOrMore>
        <ref name="technical-committee"/>
      </oneOrMore>
      <zeroOrMore>
        <ref name="subcommittee"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="workgroup"/>
      </zeroOrMore>
      <optional>
        <ref name="secretariat"/>
      </optional>
    </element>
  </define>
  <define name="preface_abstract">
    <element name="abstract">
      <ref name="Basic-Section"/>
    </element>
  </define>
  <define name="foreword">
    <element name="foreword">
      <ref name="Basic-Section"/>
    </element>
  </define>
  <define name="introduction">
    <element name="introduction">
      <ref name="Content-Section"/>
    </element>
  </define>
  <define name="stage">
    <element name="stage">
      <choice>
        <value>00</value>
        <value>10</value>
        <value>20</value>
        <value>30</value>
        <value>40</value>
        <value>50</value>
        <value>60</value>
        <value>90</value>
        <value>95</value>
      </choice>
    </element>
  </define>
  <define name="substage">
    <element name="substage">
      <choice>
        <value>00</value>
        <value>20</value>
        <value>60</value>
        <value>90</value>
        <value>92</value>
        <value>93</value>
        <value>98</value>
        <value>99</value>
      </choice>
    </element>
  </define>
  <define name="iteration">
    <element name="iteration">
      <data type="int"/>
    </element>
  </define>
  <define name="documentnumber">
    <element name="project-number">
      <optional>
        <attribute name="part">
          <data type="int"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="subpart">
          <data type="int"/>
        </attribute>
      </optional>
      <text/>
    </element>
  </define>
  <define name="tc-documentnumber">
    <element name="tc-document-number">
      <data type="int"/>
    </element>
  </define>
  <define name="technical-committee">
    <element name="technical-committee">
      <ref name="IsoWorkgroup"/>
    </element>
  </define>
  <define name="subcommittee">
    <element name="subcommittee">
      <ref name="IsoWorkgroup"/>
    </element>
  </define>
  <define name="workgroup">
    <element name="workgroup">
      <ref name="IsoWorkgroup"/>
    </element>
  </define>
  <define name="IsoWorkgroup">
    <optional>
      <attribute name="number">
        <data type="int"/>
      </attribute>
    </optional>
    <optional>
      <attribute name="type"/>
    </optional>
    <text/>
  </define>
  <define name="secretariat">
    <element name="secretariat">
      <text/>
    </element>
  </define>
  <define name="title-intro">
    <element name="title-intro">
      <ref name="FormattedString"/>
    </element>
  </define>
  <define name="title-main">
    <element name="title-main">
      <ref name="FormattedString"/>
    </element>
  </define>
  <define name="title-part">
    <element name="title-part">
      <ref name="FormattedString"/>
    </element>
  </define>
  <define name="allParts">
    <element name="allparts">
      <data type="boolean"/>
    </element>
  </define>
  <define name="clause-hanging-paragraph-with-footnote">
    <element name="clause">
      <optional>
        <attribute name="id">
          <data type="ID"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="inline-header">
          <data type="boolean"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="obligation">
          <choice>
            <value>normative</value>
            <value>informative</value>
          </choice>
        </attribute>
      </optional>
      <optional>
        <ref name="section-title"/>
      </optional>
      <zeroOrMore>
        <!-- allow hanging paragraphs in annexes: they introduce lists -->
        <ref name="BasicBlock"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="note"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="clause-hanging-paragraph-with-footnote"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="subfigure">
    <element name="figure">
      <attribute name="id">
        <data type="ID"/>
      </attribute>
      <optional>
        <ref name="tname"/>
      </optional>
      <ref name="image"/>
    </element>
  </define>
  <define name="termdocsource">
    <element name="termdocsource">
      <ref name="CitationType"/>
    </element>
  </define>
  <define name="ics">
    <element name="ics">
      <element name="code">
        <text/>
      </element>
      <element name="text">
        <text/>
      </element>
    </element>
  </define>
  <define name="term-clause">
    <element name="clause">
      <optional>
        <attribute name="id">
          <data type="ID"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="inline-header">
          <data type="boolean"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="obligation">
          <choice>
            <value>normative</value>
            <value>informative</value>
          </choice>
        </attribute>
      </optional>
      <optional>
        <ref name="section-title"/>
      </optional>
      <zeroOrMore>
        <choice>
          <ref name="term-clause"/>
          <ref name="terms"/>
          <ref name="definitions"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
  <define name="reference-clause">
    <element name="clause">
      <optional>
        <attribute name="id">
          <data type="ID"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="inline-header">
          <data type="boolean"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="obligation">
          <choice>
            <value>normative</value>
            <value>informative</value>
          </choice>
        </attribute>
      </optional>
      <optional>
        <ref name="section-title"/>
      </optional>
      <choice>
        <oneOrMore>
          <ref name="reference-clause"/>
        </oneOrMore>
        <zeroOrMore>
          <ref name="references"/>
        </zeroOrMore>
      </choice>
    </element>
  </define>
  <define name="annex-appendix">
    <element name="appendix">
      <ref name="Clause-Section"/>
    </element>
  </define>
</grammar>