RelaxNG/publiset.rng
author Patrick PIERRE <patrick.pierre@prismallia.fr>
sam., 04 juin 2011 09:01:30 +0200
changeset 0 41a5385c69a2
child 2 417bb62f2a77
permissions -rw-r--r--
Version initiale
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <!-- $Id$ -->
  <start>
    <ref name="publiset"/>
  </start>
  <define name="publiset">
    <element name="publiset">
      <ref name="publiset.attributes"/>
      <ref name="publiset.content"/>
    </element>
  </define>
  <!-- ~~~~~~ attributes -->
  <define name="publiset.attributes">
    <ref name="version.attribute"/>
  </define>
  <define name="version.attribute">
    <attribute name="version">
      <value>1.0</value>
    </attribute>
  </define>
  <!-- ~~~~~~ content -->
  <define name="publiset.content">
    <oneOrMore>
      <choice>
        <ref name="composition"/>
        <ref name="selection"/>
      </choice>
    </oneOrMore>
  </define>
  <!--
    =============================================================================
                                     Top level
    =============================================================================
  -->
  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ composition ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <define name="composition">
    <element name="composition">
      <ref name="composition.attributes"/>
      <ref name="composition.content"/>
    </element>
  </define>
  <!-- ~~~~~~ attributes -->
  <define name="composition.attributes">
    <interleave>
      <ref name="composition.id.attribute"/>
      <optional>
        <ref name="base.attribute"/>
      </optional>
      <ref name="remap.attributes"/>
    </interleave>
  </define>
  <define name="composition.id.attribute">
    <attribute name="xml:id">
      <data type="ID"/>
    </attribute>
  </define>
  <define name="base.attribute">
    <attribute name="xml:base">
      <data type="anyURI"/>
    </attribute>
  </define>
  <!-- ~~~~~~ content -->
  <define name="composition.content">
    <optional>
      <ref name="composition.metadata"/>
    </optional>
    <oneOrMore>
      <choice>
        <ref name="composition.file"/>
        <ref name="composition.division"/>
      </choice>
    </oneOrMore>
  </define>
  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ selection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <define name="selection">
    <element name="selection">
      <ref name="selection.attributes"/>
      <ref name="selection.content"/>
    </element>
  </define>
  <!-- ~~~~~~ attributes -->
  <define name="selection.attributes">
    <optional>
      <ref name="base.attribute"/>
    </optional>
  </define>
  <define name="selection.id.attribute">
    <attribute name="xml:id">
      <data type="ID"/>
    </attribute>
  </define>
  <!-- ~~~~~~ content -->
  <define name="selection.content">
    <optional>
      <ref name="selection.metadata"/>
    </optional>
    <oneOrMore>
      <choice>
        <ref name="selection.file"/>
        <ref name="selection.division"/>
      </choice>
    </oneOrMore>
  </define>
  <!--
    =============================================================================
                                    Metadata level
    =============================================================================
  -->
  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <define name="composition.metadata">
    <element name="metadata">
      <ref name="metadata.attributes"/>
      <ref name="metadata.content"/>
    </element>
  </define>
  <define name="selection.metadata">
    <element name="metadata">
      <ref name="metadata.content"/>
    </element>
  </define>
  <!-- ~~~~~~ attributes -->
  <define name="metadata.attributes">
    <ref name="remap.attributes"/>
  </define>
  <!-- ~~~~~~ content -->
  <define name="metadata.content">
    <optional>
      <ref name="title"/>
    </optional>
    <optional>
      <ref name="subtitle"/>
    </optional>
    <optional>
      <ref name="source"/>
    </optional>
  </define>
  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ title, subtitle ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <define name="title">
    <element name="title">
      <ref name="title.content"/>
    </element>
  </define>
  <define name="title.content">
    <ref name="inlines"/>
  </define>
  <define name="subtitle">
    <element name="subtitle">
      <ref name="title.content"/>
    </element>
  </define>
  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ source ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <define name="source">
    <element name="source">
      <ref name="source.attributes"/>
      <choice>
        <group>
          <attribute name="type">
            <value>book</value>
          </attribute>
          <ref name="source.content.book"/>
        </group>
        <attribute name="type">
          <value>file</value>
        </attribute>
      </choice>
    </element>
  </define>
  <!-- ~~~~~~ Attributes -->
  <define name="source.attributes">
    <interleave>
      <optional>
        <ref name="source.id.attribute"/>
      </optional>
      <ref name="remap.attributes"/>
    </interleave>
  </define>
  <define name="source.id.attribute">
    <attribute name="id">
      <data type="NMTOKEN"/>
    </attribute>
  </define>
  <!-- ~~~~~~ Content -->
  <define name="source.content.book">
    <optional>
      <ref name="title"/>
    </optional>
    <optional>
      <ref name="pagenumber"/>
    </optional>
  </define>
  <define name="pagenumber">
    <element name="pagenumber">
      <ref name="pagenumber.attributes"/>
    </element>
  </define>
  <define name="pagenumber.attributes">
    <ref name="pagenumber.value.attribute"/>
  </define>
  <define name="pagenumber.value.attribute">
    <attribute name="value">
      <ref name="pagenumber.value.enumeration"/>
    </attribute>
  </define>
  <define name="pagenumber.value.enumeration">
    <data type="positiveInteger"/>
  </define>
  <!--
    =============================================================================
                                   Division level
    =============================================================================
  -->
  <define name="composition.division">
    <element name="division">
      <ref name="composition.division.attributes"/>
      <ref name="composition.division.content"/>
    </element>
  </define>
  <define name="selection.division">
    <element name="division">
      <ref name="selection.division.attributes"/>
      <ref name="selection.division.content"/>
    </element>
  </define>
  <!-- ~~~~~~ attributes -->
  <define name="composition.division.attributes">
    <interleave>
      <optional>
        <ref name="base.attribute"/>
      </optional>
      <ref name="remap.attributes"/>
    </interleave>
  </define>
  <define name="selection.division.attributes">
    <optional>
      <ref name="base.attribute"/>
    </optional>
  </define>
  <!-- ~~~~~~ content -->
  <define name="composition.division.content">
    <optional>
      <ref name="composition.metadata"/>
    </optional>
    <oneOrMore>
      <choice>
        <ref name="composition.file"/>
        <ref name="composition.division"/>
      </choice>
    </oneOrMore>
  </define>
  <define name="selection.division.content">
    <optional>
      <ref name="selection.metadata"/>
    </optional>
    <oneOrMore>
      <choice>
        <ref name="selection.file"/>
        <ref name="selection.division"/>
      </choice>
    </oneOrMore>
  </define>
  <!--
    =============================================================================
                                     File level
    =============================================================================
  -->
  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <define name="composition.file">
    <element name="file">
      <ref name="composition.file.attributes"/>
    </element>
  </define>
  <define name="selection.file">
    <element name="file">
      <ref name="selection.file.attributes"/>
    </element>
  </define>
  <!-- ~~~~~~ attributes -->
  <define name="composition.file.attributes">
    <interleave>
      <ref name="name.attribute"/>
      <optional>
        <ref name="xpath.attribute"/>
      </optional>
      <ref name="remap.attributes"/>
    </interleave>
  </define>
  <define name="selection.file.attributes">
    <interleave>
      <ref name="name.attribute"/>
      <optional>
        <ref name="xpath.attribute"/>
      </optional>
    </interleave>
  </define>
  <define name="name.attribute">
    <attribute name="name"/>
  </define>
  <define name="xpath.attribute">
    <attribute name="xpath"/>
  </define>
  <!--
    =============================================================================
                                    Inline level
    =============================================================================
  -->
  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ inlines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <define name="inlines">
    <mixed>
      <interleave>
        <zeroOrMore>
          <ref name="sup"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="sub"/>
        </zeroOrMore>
      </interleave>
    </mixed>
  </define>
  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub, sup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <define name="sup">
    <element name="sup">
      <ref name="inlines"/>
    </element>
  </define>
  <define name="sub">
    <element name="sub">
      <ref name="inlines"/>
    </element>
  </define>
  <!--
    =============================================================================
                                  Remap attributes
    =============================================================================
  -->
  <define name="remap.attributes">
    <interleave>
      <optional>
        <ref name="as.attribute"/>
      </optional>
      <optional>
        <ref name="attributes.attribute"/>
      </optional>
    </interleave>
  </define>
  <define name="as.attribute">
    <attribute name="as">
      <data type="QName"/>
    </attribute>
  </define>
  <define name="attributes.attribute">
    <attribute name="attributes">
      <list>
        <oneOrMore>
          <data type="token">
            <param name="pattern">\c+=\S+</param>
          </data>
        </oneOrMore>
      </list>
    </attribute>
  </define>
</grammar>