<!--;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-->
<!--                                                                        -->
<!-- Title:         Tree Processor Configuration                            -->
<!-- Status:        Prototype                                               -->
<!-- Description:   A schema for the rules for a tree processing engine     -->
<!--                A tree processing engine produces trees out of any XML  -->
<!-- Version:       1.0                                                     -->
<!-- LastModified:  3 March 2009                                            -->
<!-- Author(s):     Christophe Lauret                                       -->
<!--                                                                        -->
<!--;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-->

<!-- Type of action                                                         -->
<!ENTITY  % RELATIONSHIP     "( self | alternate | subtree )"                 >

<!-- The Namespace for the tree                                             -->
<!ENTITY  % TREE_NS       "'http://pageseeder.org/ns/tree/xml'"               >

<!-- CONTAINERS =========================================================== -->

<!--
  Top level element, identifies a set of tree definitions.
  
  A configuration without any tree definition will never produce any tree.
  But it is not an error. 
  
  @element tree-def The definition of a tree
-->
<!ELEMENT tree-config                                          ( tree-def* ) >
<!ATTLIST tree-config  xmlns           CDATA                       %TREE_NS; >

<!--
  The definition of a tree.
  
  A tree definition with no rules generates an empty tree.
  
  @element rule Defines how to build nodes from the input tree.

  @attribute id    The identifier for the tree
  @attribute match An XSLT Pattern.
-->
<!ELEMENT tree-def                                                 ( rule* ) >
<!ATTLIST tree-def     id              ID                          #REQUIRED >

<!--
  A rule to identify nodes from the input tree and generate nodes to include
  in the tree.
  
  The rule sets the context for all the XPath expressions within the rule. 

  @element unique   A unique constraint
  @element param    A parameter to use in the rule.
  @element given    A constraint for node selections.
  @element subtree  Specifies how to build the subtree.
  @element link     Specifies a link for the nodes. 

  @attribute match An XSLT Pattern.
-->
<!ELEMENT rule             (unique?, param*, given*, node?, link*, subtree?) >
<!ATTLIST rule         match           CDATA                       #REQUIRED >

<!--
  A UNIQUE constraint for the parent rule.

  @attribute select The XPath expression to enforce the UNIQUE constraint.
-->
<!ELEMENT unique                                                       EMPTY >
<!ATTLIST unique       select         CDATA                         #IMPLIED >

<!--
  An external parameter for use by the rule.
  
  External parameters can be used in XPath expressions and variable templates.

  @element   name   The name of the parameter.
-->
<!ELEMENT param                                                        EMPTY >
<!ATTLIST param        name           NMTOKEN                      #REQUIRED >

<!--
  A constraint on the rule for a given XPath expression.

  The 'given' constraint is required for online subtrees which need to 
  restrict the possible selected nodes based on the values from the current
  one.

  It is used to construct predicates by matching the name with the named
  predicated specified by the invoking subtree 'with' 
  
  For example:
  A rule (R1) invokes an inline subtree 'with' xpath '@foo' for a tree 
  definition defined in rule (R2) which expect a 'given' value for xpath 
  '@bar'. This means only nodes matched by R2 that have an attribute bar's
  value that is identical to attribute foo's value of nodes in R1.
  
  So if R1 invokes R2 'with' X=@foo
  And R2 selects node 'given' X=@bar
  The following predicate will be produced: [@foo = @bar]

  @attribute name   The name of the given value.
  @attribute select The XPath where the find the value.
-->
<!ELEMENT given                                                        EMPTY >
<!ATTLIST given        name           NMTOKEN                      #REQUIRED 
                       select         CDATA                        #REQUIRED >

<!--
  A node.

  This element is used to define nodes simply with minimum configuration
  without the need to utilise the property element.  

  It is possible to use XSLT variable templates (XPath expressions in curly
  brackets within each of the attribute values)
  
  The attribute values can also be defined using the 'property' element. 

  @element property A node property.
  
  @attribute id   The ID of the node.
  @attribute name The name of the node.
  @attribute type The type of node.
-->
<!ELEMENT node                                                     property* >
<!ATTLIST node         id             ID                            #IMPLIED
                       name           NMTOKEN                       #IMPLIED 
                       type           NMTOKEN                       #IMPLIED >

<!--
  A property of the node.

  This element is used to define properties for the node specified in the 
  rule. It is possible to define the ID, name and type attributes of the node.  

  @attribute name   The name of the property.
  @attribute select The XPath expression for the value of the property.
-->
<!ELEMENT property                                                     EMPTY >
<!ATTLIST property     name           NMTOKEN                      #REQUIRED 
                       select         CDATA                        #REQUIRED >

<!--
  The self link for this node.
  
  It is possible to use XSLT variable templates (XPath expressions in curly
  brackets within each of the attribute values)

  @attribute href The URL to that points to a representation of this node.
-->
<!ELEMENT link                                                         EMPTY >
<!ATTLIST link         rel            %RELATIONSHIP;               #REQUIRED 
                       type           NMTOKEN                       #IMPLIED 
                       href           CDATA                        #REQUIRED >

<!-- SUBTREES ============================================================ -->

<!--
  A subtree.
  
  One of 'href' or 'idref' must have a value.

  @element with   Values to pass on as constraints to match the nodes in the
                  referenced subtree.

  @attribute href   The href points to the URL that can return subtree.
  @attribute idref  The id of the tree to act as a subtree.
-->
<!ELEMENT subtree                                                    (with*) >
<!ATTLIST subtree      href           CDATA                         #IMPLIED
                       idref          IDREF                         #IMPLIED >

<!--
  A named value that the subtree should match.
  
  The name must correspond to a value constraint. If it does not, it will be
  ignored.

  @attribute name   The named predicate value.
  @attribute select The XPath where the find the value.
-->
<!ELEMENT with                                                         EMPTY >
<!ATTLIST with         name           NMTOKEN                      #REQUIRED 
                       select         CDATA                        #REQUIRED >

