Relax NG Schema for MakeIndex Implemented via XSLT 2.0

Table of contents

<grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">

This RNG Schema defines the structure of auxiliary XML files used in reimplementation of MakeIndex via XSLT 2.0. The project is available from http://icebearsoft.euweb.cz/xslt-indexing/.

<start>

This schema defines the structure on intermediate files used by MakeIndex implemented via XSLT 2.0. The files are usually kept only in memory and never written to the disk but their output is supported for the sake of debugging. The MakeIndex stylesheet works in two steps. The input file is first parsed and afterwards sorted. The schema therefore defines structures of two related files.

<start>
  <choice>
    <element name="parsed-index">
      <oneOrMore>
        <ref name="parsed.indexentry"/>
      </oneOrMore>
    </element>
    <element name="sorted-index">
      <oneOrMore>
        <ref name="sorted.indexentry"/>
      </oneOrMore>
    </element>
  </choice>
</start>

<define name="parsed.indexentry">

Index entries may contain several levels. Only the innermost entry carries its page number. The sort key and entry text are mandatory for each level.

The pattern is used in:

<define name="parsed.indexentry">
  <element name="indexentry">
    <ref name="def.key"/>
    <ref name="def.text"/>
    <choice>
      <ref name="parsed.indexentry"/>
      <ref name="parsed.page"/>
    </choice>
  </element>
</define>

<define name="def.key">

This element contains the sort key. If it were not supplied by the user, the stylesheet is responsible for copying the contents of the <text> element.

The pattern is used in:

<define name="def.key">
  <element name="key">
    <text/>
  </element>
</define>

<define name="def.text">

This is the text of the index entry.

The pattern is used in:

<define name="def.text">
  <element name="text">
    <text/>
  </element>
</define>

<define name="parsed.page">

The page number must be an integer. The style must either be supplied in the input file or a default value must be added by the stylesheet. The range attributes are optional.

The pattern is used in:

<define name="parsed.page">
  <element name="page">
    <attribute name="number">
      <data type="integer"/>
    </attribute>
    <optional>
      <attribute name="range">
        <choice>
          <value>a-open</value>
          <value>z-close</value>
        </choice>
      </attribute>
    </optional>
    <attribute name="style"/>
  </element>
</define>

<define name="sorted.indexentry">

These elements are used in the sorted file. The entries may also be nested but all levels may contain page numbers.

The pattern is used in:

<define name="sorted.indexentry">
  <element name="indexentry">
    <attribute name="id"/>
    <attribute name="text"/>
    <oneOrMore>
      <choice>
        <ref name="sorted.indexentry"/>
        <ref name="sorted.page"/>
      </choice>
    </oneOrMore>
  </element>
</define>

<define name="sorted.page">

The contents of this element is similar to the <page> element in the parsed file. The main difference is that the ranges are collapsed to single elements. If the element represents a page range, then the number attribute contains the starting number and the rangeTo attribute contains the last page of the range. The style attribute specifies the style. It may contain the default value inserted when the source file is parsed.

The pattern is used in:

<define name="sorted.page">
  <element name="page">
    <attribute name="number">
      <data type="integer"/>
    </attribute>
    <optional>
      <attribute name="rangeTo">
        <data type="integer"/>
      </attribute>
    </optional>
    <attribute name="style"/>
  </element>
</define>