<?xml version="1.0" encoding="utf-8"?>
<!-- ===========================================================================
Copyright © 2004-2007 Typefi Systems. All rights reserved.

Schema Version: 1.4
Schema Location: http://www.typefi.com/TPS/content/1_4/ContentXML.xsd

Version:
    $Date: 2007-11-09 09:58:05 -0500 (Fri, 09 Nov 2007) $
    $Revision: 816 $

============================================================================ -->
<xsd:schema xmlns="http://www.typefi.com/ContentXML"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.typefi.com/ContentXML"
  elementFormDefault="qualified" attributeFormDefault="unqualified" xml:lang="en">

  <!-- ====== -->
  <!-- GROUPS -->
  <!-- ====== -->

  <!-- ===================================================================== -->
  <!-- Content is composed of paras, contexts, conditions, images and lists. -->
  <!-- ===================================================================== -->
  <xsd:group name="ContentGroup">
    <xsd:choice>
      <xsd:element name="p" type="InlineType"/>
      <xsd:element name="context" type="ContextType"/>
      <xsd:element name="condition" type="ConditionType"/>
      <xsd:element name="image" type="ImageType"/>
      <xsd:element name="ol" type="OrderedListType"/>
      <xsd:element name="ul" type="UnorderedListType"/>
      <xsd:element name="table" type="TableType"/>
    </xsd:choice>
  </xsd:group>

  <!-- ============ -->
  <!-- SIMPLE TYPES -->
  <!-- ============ -->

  <!-- ===================================================================== -->
  <!-- Valid values for the xref type attribute.                         -->
  <!--   Enumeration is here for reference. Some values will extend PartType -->
  <!-- ===================================================================== -->
  <xsd:simpleType name="XRefTypeEnumeration">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="pagecount"/>
      <xsd:enumeration value="content"/>
      <xsd:enumeration value="display"/>
      <xsd:enumeration value="itemcount"/>
      <xsd:enumeration value="itemindex"/>
      <xsd:enumeration value="indexname"/>
      <xsd:enumeration value="paracount"/>
    </xsd:restriction>
  </xsd:simpleType>

  <!-- ===================================================================== -->
  <!-- Valid values for the xef partType attribute.                         -->
  <!-- ===================================================================== -->
  <xsd:simpleType name="PartTypeEnumeration">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="content"/>
      <xsd:enumeration value="field"/>
      <xsd:enumeration value="pageNumber"/>
    </xsd:restriction>
  </xsd:simpleType>

  <!-- ===================================================================== -->
  <!-- Valid values for the xef refType attribute.                         -->
  <!-- ===================================================================== -->
  <xsd:simpleType name="RefTypeEnumeration">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="project"/>
      <xsd:enumeration value="document"/>
      <xsd:enumeration value="section"/>
      <xsd:enumeration value="context"/>
      <xsd:enumeration value="paragraph"/>
      <xsd:enumeration value="anchor"/>
    </xsd:restriction>
  </xsd:simpleType>

  <!-- ===================================================================== -->
  <!-- Valid values for the xef textType attribute.                         -->
  <!-- ===================================================================== -->
  <xsd:simpleType name="TextTypeEnumeration">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="dynamic"/>
      <xsd:enumeration value="static"/>
      <xsd:enumeration value="error"/>
    </xsd:restriction>
  </xsd:simpleType>

  <!-- ===================================================================== -->
  <!-- Valid values for the table valign attribute.                          -->
  <!-- ===================================================================== -->
  <xsd:simpleType name="TableValignEnumeration">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="top"/>
      <xsd:enumeration value="middle"/>
      <xsd:enumeration value="bottom"/>
      <xsd:enumeration value="justify"/>
    </xsd:restriction>
  </xsd:simpleType>

  <!-- ===================================================================== -->
  <!-- Valid values for the table halign attribute.                          -->
  <!-- ===================================================================== -->
  <xsd:simpleType name="TableHalignEnumeration">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="left"/>
      <xsd:enumeration value="center"/>
      <xsd:enumeration value="right"/>
      <xsd:enumeration value="justify"/>
    </xsd:restriction>
  </xsd:simpleType>

  <!-- ===================================================================== -->
  <!-- Valid values for the table rotate attribute.                          -->
  <!-- ===================================================================== -->
  <xsd:simpleType name="TableRotateEnumeration">
    <xsd:restriction base="xsd:integer">
      <xsd:enumeration value="0"/>
      <xsd:enumeration value="90"/>
      <xsd:enumeration value="180"/>
      <xsd:enumeration value="270"/>
    </xsd:restriction>
  </xsd:simpleType>

  <!-- ===================================================================== -->
  <!-- Length type (either pixels or a percentage, eg: "10" or "10%").       -->
  <!-- (Hoisted from: http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd)     -->
  <!-- ===================================================================== -->
  <xsd:simpleType name="LengthType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[\-+]?(\d+|\d+(\.\d+)?%)"/>
    </xsd:restriction>
  </xsd:simpleType>

  <!-- ============= -->
  <!-- COMPLEX TYPES -->
  <!-- ============= -->

  <!-- ===================================================================== -->
  <!-- Table cells are composed of the normal content group.                 -->
  <!-- ===================================================================== -->
  <xsd:complexType name="TableCellType">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:group ref="ContentGroup"/>
    </xsd:choice>
    <xsd:attribute name="namest" type="xsd:string" use="optional" />
    <xsd:attribute name="nameend" type="xsd:string" use="optional" />
    <xsd:attribute name="valign" type="TableValignEnumeration" use="optional"/>
    <xsd:attribute name="align" type="TableHalignEnumeration" use="optional"/>
    <xsd:attribute name="rotate" type="TableRotateEnumeration" use="optional"/>
    <xsd:attribute name="morerows" type="xsd:integer" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Table rows are composed of table cells.                               -->
  <!-- ===================================================================== -->
  <xsd:complexType name="TableRowType">
    <xsd:sequence minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="entry" type="TableCellType"/>
    </xsd:sequence>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Table Sections are composed of table rows.                            -->
  <!-- ===================================================================== -->
  <xsd:complexType name="TableSectionType">
    <xsd:sequence minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="row" type="TableRowType"/>
    </xsd:sequence>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- A table col spec defines column information for a table.              -->
  <!-- ===================================================================== -->
  <xsd:complexType name="TableColSpecType">
    <!-- colname must be a sequential integer starting with 1 -->
    <xsd:attribute name="colname" type="xsd:integer" use="required"/>    
    <xsd:attribute name="align" type="TableHalignEnumeration" use="optional"/>
    <xsd:attribute name="rotate" type="TableRotateEnumeration" use="optional"/>
    <xsd:attribute name="colwidth" type="LengthType" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- A table group is a sequence of header, body and footer regions.       -->
  <!-- ===================================================================== -->
  <xsd:complexType name="TableGroupType">
    <xsd:sequence>
      <!-- each column in the table must have a colspec -->
      <xsd:element name="colspec" minOccurs="1" maxOccurs="unbounded" type="TableColSpecType"/>
      <xsd:element name="thead" minOccurs="0" maxOccurs="1" type="TableSectionType"/>
      <xsd:element name="tbody" minOccurs="1" maxOccurs="1" type="TableSectionType"/>
      <xsd:element name="tfoot" minOccurs="0" maxOccurs="1" type="TableSectionType"/>
    </xsd:sequence>
    <xsd:attribute name="cols" type="xsd:integer" use="required"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Tables are composed of table groups.                                  -->
  <!-- ===================================================================== -->
  <xsd:complexType name="TableType">
    <xsd:sequence minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="tgroup" type="TableGroupType"/>
    </xsd:sequence>
    <xsd:attribute name="type" type="xsd:string" use="required"/>
    <xsd:attribute name="keepProportionalWidth" type="xsd:boolean" use="optional"/>
    <xsd:attribute name="keepVerticalCellAlignment" type="xsd:boolean" use="optional"/>
    <xsd:attribute name="keepHorizontalCellAlignment" type="xsd:boolean" use="optional"/>    
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Ordered List type.                                                    -->
  <!-- ===================================================================== -->
  <xsd:complexType name="OrderedListType">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="li" type="ListItemType"/>
    </xsd:choice>
    <xsd:attribute name="type" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Unordered List type.                                                  -->
  <!-- ===================================================================== -->
  <xsd:complexType name="UnorderedListType">
    <xsd:sequence minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="li" type="ListItemType"/>
    </xsd:sequence>
    <xsd:attribute name="type" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- List Item Type.                                                       -->
  <!-- ===================================================================== -->
  <xsd:complexType name="ListItemType">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:group ref="ContentGroup"/>
    </xsd:choice>
    <xsd:attribute name="condType" type="xsd:string" use="optional"/>
    <xsd:attribute name="condId" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Images contain ref and comment attributes.                            -->
  <!-- ===================================================================== -->
  <xsd:complexType name="ImageType">
    <xsd:attribute name="ref" type="xsd:string" use="optional"/>
    <xsd:attribute name="comment" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Conditions are composed of sections or standard content.              -->
  <!-- ===================================================================== -->
  <xsd:complexType name="ConditionType" mixed="true">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:group ref="ContentGroup"/>
    </xsd:choice>
    <xsd:attribute name="id" type="xsd:string" use="optional"/>
    <xsd:attribute name="type" type="xsd:string" use="required"/>
  </xsd:complexType>

  <xsd:complexType name="XRefConditionType" mixed="true">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="c" type="StyledTextType"/>
      <xsd:element name="t" type="WhitespaceType"/>
      <xsd:element name="s" type="WhitespaceType"/>
      <xsd:element name="l" type="WhitespaceType"/>
      <xsd:element name="condition" type="XRefConditionType"/>
      <xsd:element name="p" type="StyledTextType"/>
    </xsd:choice>
    <xsd:attribute name="id" type="xsd:string" use="optional"/>
    <xsd:attribute name="type" type="xsd:string" use="required"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Contexts are composed of standard content.                            -->
  <!-- ===================================================================== -->
  <xsd:complexType name="ContextType">
    <xsd:sequence>
      <xsd:element name="fieldSet" minOccurs="0" maxOccurs="unbounded" type="FieldSetType"/>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:group ref="ContentGroup"/>
      </xsd:choice>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:string" use="optional"/>
    <xsd:attribute name="type" type="xsd:string" use="required"/>
    <xsd:attribute name="variant" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Footnotes are composed of standard content.                           -->
  <!-- ===================================================================== -->
  <xsd:complexType name="FootnoteType">
    <xsd:sequence>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:group ref="ContentGroup"/>
      </xsd:choice>
    </xsd:sequence>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Endnotes are composed of standard content.                            -->
  <!-- ===================================================================== -->
  <xsd:complexType name="EndnoteType">
    <xsd:sequence>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:group ref="ContentGroup"/>
      </xsd:choice>
    </xsd:sequence>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Anchors are InlineTypes with a couple of extra attributes.            -->
  <!-- ===================================================================== -->
  <xsd:complexType name="AnchorType">
    <xsd:attribute name="name" type="xsd:string" use="optional"/>
    <xsd:attribute name="id" type="xsd:string" use="required"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Anchors are InlineTypes with a couple of extra attributes.            -->
  <!-- ===================================================================== -->
  <xsd:complexType name="EndAnchorType">
    <xsd:attribute name="name" type="xsd:string" use="optional"/>
    <xsd:attribute name="id" type="xsd:string" use="required"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- xrefs can have some content set, if they are dynamic, the content is  -->
  <!-- usually the result of resolving the xref the last time, otherwise it  -->
  <!-- is usually some static text.                                          -->
  <!--                                                                       -->
  <!-- TODO: The content of an xref needs to allow to contain conditions     -->
  <!--       and needs to allow the use of intermediate paragraphs.          -->
  <!-- ===================================================================== -->
  <xsd:complexType name="XRefType" mixed="true">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="c" type="StyledTextType"/>
      <xsd:element name="t" type="WhitespaceType"/>
      <xsd:element name="s" type="WhitespaceType"/>
      <xsd:element name="l" type="WhitespaceType"/>
      <xsd:element name="condition" type="XRefConditionType"/>
      <xsd:element name="p" type="StyledTextType"/>
    </xsd:choice>
    <xsd:attribute name="ref" type="xsd:string" use="optional"/>
    <xsd:attribute name="refType" type="RefTypeEnumeration" use="optional"/>
    <xsd:attribute name="refName" type="xsd:string" use="optional"/>
    <xsd:attribute name="refId" type="xsd:string" use="optional"/>
    <xsd:attribute name="partType" type="PartTypeEnumeration" use="optional"/>
    <xsd:attribute name="partName" type="xsd:string" use="optional"/>
    <xsd:attribute name="textType" type="TextTypeEnumeration" use="optional"/>
    <xsd:attribute name="textLimit" type="xsd:integer" use="optional"/>
    <xsd:attribute name="nolink" type="xsd:boolean" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Whitespace is an empty element with a single attribute.               -->
  <!-- ===================================================================== -->
  <xsd:complexType name="WhitespaceType">
    <xsd:attribute name="c" type="xsd:integer" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Paras are composed of inline elements.                                -->
  <!-- ===================================================================== -->
  <xsd:complexType name="InlineType" mixed="true">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="c" type="InlineType"/>
      <xsd:element name="context" type="ContextType"/>
      <xsd:element name="condition" type="InlineType"/>
      <xsd:element name="image" type="ImageType"/>
      <xsd:element name="footnote" type="FootnoteType"/>
      <xsd:element name="endnote" type="EndnoteType"/>
      <xsd:element name="anchor" type="AnchorType"/>
      <xsd:element name="endAnchor" type="EndAnchorType"/>
      <xsd:element name="xref" type="XRefType"/>
      <xsd:element name="link" type="LinkType"/>
      <xsd:element name="t" type="WhitespaceType"/>
      <xsd:element name="s" type="WhitespaceType"/>
      <xsd:element name="l" type="WhitespaceType"/>
    </xsd:choice>
    <xsd:attribute name="type" type="xsd:string" use="optional"/>
    <xsd:attribute name="id" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- Styled text is mixed with character styles and whitespace.            -->
  <!-- ===================================================================== -->
  <xsd:complexType name="StyledTextType" mixed="true">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="c" type="StyledTextType"/>
      <xsd:element name="t" type="WhitespaceType"/>
      <xsd:element name="s" type="WhitespaceType"/>
      <xsd:element name="l" type="WhitespaceType"/>
      <xsd:element name="condition" type="StyledTextType"/>
    </xsd:choice>
    <xsd:attribute name="type" type="xsd:string" use="optional"/>
    <xsd:attribute name="id" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- A field set contains the field's 'name' and 'value'.                  -->
  <!-- ===================================================================== -->
  <xsd:complexType name="FieldSetType">
    <xsd:attribute name="name" type="xsd:string" use="required"/>
    <xsd:attribute name="value" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- A link contains the reference and an optional label.                  -->
  <!-- ===================================================================== -->
  <xsd:complexType name="LinkType" mixed="true">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="c" type="SubLinkType"/>
      <xsd:element name="context" type="ContextType"/>
      <xsd:element name="condition" type="SubLinkType"/>
      <xsd:element name="image" type="ImageType"/>
      <xsd:element name="footnote" type="FootnoteType"/>
      <xsd:element name="endnote" type="EndnoteType"/>
      <xsd:element name="anchor" type="AnchorType"/>
      <xsd:element name="endAnchor" type="EndAnchorType"/>
      <xsd:element name="xref" type="XRefType"/>
      <xsd:element name="t" type="WhitespaceType"/>
      <xsd:element name="s" type="WhitespaceType"/>
      <xsd:element name="l" type="WhitespaceType"/>
    </xsd:choice>
    <xsd:attribute name="ref" type="xsd:string" use="required"/>
    <xsd:attribute name="label" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- The sub link type is a helper construction to avoid the use of        -->
  <!-- tps:link inside tps:c and tps:condition if thes occur in the context  -->
  <!-- of a tps:link. The attribute id is needed for conditions.             -->
  <!-- ===================================================================== -->
  <xsd:complexType name="SubLinkType" mixed="true">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="c" type="SubLinkType"/>
      <xsd:element name="context" type="ContextType"/>
      <xsd:element name="condition" type="SubLinkType"/>
      <xsd:element name="image" type="ImageType"/>
      <xsd:element name="footnote" type="FootnoteType"/>
      <xsd:element name="endnote" type="EndnoteType"/>
      <xsd:element name="anchor" type="AnchorType"/>
      <xsd:element name="endAnchor" type="EndAnchorType"/>
      <xsd:element name="xref" type="XRefType"/>
      <xsd:element name="t" type="WhitespaceType"/>
      <xsd:element name="s" type="WhitespaceType"/>
      <xsd:element name="l" type="WhitespaceType"/>
    </xsd:choice>
    <xsd:attribute name="type" type="xsd:string" use="optional"/>
    <xsd:attribute name="id" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ===================================================================== -->
  <!-- A section consists of (optional) fieldSets                            -->
  <!-- followed by a possibly large amount of mixed section content.         -->
  <!-- ===================================================================== -->
  <xsd:complexType name="SectionType">
    <xsd:sequence>
      <xsd:element name="fieldSet" minOccurs="0" maxOccurs="unbounded" type="FieldSetType"/>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:group ref="ContentGroup"/>
      </xsd:choice>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:string" use="optional"/>
    <xsd:attribute name="type" type="xsd:string" use="required"/>
    <xsd:attribute name="condition" type="xsd:string" use="optional"/>
  </xsd:complexType>

  <!-- ======== -->
  <!-- ELEMENTS -->
  <!-- ======== -->

  <!-- ===================================================================== -->
  <!-- A content.xml document consists of a top-level 'content' element      -->
  <!-- containing a collection of sections and conditions.                   -->
  <!-- ===================================================================== -->
  <xsd:element name="content">
    <xsd:complexType>
      <xsd:sequence>
        <!-- Allow to pass project level fields at the beginning of the     -->
        <!-- content. Section level fields would be interpreted as document -->
        <!-- level fields if they would be used here.                       -->
        <xsd:element name="fieldSet" minOccurs="0" maxOccurs="unbounded" type="FieldSetType"/>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:element name="section" type="SectionType"/>
        </xsd:choice>
      </xsd:sequence>
      <!--  type is not currently used for the content element. It is always
            set to 'book' in current TPS.
       -->
      <xsd:attribute name="type" type="xsd:string" use="optional"/>
      <xsd:attribute name="schemaVersion" use="optional" type="xsd:string"/>
    </xsd:complexType>
  </xsd:element>
  
  <!-- =====================================================================    -->
  <!-- A content.xml document can also start with a top-level 'section' element -->
  <!-- =====================================================================    --> 
  <xsd:element name="section" type="SectionType"/>
  
</xsd:schema>
