<?xml version="1.0" encoding="UTF-8"?>
<!-- This schema defines the Enterprise Mashup Markup Language(EMML), version 1.0, using the following
     namespaces: 
     
     * http://www.openemml.org/2009-04-15/EMMLSchema (for EMML proper)
     * http://www.openemml.org/2009-04-15/EMMLMacro (for references to macros defined using EMML)
  
     This schema is licensed under a Creative Commons Attribution-No Derivative Works 3.0 United States License 
     (see http://creativecommons.org/licenses/by-nd/3.0/us/ for the full text). Extensions to the EMML Schema
     that include the EMML Schema in its entirety and define all extensions in a namespace separate from the 
     EMML namespaces are considered a 'Collection' and not an 'Adaptation' under this license.      
     -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:macro="http://www.openemml.org/2009-04-15/EMMLMacro"
  xmlns="http://www.openemml.org/2009-04-15/EMMLSchema" 
  targetNamespace="http://www.openemml.org/2009-04-15/EMMLSchema" 
  elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">


<!-- .......... Root Elements ........... -->
<!-- mashup script -->
<xs:element name="mashup">
  <xs:annotation>
    <xs:documentation><p>A script defining a mashup that may combine, filter or otherwise process the results from one or more publicly accessible services (component services) or web sites.</p></xs:documentation>
  </xs:annotation>
  <xs:complexType>
    <xs:choice>
      <xs:group ref="OperationGroup"/>
      <xs:choice maxOccurs="unbounded">
        <xs:group ref="Declarations"/>
        <xs:group ref="VariablesGroup"/>
        <xs:group ref="Statements"/>
        <xs:group ref="Macroincludes"/>
        <xs:group ref="MacroRefs"/>
      </xs:choice>
    </xs:choice>
    <xs:attribute name="name" type="xs:string">
      <xs:annotation>
        <xs:documentation><p>The optional logical name for this mashup. Names must be unique and can contain ASCII letters, numerals, underscores (_) or dashes (-). Names must start with a letter. </p></xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>
</xs:element>

<!-- mashup macro library -->
<xs:element name="macros">
  <xs:annotation>
    <xs:documentation><p>The root element for a file containing one or more macro definitions that may be included in many EMML scripts. By default, each EMML Engine has a <code>global.emml-macros</code> file with global macros. You can add custom macro library files to EMML Engines.</p></xs:documentation>
  </xs:annotation>
  <xs:complexType>
    <xs:choice maxOccurs="unbounded">
      <xs:group ref="Macroincludes"/>
    </xs:choice>
  </xs:complexType>
</xs:element>

<!-- .......... Substitution Group Heads .......... -->
<!-- Allows extension schemas to define extension-specific metadata -->
<xs:element name="emml-meta" type="metadataType">
  <xs:annotation>
    <xs:documentation><p>One EMML built-in metadata property to assign to this mashup or macro. </p></xs:documentation>
  </xs:annotation>
</xs:element>

<xs:element name="sqlBeginTransaction" type="sqlTransactionType">
  <xs:annotation>
    <xs:documentation><p>This statement marks the beginning of a SQL transaction that includes all &lt;sqlUpdate&gt; statements until a &lt;sqlCommit&gt; or &lt;sqlRollback&gt; statement is encountered. </p></xs:documentation>
  </xs:annotation>
</xs:element>

<xs:element name="sqlCommit" type="sqlTransactionType">
  <xs:annotation>
    <xs:documentation><p>This statement marks the successful end of a SQL transaction that includes all &lt;sqlUpdate&gt; statements since the &lt;sqlBeginTransaction&gt; statement. </p></xs:documentation>
  </xs:annotation>
</xs:element>

<xs:element name="sqlRollback" type="sqlTransactionType">
  <xs:annotation>
    <xs:documentation><p>This statement marks the unsuccessful end of a SQL transaction that includes all &lt;sqlUpdate&gt; statements since the &lt;sqlBeginTransaction&gt; statement. </p></xs:documentation>
  </xs:annotation>
</xs:element>

<!-- .......... Shared Content Groups ......... -->
<!-- declarations -->
<xs:group name="Declarations">
  <xs:annotation>
    <xs:documentation>
      <link>true</link>
      <description><p>Declarations define the variables, meta data or macros used within a mashup. Variables include input parameters and the result of the mashup. Meta data may be user- or system-defined. </p></description>
    </xs:documentation>
  </xs:annotation>
  <xs:choice>
    <xs:element ref="emml-meta"/>
    <xs:element name="input">
      <xs:annotation>
        <xs:documentation><p>Optional element to declare parameters that can be used as input to a mashup, operation or macro. Input parameters can be used to provide values for EMML statements including input parameters for component services. </p></xs:documentation>
      </xs:annotation>
      <xs:complexType mixed="true">
        <xs:choice>
          <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax">
            <xs:annotation>
              <xs:documentation><p>Typically empty. The input data can be defined as text and any well-formed literal XML. </p></xs:documentation>
            </xs:annotation>
          </xs:any>
        </xs:choice>
        <xs:attributeGroup ref="nameReq"/>
        <xs:attributeGroup ref="typeReq"/>
        <xs:attributeGroup ref="serviceOpt"/>
        <xs:attributeGroup ref="defaultOpt"/>
      </xs:complexType>
    </xs:element>
    <xs:element name="output">
      <xs:annotation>
        <xs:documentation><p>The parameter that holds the result returned from this mashup, operation or macro. </p></xs:documentation>
      </xs:annotation>
      <xs:complexType mixed="true">
        <xs:choice>
          <xs:any minOccurs="0" namespace="##any" processContents="lax">
            <xs:annotation>
              <xs:documentation><p>Typically empty. Can contain text and any well-formed literal XML. If content is defined within this statement, this is the sole output for the mashup or operation. </p></xs:documentation>
            </xs:annotation>
          </xs:any>
        </xs:choice>
        <xs:attributeGroup ref="nameReq"/>
        <xs:attributeGroup ref="typeReq"/>
        <xs:attributeGroup ref="serviceOpt"/>
        <xs:attributeGroup ref="defaultOpt"/>
      </xs:complexType>
    </xs:element>
    <xs:element name="user-meta">
      <xs:annotation>
        <xs:documentation><p>One user-defined metadata property to assign to this mashup. User-defined property names should be unique within a given mashup script and cannot use reserved property names. You assign the value for this property as the value of this element. </p></xs:documentation>
      </xs:annotation>
      <xs:complexType mixed="true">
        <xs:choice>
          <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax">
            <xs:annotation>
              <xs:documentation><p>Can contain text and any well-formed literal XML. Valid content is user defined. </p></xs:documentation>
            </xs:annotation>
          </xs:any>
        </xs:choice>
        <xs:attribute name="name" use="required" type="xs:string">
          <xs:annotation>
            <xs:documentation><p>The name of this user-defined metadata property. </p></xs:documentation>
          </xs:annotation>
        </xs:attribute>
      </xs:complexType>
    </xs:element>
  </xs:choice>
</xs:group>

<!-- statements -->
<xs:group name="Statements">
  <xs:annotation>
    <xs:documentation>
      <link>true</link>
      <description><p>Statements are the actions that the mashup performs. </p></description>    </xs:documentation>
  </xs:annotation>
  <xs:choice>
    <xs:element name="annotate" type="annotateType">
      <xs:annotation>
        <xs:documentation><p>This statement adds attributes or children nodes to node(s) of a document-type variable. Each added node is defined in text within the body of &lt;annotate&gt; in the form:</p><p><code>[element | attribute] <i>name   value</i></code></p><p>Both the name and value of attributes or children can be a static or dynamic expressions. Separate multiple annotation definitions with commas.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="appendresult" type="appendResultType">
      <xs:annotation>
        <xs:documentation><p>This statement appends the well-formed document fragment defined in its content to the specified variable. This is commonly used with repeating statements, such as &lt;for&gt; or &lt;foreach&gt;.</p><p>The document fragment contains literal XML with static values or dynamic mashup expressions. Elements in the structure should use a namespace, so that they are clearly separated from EMML markup. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="assign" type="assignType">
      <xs:annotation>
        <xs:documentation><p>Use &lt;assign&gt; to assign values to a variable. Values may be: </p><ul><li><p>Literal values</p></li><li><p>Fragments of another variable</p></li><li><p>A whole variable</p></li></ul><p>You use XPath expressions to define the fragments or variables to assign or otherwise modify the resulting variable content.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="assert" type="assertType">
      <xs:annotation>
        <xs:documentation><p>Use &lt;assert&gt; to add error checking assertions within a mashup, operation, macro or other statement. Assertions are evaluated at runtime and throw exceptions if they evaluate to false. </p><p>Assertions may compare any two of the following:</p><ul><li><p>A variable</p></li><li><p>An XPath expression of any kind</p></li><li><p>A literal value</p></li><li><p>A count of nodes identified by an XPath expression</p></li><li><p>A count of the levels of descendants from a node or node set identified by an XPath expression</p></li></ul></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="constructor" type="constructorType">
      <xs:annotation>
        <xs:documentation><p>This statement constructs a well-formed document, wrapped in a root node, and assigns it to an input or output parameter or to a variable. You define the structure as literal XML and assign static data or use dynamic mashup expressions to assign data dynamically. </p><p class="note">it is a good practice to use a separate namespace for the elements in the structure being constructed, so that they are clearly separated from EMML markup. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="directinvoke" type="directInvokeType">
      <xs:annotation>
        <xs:documentation><p>Use &lt;directinvoke&gt; to invoke services or web sites that are publically accessible on the Web or accessible internally within your organization. Web services must have a REST, SOAP or syndication (RSS/Atom) interface.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="display" type="displayType">
      <xs:annotation><xs:documentation><p>This statement sends a debugging message to the standard output (both log and console) when the mashup script is processed. Messages can contain both static and dynamic content. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="filter" type="filterType">
      <xs:annotation>
        <xs:documentation><p>This statement filters the content of a variable based on a condition and places the result in a new variable. You can also simply update the input variable with filtered results. </p><p>The filter condition is defined in an XPath expression. You can use comparisons, position, XPath functions and dynamic expressions in the condition. You can also combine multiple conditions.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="for" type="forType">
      <xs:annotation>
        <xs:documentation><p>This looping statement processes any children statements in a repeated loop for the specified count. The count may be static or may use expressions to define a dynamic limit. The increment is always one.</p><p>You can use most EMML statements within &lt;for&gt;. You can also use &lt;break&gt; within this statement to forceably stop loop processing. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="foreach" type="forEachType">
      <xs:annotation>
        <xs:documentation><p>This looping statement processes any children statements in either a repeated loop or in parallel for each node in a node set. The node set is defined in an XPath expression.</p><p>You can use most EMML statements within &lt;foreach&gt;. You can also use &lt;break&gt; within this statement to forceably stop loop processing. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="group" type="groupType">
      <xs:annotation>
        <xs:documentation><p>This statement groups repeating nodes, optionally filtering and sorting them, based on an XPath expression. It constructs a document structure from the group using literal XML you define and dynamic expressions to determine content or perform calculations. Groups can be nested, allowing any level of detail.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="invoke" type="invokeType">
      <xs:annotation>
        <xs:documentation><p>This statement is not yet implemented. It is reserved for future use to invoke an operation for a component service that is governed by another system. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="if" type="ifType">
      <xs:annotation>
        <xs:documentation><p>This conditional statement follows the well-known if-elseif-else control pattern to processes specific children statements based on one or more conditions. Both &lt;elseif&gt; and &lt;else&gt; are optional. </p><p>You can use most EMML statements within &lt;if&gt;, &lt;elseif&gt; or &lt;else&gt;. You can also use &lt;break&gt; within these statements if they are descendants of a looping statement to forceably stop the ancestor loop processing. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="join" type="joinType">
      <xs:annotation>
        <xs:documentation><p>This statement defines how the data from disparate variables should be joined. Variable data should have repetitive structures that are related based on some criteria in those structures - the foreign keys that define the relation. Optionally, you can also select specific nodes from the result and modify them to build the resulting document structure. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="merge" type="unionType">
      <xs:annotation>
        <xs:documentation><p>Merges the results of two or more variables with a uniform structure or type. The structures of the variables must be identical, except for root node names, and they must be document type variables. Optionally, this can also select specific nodes to be included in the output. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="parallel" type="parallelType">
      <xs:annotation>
        <xs:documentation><p>This container statement processes one or more groups of statements in parallel. Each group of statements to be processed concurrently is defined within a &lt;sequence&gt; statement. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="script" type="scriptType">
      <xs:annotation>
        <xs:documentation><p>This statement includes scripting code to execute as the mashup script is processed. Script code can be included as the content of &lt;script&gt; or &lt;script&gt; can import code from an external file from the local server.</p><p class="note">JavaScript and JRuby are supported as scripting languages.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="select" type="selectType">
      <xs:annotation>
        <xs:documentation><p>This statement selects specific nodes in all repeating children from an input variable and places the result in a variable. This acts as a 'column filter,' selecting specific nodes within all repeating children. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="sort" type="sortType">
      <xs:annotation>
        <xs:documentation><p>This statement sorts the content of a document-type variable or variable fragment based on key expressions and places the result in another variable. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="sql" type="sqlType">
      <xs:annotation>
        <xs:documentation><p>Use &lt;sql&gt; to issue individual SQL queries to a data source that you have declared in the mashup script. You can also use this command to invoke stored procedures that return result sets.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element ref="sqlBeginTransaction"/>
    <xs:element ref="sqlCommit"/>
    <xs:element name="sqlRollback"/>
    <xs:element name="sqlUpdate" type="sqlUpdateType">
      <xs:annotation>
        <xs:documentation><p>Use &lt;sqlUpdate&gt; to execute any SQL statement that is not a query against a data source that you have declared in the mashup script. This includes basic statements to update database records or stored procedures that do <b>not</b> return result sets.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="template" type="templateType">
      <xs:annotation>
        <xs:documentation><p>This statement defines an expression with dynamic parameters and assigns that to a variable. This variable can then be referred to dynamically in other mashup script statements that use expressions. </p></xs:documentation>
      </xs:annotation>
    </xs:element>  
    <xs:element name="while" type="whileType">
      <xs:annotation>
        <xs:documentation><p>This looping statement processes any children statements in a repeated loop as long as its specified condition remains true or until a &lt;break&gt; statement is executed. You can use most EMML statements within &lt;while&gt;. You can also use &lt;break&gt; to explictly stop further loop processing. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="xslt" type="xsltType">
      <xs:annotation>
        <xs:documentation><p>This statement processes an XSLT 2.0 stylesheet that has been deployed in the EMML Engine. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:choice>
</xs:group>

<!-- break group -->
<xs:group name="BreakGroup">
  <xs:sequence>
    <xs:element name="break" >
      <xs:annotation>
        <xs:documentation><p>This statement forceably stops loop processing for &lt;for&gt;, &lt;foreach&gt; or &lt;while&gt; statements. You can also use this in &lt;if&gt;, &lt;elseif&gt; or &lt;else&gt; statements if they are descendants of a looping statement. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:sequence>
</xs:group>

<!-- operation group -->
<xs:group name="OperationGroup">
  <xs:sequence>
    <xs:element name="operation" type="operationType">
    <xs:annotation>
      <xs:documentation><p>A named operation for this mashup service. </p></xs:documentation>
    </xs:annotation>
    </xs:element>
  </xs:sequence>
</xs:group>

<!-- macroincludes -->
<xs:group name="Macroincludes">
  <xs:annotation>
    <xs:documentation>
      <link>true</link>
      <description><p>Macros define custom statements for use in a specific mashup or in any mashup hosted by a given EMML Engine. They are 'mini-mashups.'</p><p>Include statements allow you to include macro definitions from a macro library in a mashup or in another macro library. </p></description>
    </xs:documentation>
  </xs:annotation>
  <xs:choice>
    <xs:element name="include">
      <xs:annotation>
        <xs:documentation><p>A statement to include the macro definitions from a macro library file in a mashup script or another macro library. The included macro library must be deployed in the EMML Engine that hosts this mashup service. </p></xs:documentation>
      </xs:annotation>
      <xs:complexType>
        <xs:attribute name="file" type="xs:string" use="required">
          <xs:annotation>
            <xs:documentation><p>The name of the macro library file containing EMML macros to included here.</p></xs:documentation>
          </xs:annotation>
        </xs:attribute>
      </xs:complexType>
    </xs:element>
    <xs:element name="macro" type="macroType">
      <xs:annotation>
        <xs:documentation><p>One macro definition in an EMML script or a macro library. Macros define custom statements that can be used in mashup scripts.</p><p>Macros can contain any EMML declaration except for definitions of another macro. Macros can contain any EMML statement, except for the statement to call another macro.</p><p>Macros allow behavior to be parameterized. They support both input parameters and an output parameter. </p><p>Macros have access to the variables defined within the macro plus all variables in the calling EMML script. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:choice>
</xs:group>

<!-- references to user-defined macros or other elements in other namespaces -->
<xs:group name="MacroRefs">
  <xs:choice>
    <xs:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.jackbe.com/2008-03-01/EMMLMacro" processContents="lax">
      <xs:annotation>
        <xs:documentation>
          <filename>macroUse</filename>
          <elementname>macro:custom-macro-name</elementname>
          <description><p>The use of a custom EMML statement defined in a macro of that name. To use macros in a mashup script, you must declare the macro reference namespace and use the namespace prefix with your custom macro name. </p><p>Pass input parameters to the custom macro as attributes in this statement. Use the <code>outputvariable</code> attribute to identify the variable that should receive the results of the macro, if any.</p></description>
          <content-model>Empty. Input parameters to the macro are passed as attributes of the same name. </content-model>
          <as-child>( macro:custom-macro-name | any element in a non-EMML namespace )</as-child>
        </xs:documentation>
      </xs:annotation>
    </xs:any>
  </xs:choice>
</xs:group>

<!-- variables -->
<xs:group name="VariablesGroup">
  <xs:choice>
    <xs:element name="datasource">
      <xs:annotation>
        <xs:documentation><p>Optional element to declare the connection information to a database. Connection configuration can be specified as a JDBC connection or using JNDI. This connection information is used to execute SQL commands. </p><p>You can declare any number of named datasources in a mashup script. You can also use a single, unnamed datasource that is considered the default. EMML statements that execute SQL commands and do not have a datasource name use the default datasource. </p><p>Datasource names must be <b>unique</b> within a given EMML Engine. </p></xs:documentation>
      </xs:annotation>
      <xs:complexType>
        <xs:attribute name="name" type="xs:string">
          <xs:annotation>
            <xs:documentation><p>Optional name for this datasource. If omitted, this becomes the default datasource for SQL commands that do not define a datasource. </p></xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="url" type="xs:anyURI" >
          <xs:annotation>
            <xs:documentation><p>The URL for a JDBC connection to this datasource in the form <code>jdbc:<i>name:protocol://host:port</i></code>. If omitted, you must specify connection information for this datasource in the <code>jndiname</code> attribute.</p></xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="driverClassName" type="xs:string">
          <xs:annotation>
            <xs:documentation><p>The class name of the driver for a JDBC connection to this datasource. This is only relevant if <code>url</code>code is specified. If omitted, this defaults to the HSQLDB JDBC driver class. </p></xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="username" type="xs:string">
          <xs:annotation>
            <xs:documentation><p>The user name for the JDBC connection to this datasource. This is required for JDBC connections (with <code>url</code>), but is not relevant for JNDI connections. </p></xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="password" type="xs:string">
          <xs:annotation>
            <xs:documentation><p>The password for the JDBC connection to this datasource. Unless you specify a JNDI connection, this is required, but can be empty when no password is needed. </p></xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="jndiname" type="xs:string">
          <xs:annotation>
            <xs:documentation><p>The JDNI name for this datasource, in the form <code>java:/comp/env/jdbc/<i>jndi-name</i></code>. If omitted, you must specify JDBC connection information in the <code>url</code> and related attributes.</p></xs:documentation>
          </xs:annotation>
        </xs:attribute>
      </xs:complexType>
    </xs:element>
    <xs:element name="variables" type="variablesType">
      <xs:annotation>
        <xs:documentation><p>A list of variables to use for input, output or to hold any intermediate data or document content in the flow of mashup processing. Variables must be declared as direct children of &lt;mashup&gt;, &lt;macro&gt;, &lt;operation&gt; or any looping statement that can contain other EMML statements.</p><p>Variables declared in &lt;mashup&gt; or &lt;operation&gt; have a global scope and are accessible in any statement. Variables declared in &lt;macro&gt; or looping statements have only a statement scope. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="variable" type="variableType">
      <xs:annotation>
        <xs:documentation><p>One variable to hold input, output or any intermediate data or document content.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:choice>
</xs:group>

<!-- .......... Types ......... -->
<!-- annotate -->
<xs:complexType name="annotateType">
  <xs:simpleContent>
    <xs:annotation>
      <xs:documentation><p>The specific syntax for annotations.</p></xs:documentation>
    </xs:annotation>
    <xs:extension base="xs:string">
      <xs:attributeGroup ref="variableReq"/>
      <xs:attribute name="expr" type="xs:string" use="required">
        <xs:annotation>
          <xs:documentation><p>The relative path within the input variable to the node to be annotated.</p></xs:documentation>
        </xs:annotation>
      </xs:attribute>
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

<!--  appendResult -->
<xs:complexType name="appendResultType" mixed="true">
  <xs:choice>
    <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax">
      <xs:annotation>
        <xs:documentation><p>Can contain text and any well-formed literal XML. </p></xs:documentation>
      </xs:annotation>
    </xs:any>
  </xs:choice>
 <xs:attributeGroup ref="outputVarReq"/>
</xs:complexType>

<!-- assign -->
<xs:complexType name="assignType">
  <xs:attribute name="fromvariable" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The variable to copy. &lt;assign&gt; must have either a <code>fromvariable</code>, a <code>fromexpr</code> or a <code>literal</code> attribute. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="fromexpr" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An expression identifying a variable or variable fragment and any functions to apply before copying the result. &lt;assign&gt; must have either a <code>fromvariable</code>, a <code>fromexpr</code> or a <code>literal</code> attribute. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="literal" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>A literal value to assign. &lt;assign&gt; must have either a <code>fromvariable</code>, a <code>fromexpr</code> or a <code>literal</code> attribute. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="toexpr" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An XPath expression defining a specific node in a variable that is the target to be assigned. &lt;assign&gt; must have either a <code>toexpr</code> or an <code>outputvariable</code> attribute. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="outputvariable" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The variable that is the target to be assigned. &lt;assign&gt; must have either a <code>toexpr</code> or an <code>outputvariable</code> attribute. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- assert -->
<xs:complexType name="assertType">
  <xs:attribute name="actualexpr" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An XPath expression identifying one or more nodes, values or any valid calculation to be used in the comparison for this assertion. Assertions must contain at least one of <code>actualexpr</code> or <code>actualvar</code>.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="actualvar" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The variable to be used in the comparison for this assertion. For variables that are a document type, the comparison is made for all nodes.</p><p>Assertions must contain at least one of <code>actualexpr</code> or <code>actualvar</code>.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="equals" type="xs:boolean">
    <xs:annotation>
      <xs:documentation><p>Optionally determines what operator is used for the comparison of this assertion. True (the default) uses equals as the operator or false uses not equals.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="expectedexpr" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An XPath expression identifying one or more nodes, values or any valid calculation that the <code>actualexpr</code> or <code>actualvar</code> should be compared to. Assertions must contain at least one of <code>expectedexpr</code>, <code>expectedvar</code>, <code>literal</code>, <code>count</code> or <code>elementdepth</code>. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="expectedvar" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The variable that the <code>actualexpr</code> or <code>actualvar</code> should be compared to. Assertions must contain at least one of <code>expectedexpr</code>, <code>expectedvar</code>, <code>literal</code>, <code>count</code> or <code>elementdepth</code>. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="literal" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The literal value that the <code>actualexpr</code> or <code>actualvar</code> should be compared to. This value is treated as a string.</p><p>Assertions must contain at least one of <code>expectedexpr</code>, <code>expectedvar</code>, <code>literal</code>, <code>count</code> or <code>elementdepth</code>. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="count" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An XPath expression identifying a set of one or more nodes. The <code>actualexpr</code> or <code>actualvar</code> is compared against the number of nodes found in this node set.</p><p>Assertions must contain at least one of <code>expectedexpr</code>, <code>expectedvar</code>, <code>literal</code>, <code>count</code> or <code>elementdepth</code>. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="elementdepth" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An XPath expression identifying a set of one or more nodes. The <code>actualexpr</code> or <code>actualvar</code> is compared against the number of levels of descendants <b>plus 1</b> (for the node itself) of the nodes in this node set. </p><p>Assertions must contain at least one of <code>expectedexpr</code>, <code>expectedvar</code>, <code>literal</code>, <code>count</code> or <code>elementdepth</code>. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- constructor -->
<xs:complexType name="constructorType" mixed="true">
  <xs:choice>
    <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax">
      <xs:annotation>
        <xs:documentation><p>Can contain text and any well-formed literal XML. </p></xs:documentation>
      </xs:annotation>
    </xs:any>
  </xs:choice>
  <xs:attributeGroup ref="outputVarReq"/>
</xs:complexType>

<!-- directInvoke -->
<xs:complexType name="directInvokeType">
  <xs:attribute name="endpoint" type="xs:anyURI" use="required">
    <xs:annotation>
      <xs:documentation><p>The URI to the endpoint for the publicly accessible web service to invoke. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="method" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>Either GET or POST.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="requestbody" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An optional attribute for the name of the variable containing the body of the request to send when <code>method = 'POST'</code>. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="headerAttr"/>
  <xs:attribute name="feedtype">
    <xs:annotation>
      <xs:documentation><p>An optional attribute for syndication feeds identifying the protocol for normalization. </p></xs:documentation>
    </xs:annotation>
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="rss">
          <xs:annotation>
            <xs:documentation><p>Normalizes the feed results to RSS 2.0.</p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="atom">
          <xs:annotation>
            <xs:documentation><p>Normalizes the feed results to Atom 1.0.</p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
  <xs:attributeGroup ref="outputVarReq"/>
  <xs:attribute name="responseheader" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An optional attribute for the name of the variable to receive HTTP headers from the response. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="responsecode" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An optional attribute for the name of the variable to receive the HTTP status code from the response. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="cookies" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An optional attribute for the name of the variable to receive cookies from the response. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="bypassproxy" type="xs:boolean">
    <xs:annotation>
      <xs:documentation><p>An optional attribute to have the invocation bypass the proxy server, if any. This is <code>false</code> by default.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="invokeControls"/>
  <xs:anyAttribute processContents="lax">
    <xs:annotation>
      <xs:documentation><p>Any service-related attribute. Service-related attributes are passed to the ungoverned web service as input parameters. They can be unqualified (no namespace) or any namespace other than the EMML namespace.</p></xs:documentation>
    </xs:annotation>
  </xs:anyAttribute>
</xs:complexType>

<!-- display -->
<xs:complexType name="displayType">
  <xs:attribute name="message" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The static portion of a debugging message for this mashup script.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="expr" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An optional XPath 2.0 expression to provide a dynamic value as part of a debuggning message for this mashup script. You cannot have both an expression and a variable in a debugging message. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="variable" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An optional variable to provide a dynamic value as part of a debuggning message for this mashup script. You cannot have both an expression and a variable in a debugging message. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- else  -->
<xs:complexType name="elseType">
  <xs:choice maxOccurs="unbounded">
    <xs:group ref="Statements"/>
    <xs:group ref="MacroRefs"/>
    <xs:group ref="VariablesGroup"/>
  </xs:choice>
</xs:complexType>

<!-- elseif -->
<xs:complexType name="elseIfType">
  <xs:choice maxOccurs="unbounded">
    <xs:group ref="Statements"/>
    <xs:group ref="MacroRefs"/>
    <xs:group ref="BreakGroup"/>
    <xs:group ref="VariablesGroup"/>
  </xs:choice>
  <xs:attribute name="condition" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>An expression for the condition to test for the &lt;elseif&gt; statement. If this condition is matched, the statements that are direct children of &lt;elseif&gt; are processed and any subsequent &lt;elseif&gt; statements or the &lt;else&gt; statement is skipped.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- filter -->
<xs:complexType name="filterType">
  <xs:attribute name="inputvariable" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The name of the input variable to filter.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="filterexpr" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>An expression that defines the filter to apply to the input variable. All matching nodes are included in the result.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="outputVarReq"/>
</xs:complexType>
 
<!-- for -->
<xs:complexType name="forType">
  <xs:choice maxOccurs="unbounded">
    <xs:group ref="Statements"/>
    <xs:group ref="MacroRefs"/>
    <xs:group ref="BreakGroup"/>
    <xs:group ref="VariablesGroup"/>
  </xs:choice>
  <xs:attribute name="variable" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The name for the counter variable for this looping statement. The scope for this variable is limited to the &lt;for&gt; loop. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="startcountervalue" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The number or expression that defines the number to use as the counter for the first loop. The increment is always one. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="finalcountervalue" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The number or expression that defines the number of the last loop to execute. Expressions must evaluate to an integer value.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- forEach  -->
<xs:complexType name="forEachType">
  <xs:choice maxOccurs="unbounded">
    <xs:group ref="Statements"/>
    <xs:group ref="MacroRefs"/>
    <xs:group ref="BreakGroup"/>
    <xs:group ref="VariablesGroup"/>
    <xs:element name="fuse">
      <xs:annotation>
        <xs:documentation><p>Optionally, defines the literal XML structure and specific nodes or computations to include in the result when loops are processed concurrently for &lt;foreach&gt;. If this is omitted, loops are processed concurrently, but the results of each loop are not bound to any variables. </p><p>How results for each loop are fused together and assigned to variable(s) depends on the value of the <code>merge</code> attribute in &lt;foreach&gt;. The &lt;fuse&gt; <code>outputvariable</code> attribute identifies the variable for the fused result, and if applicable the base name for variable names for the results of each loop. </p><p class="note">The structure inside &lt;fuse&gt; must be well-formed, enclosed in a root node.  Elements in the structure should use a namespace, so that they are clearly separated from EMML markup. </p></xs:documentation>
      </xs:annotation>
      <xs:complexType mixed="true">
        <xs:choice>
          <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax">
            <xs:annotation>
              <xs:documentation><p>Can contain text and any well-formed literal XML. </p></xs:documentation>
            </xs:annotation>
          </xs:any>
        </xs:choice>
        <xs:attributeGroup ref="outputVarReq"/>
      </xs:complexType>
    </xs:element>
  </xs:choice>
  <xs:attribute name="variable" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The name for the variable to hold each 'item' for this looping statement. The scope for this variable is limited to the &lt;foreach&gt; loop. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="items" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>An XPath 2.0 expression that defines the set of nodes (or sequence) to loop through. The length of this set defines the limit for looping and typically also defines a context for relative expressions used in statements or content within the &lt;foreach&gt; loop.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="parallel">
    <xs:annotation>
      <xs:documentation><p>Determines whether each loop is processed sequentially (the default) or concurrently (<code>parallel="yes"</code>). </p></xs:documentation>
    </xs:annotation>
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="yes">
          <xs:annotation>
            <xs:documentation><p>Process each loop concurrently. </p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="no">
          <xs:annotation>
            <xs:documentation><p>Process each loop sequentially. This is the default. </p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
  <xs:attribute name="tasks">
    <xs:annotation>
      <xs:documentation><p>Determines how many loops are processed when loops are processed concurrently (<code>parallel="yes"</code>). This can be all loops or any one loop (the first loop to complete ends all loop processing). </p></xs:documentation>
    </xs:annotation>
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="InvokeAll">
          <xs:annotation>
            <xs:documentation><p>Process all loops. </p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="invokeAll">
          <xs:annotation>
            <xs:documentation><p>Process all loops. </p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="invokeall">
          <xs:annotation>
            <xs:documentation><p>Process all loops. </p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="InvokeAny">
          <xs:annotation>
            <xs:documentation><p>The completion of any one loop ends loop processing.</p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="invokeAny">
          <xs:annotation>
            <xs:documentation><p>The completion of any one loop ends loop processing.</p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="invokeany">
          <xs:annotation>
            <xs:documentation><p>The completion of any one loop ends loop processing.</p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
  <xs:attribute name="merge" type="xs:boolean">
    <xs:annotation>
      <xs:documentation><p>Determines how the results from multiple concurrent loops are fused into one or more variables:</p><ul><li><p><code>true</code> = the single output variable defined in &lt;fuse&gt; holds all the results of concurrent loops "by value".</p></li><li><p><code>false</code> = the output variable defined in &lt;fuse&gt; holds a structure that references iterative variables containing the results of each concurrent loop - results "by reference". The output variable name is the base name used for iterative variables, such as $summary (the output variable), $summary1 (one loop's results), $summary2 and so on. </p></li></ul><p>This attribute is only meaningful when <code>parallel="yes"</code> and <code>tasks="invokeall"</code>.</p><p>The order in which concurrent loops are assigned or fused in variables is not determinant. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- group -->
<xs:complexType name="groupType" mixed="true">
  <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:any namespace="##any" processContents="lax">
      <xs:annotation>
        <xs:documentation><p>( group | literal XML and dynamic expressions that define the resulting output for the group)</p><p>Literal XML must be well-formed, starting with a root node.  Elements in the structure should use a namespace, so that they are clearly separated from EMML markup. </p></xs:documentation>
      </xs:annotation>
    </xs:any>
  </xs:choice>
  <xs:attribute name="by" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>An XPath expression that defines the set of nodes to group and the value for each item in that node set that defines how they are grouped. For nested groups, this XPath expression is relative to the XPath expression for the parent group.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="having" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An XPath expression that defines a criteria to select the set of nodes in the group.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="outputVarReq"/>
</xs:complexType>

<!-- if -->
<xs:complexType name="ifType">
  <xs:sequence>
    <xs:choice maxOccurs="unbounded">
      <xs:group ref="Statements"/>
      <xs:group ref="MacroRefs"/>
      <xs:group ref="BreakGroup"/>
      <xs:group ref="VariablesGroup"/>
    </xs:choice>
    <xs:element name="elseif" minOccurs="0" maxOccurs="unbounded" type="elseIfType">
      <xs:annotation>
        <xs:documentation><p>An optional, alternate condition with a set of statements to process if this condition is matched.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="else" minOccurs="0" type="elseType">
      <xs:annotation>
        <xs:documentation><p>A optional statement with a default set of children statements to process if no conditions are matched.</p></xs:documentation>
      </xs:annotation>
  </xs:element>
  </xs:sequence>
  <xs:attribute name="condition" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>An expression for the initial condition to test for the &lt;if&gt; statement. If this condition is matched, the statements that are direct children of &lt;if&gt; (not including &lt;elseif&gt; or &lt;else&gt;) are processed.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- invoke; this is not implemented -->
<xs:complexType name="invokeType">
  <xs:attribute name="service" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The service ID for the governed service to invoke.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="serviceversion" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>Optional. Reserved for future use. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="operation" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The operation ID to invoke in this service.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="inputvariables" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An optional list of input or variable names, separated by commas, to use as input parameters to the operation. Variables must be listed in the order in which the service operation expects input parameters. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="outputvariable" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The name of the variable to hold the response from this invocation. This is optional. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="headerAttr"/>
  <xs:attribute name="responseheader" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The name of the variable to receive headers in the servoce response from this invocation. This is optional. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="invokeControls"/>
  <xs:attribute name="filterexpr" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An optional XPath expression to use as a filter for the result of this service.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- join -->
<xs:complexType name="joinType">
  <xs:sequence>
    <xs:element name="select" minOccurs="0">
      <xs:annotation>
        <xs:documentation><p>Optionally, defines the literal XML structure and specific nodes or computations to include in the result of the join. If this is omitted, all nodes matching the join condition are included in the result.</p><p class="note">The structure inside &lt;select&gt; must be well-formed, starting with a root node, that is repeated for each included node.  Elements in the structure should use a namespace, so that they are clearly separated from EMML markup. </p></xs:documentation>
      </xs:annotation>
      <xs:complexType mixed="true">
        <xs:choice>
          <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax">
          <xs:annotation>
            <xs:documentation><p>Can contain text and any well-formed literal XML. Data can be literal text or assigned with dynamic mashup expressions. </p></xs:documentation>
          </xs:annotation>
          </xs:any>
        </xs:choice>
        <xs:attribute name="name" type="xs:string" use="required">
          <xs:annotation>
            <xs:documentation><p>The name to assign to the root node enclosing all selected results for the join. </p></xs:documentation>
          </xs:annotation>
        </xs:attribute>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
  <xs:attributeGroup ref="outputVarReq"/>
  <xs:attribute name="joincondition" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>An XPath 2.0 expression defining the variables to join and one or more conditions to apply to determine how variables are joined. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- macro -->
<xs:complexType name="macroType">
  <xs:choice maxOccurs="unbounded">
    <xs:group ref="Declarations"/>
    <xs:group ref="VariablesGroup"/>
    <xs:group ref="Statements"/>
  </xs:choice>
  <xs:attribute name="name" type="xs:string">
  <!-- should @name be required? -->
    <xs:annotation>
      <xs:documentation><p>The name for this macro definition. This becomes the custom statement name within the calling EMML script, so macro names must be valid XML names. They also must be unique within an EMML Engine. They can contain ASCII letters, numerals, periods (.), underscores (_) or dashes (-). Names must start with a letter. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- metadata -->
<xs:complexType name="metadataType" mixed="true">
  <xs:choice>
    <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax">
     <xs:annotation>
        <xs:documentation><p>Metadata for this mashup. </p></xs:documentation>
      </xs:annotation>
    </xs:any>
  </xs:choice>
  <xs:attribute name="name" use="required" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The name of this metadata property. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- operations -->
<xs:complexType name="operationType">
  <xs:choice maxOccurs="unbounded">
    <xs:group ref="Declarations"/>
    <xs:group ref="VariablesGroup"/>
    <xs:group ref="Statements"/>
    <xs:group ref="Macroincludes"/>
    <xs:group ref="MacroRefs"/>
  </xs:choice>
  <xs:attribute name="name" type="xs:string" default="invoke">
    <xs:annotation>
      <xs:documentation><p>The optional name for this operation. </p></xs:documentation>
      </xs:annotation>
    </xs:attribute>
</xs:complexType>

<!-- parallel -->
<xs:complexType name="parallelType">
  <xs:sequence maxOccurs="unbounded">
    <xs:element name="sequence" type="sequenceType">
      <xs:annotation>
        <xs:documentation><p>Defines a group of statements that should be processed sequentially as one concurrent task within &lt;parallel&gt;. </p></xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:sequence>
</xs:complexType>

<!-- script -->
<xs:complexType name="scriptType">
  <xs:simpleContent>
    <xs:annotation>
      <xs:documentation><p>The JavaScript code to execute. Inline scripting is only supported for JavaScript. If no inline code is provided, you must specify a source file for the code to execute. </p></xs:documentation>
    </xs:annotation>
    <xs:extension base="xs:string">
      <xs:attribute name="type" type="xs:string" use="required">
        <xs:annotation>
          <xs:documentation><p>The MIME type of the scripting language used, such as 'text/javascript'.</p></xs:documentation>
        </xs:annotation>
      </xs:attribute>
      <xs:attribute name="src" type="xs:string">
        <xs:annotation>
          <xs:documentation><p>The local file with the scripting code to include and execute here. This is required for JRuby scripts and optional for JavaScript. If omitted for JavaScript scripts, the content of &lt;script&gt; should contain the scripting code to run. </p></xs:documentation>
        </xs:annotation>
      </xs:attribute>
      <xs:attribute name="application" type="xs:string">
        <xs:annotation>
          <xs:documentation><p>An optional attribute identifying a folder containing JAR files with Java classes that are used within this script code. The EMML Engine loads classes from this application folder first.</p><p>Applications allow POJO services to use third-party libraries that may conflict with your Java application's libraries. Application folders must be deployed in the Application Server hosting the EMML Engine. </p></xs:documentation>
        </xs:annotation>
      </xs:attribute>
      <xs:attribute name="inputvariables" type="xs:string">
        <xs:annotation>
          <xs:documentation><p>A list of mashup variables separated by commas that the script should have acccess to. </p></xs:documentation>
        </xs:annotation>
      </xs:attribute>
      <xs:attribute name="outputvariable" type="xs:string">
        <xs:annotation>
          <xs:documentation><p>The mashup variable to contain the result of the script.</p></xs:documentation>
        </xs:annotation>
      </xs:attribute>
    </xs:extension>
  </xs:simpleContent>
</xs:complexType> 

<!-- select (as a statement; not in join) -->
<xs:complexType name="selectType">
  <xs:sequence>
    <xs:element name="columns">
      <xs:annotation>
        <xs:documentation><p>The set of nodes to select from each repeating item in the results of the select expression.</p></xs:documentation>
      </xs:annotation>
      <xs:complexType>
        <xs:sequence>
          <xs:element name="column" type="xs:string" maxOccurs="unbounded">
            <xs:annotation>
              <xs:documentation><p>An XPath expression identifying one node to include in the output variable for each repeating item in the results of the select expression. </p></xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
  <xs:attribute name="inputvariable" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The name of the input variable to select from.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="selectexpr" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An XPath expression that defines the set of repeating nodes in the input variable to use as the source to select from.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="outputVarReq"/>
</xs:complexType>

<!-- sequence  -->
<xs:complexType name="sequenceType">
  <xs:choice maxOccurs="unbounded">
    <xs:group ref="Statements"/>
    <xs:group ref="MacroRefs"/>
    <xs:group ref="VariablesGroup"/>
  </xs:choice>
</xs:complexType>

<!-- sort -->
<xs:complexType name="sortType">
  <xs:attribute name="inputvariable" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The name of the input variable to be sorted.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="sortexpr" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The path to the set of nodes to be sorted.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="sortkeys" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The node, relative to the the sort expression path, that should be used to define sorting.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="sortdir">
    <xs:annotation>
      <xs:documentation><p>The direction for sorting.</p></xs:documentation>
    </xs:annotation>
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="ascending">
          <xs:annotation>
            <xs:documentation><p>Sort is ascending. This is the default.</p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="descending">
          <xs:annotation>
            <xs:documentation><p>Sort is descending.</p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
  <xs:attributeGroup ref="outputVarReq"/>
</xs:complexType>

<!-- sql queries -->
<xs:complexType name="sqlType">
  <xs:attribute name="name" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The name of the data source for this query. If omitted, the query is sent to the default data source. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="query" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The query to execute. The actual SQL syntax supported depends on the database and driver class for this data source. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="startrow" type="xs:integer">
    <xs:annotation>
      <xs:documentation><p>Optionally, the index for the first row in the result set to return. If omitted, this defaults to one.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="rowcount" type="xs:integer">
    <xs:annotation>
      <xs:documentation><p>Optionally, the total number of rows in the result set to return. If omitted, this defaults to the end of the result set. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="outputVarReq"/>
</xs:complexType>

<!-- sql tranactions -->
<xs:complexType name="sqlTransactionType">
  <xs:attribute name="name" type="xs:string" >
    <xs:annotation>
      <xs:documentation><p>The name of the data source for this SQL transaction. If omitted, the transaction applies to SQL commands for the default data source. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- sql updates -->
<xs:complexType name="sqlUpdateType">
  <xs:attribute name="name" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The name of the data source for this query. If omitted, the query is sent to the default data source. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="statement" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The SQL statement to execute. The actual SQL syntax supported depends on the database and driver class for this data source. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="outputvariable" type="xs:string" >
    <xs:annotation>
      <xs:documentation><p>An optional variable to accept the output of this SQL command.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- template -->
<xs:complexType name="templateType">
  <xs:attribute name="expr" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The XPath expression to assign to the output variable. Typically, this XPath expression also contains one or more mashup expressions that will accept input parameters at runtime. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="outputVarReq"/>
</xs:complexType>

<!-- merge -->
<xs:complexType name="unionType">
  <xs:attribute name="inputvariables" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>A list of comma-separated input or variable names to use as input to the operation.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="outputVarReq"/>
  <xs:attribute name="select" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An expression identifying the specific nodes within the merged result that should be the only nodes included in the output of this statement. This expression must define a well-formed XML structure. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!--  variables -->
<xs:complexType name="variablesType">
  <xs:sequence>
    <xs:element name="variable" type="variableType" maxOccurs="unbounded">
      <xs:annotation>
        <xs:documentation><p>One variable to hold input, output or any intermediate data or document content.</p></xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:sequence>
</xs:complexType>

<!-- variable -->
<xs:complexType name="variableType" mixed="true">
  <xs:choice>
    <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax">
      <xs:annotation>
        <xs:documentation><p>Typically empty, but can contain text and any well-formed literal XML. </p></xs:documentation>
      </xs:annotation>
    </xs:any>
  </xs:choice>
  <xs:attributeGroup ref="nameReq"/>
  <xs:attributeGroup ref="typeReq"/>
  <xs:attributeGroup ref="serviceOpt"/>
  <xs:attributeGroup ref="defaultOpt"/>
</xs:complexType>

<!-- while -->
<xs:complexType name="whileType">
  <xs:choice maxOccurs="unbounded">
    <xs:group ref="Statements"/>
    <xs:group ref="MacroRefs"/>
    <xs:group ref="BreakGroup"/>
    <xs:group ref="VariablesGroup"/>
  </xs:choice>
  <xs:attribute name="condition" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>An expression for the condition to test at the beginning or each &lt;while&gt; statement loop. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>

<!-- xslt -->
<xs:complexType name="xsltType">
  <xs:attribute name="script" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The file name of the deployed XSLT stylesheet to execute. This must be just the file name, no relative paths, folders or URLs. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="inputvariable" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>An optional variable to provide input parameter(s) for the XSLT stylesheet. You can only specify variable as an input parameter to the stylesheet. Use a document-type variable to pass multiple input parameters. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attributeGroup ref="outputVarReq"/>
</xs:complexType>

<!-- .......... Shared Attributes ......... -->
<xs:attributeGroup name="nameReq">
  <xs:attribute name="name" type="xs:string"  use="required">
    <xs:annotation>
      <xs:documentation><p>The required name for a variable, input parameter or output parameter. Parameter names must be unique within the scope of the mashup script. Names for variables must be unique within the scope of the mashup, if the variable has a global scope, or within the statement in which the variable is declared. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:attributeGroup>

<xs:attributeGroup name="typeReq">
  <xs:attribute name="type"  use="required" type="xs:token">
    <xs:annotation>
      <xs:documentation><p>The required data type for this parameter or variable. Valid values for this include:</p><ul><li>boolean</li><li>date</li><li>document (complex variables that have structure)</li><li>number</li><li>string</li><li>Any token that identifies a data type defined by a service. Tokens are typically used for input or output parameters where the service has metadata for a named datatype.</li></ul><p>Input parameters for the mashup script <b>cannot</b> be a document type. Only simple types are supported for mashup input. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:attributeGroup>

<xs:attributeGroup name="serviceOpt">
  <xs:attribute name="service" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The optional name of the service that has metadata defining the data type for this parameter or variable. This is required if the value of the type attribute is a token. </p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:attributeGroup>

<xs:attributeGroup name="defaultOpt">
  <xs:attribute  name="default" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The optional default value to use for this variable, input parameter or output parameter.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:attributeGroup>

<xs:attributeGroup name="outputVarReq">
  <xs:attribute name="outputvariable" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The required variable to accept the output of this statement.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:attributeGroup>

<xs:attributeGroup name="variableReq">
  <xs:attribute name="variable" type="xs:string" use="required">
    <xs:annotation>
      <xs:documentation><p>The required input variable for this statement.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:attributeGroup>

<xs:attributeGroup name="headerAttr">
  <xs:attribute name="header" type="xs:string">
    <xs:annotation>
      <xs:documentation><p>The name of a variable containing headers to use when this service is invoked. The payload in a headers variable must be in the form:</p><pre>&lt;header&gt;
  service-specific payload for headers
&lt;/header&gt;</pre>
      </xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:attributeGroup>

<xs:attributeGroup name="invokeControls">
  <xs:attribute name="timeout" type="xs:integer" default="5">
    <xs:annotation>
      <xs:documentation><p>The maximum number of minutes to wait for a response before terminating this service invocation. The default timeout is 5 minutes.</p></xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="onerror" default="abort">
    <xs:annotation>
      <xs:documentation><p>The behavior for the mashup script if errors occur when this service is invoked. </p></xs:documentation>
    </xs:annotation>
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="abort">
          <xs:annotation>
            <xs:documentation><p>Stops all further mashup script processing after an invocation error. </p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="continue">
          <xs:annotation>
            <xs:documentation><p>Continues mashup script processing after an invocation error. </p></xs:documentation>
          </xs:annotation>
        </xs:enumeration>
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
</xs:attributeGroup>

</xs:schema>
