<?xml version="1.0"?>

<!-- 

	flowdef_r1.7.0.xsd 

	http://openwfe.org/flowdef_r1.7.0.xsd
            and
	http://www.openwfe.org/flowdef_r1.7.0.xsd

	$Id$

	to be used with OpenWFE 1.7.0 at least

-->

<xsd:schema 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:openwfe="http://openwfe.org/xsdplus.htm"
>


    <!--
	substitution groups
    -->

    <xsd:element name="sgDefinition" />

    <xsd:element name="sgExpression" />

    <xsd:element name="sgConditional" />

    <xsd:element name="sgWorkitemAttribute" />


    <!-- 
	"process-definition" 
	or
	"define"
    -->

    <xsd:element 
	name="process-definition" 
	type="tDefine" 
	substitutionGroup="sgDefinition" 
    >
        <xsd:annotation>
            <xsd:documentation>
This expression is used to define top-level process definitions as well as subprocess definitions.
Top-level process definition require the 'revision' attribute to be set. The 'name' attribute is mandatory for top-level and sub process definitions.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch06s02.html#expression_process_definition
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
    </xsd:element>

    <xsd:element 
	name="define" 
	type="tDefine" 
	substitutionGroup="sgDefinition" 
    />

    <!-- or 'workflow-definition' -->
    <xsd:element 
	name="workflow-definition" 
	type="tDefine" 
	substitutionGroup="sgDefinition" 
    />

    <xsd:complexType name="tDefine">
	<xsd:sequence>

	    <!--
		description of the flow
	    -->
	    <xsd:element 
		name="description" 
		minOccurs="0" 
		maxOccurs="unbounded"
	    >
		<xsd:complexType>
		    <xsd:simpleContent>
			<xsd:extension base="xsd:string">
			    <xsd:attribute 
				name="language" 
				type="xsd:string" 
				default="default" 
			    />
			</xsd:extension>
		    </xsd:simpleContent>
		</xsd:complexType>
	    </xsd:element>

	    <!--
		subprocess definitions
		and
		filters

                (before)
	    -->

	    <xsd:element 
		ref="sgDefinition"
		minOccurs="0" 
		maxOccurs="unbounded" 
	    />

	    <!--
		body of the flow
	    -->
	    <xsd:element 
		ref="sgExpression" 
		maxOccurs="unbounded" 
	    />

	    <!--
		subprocess definitions
		and
		filters

                (after)
	    -->

	    <xsd:element 
		ref="sgDefinition"
		minOccurs="0" 
		maxOccurs="unbounded" 
	    />

	</xsd:sequence>

	<!--
	    attributes of 'process-definition'
	-->
	<xsd:attribute name="name" type="xsd:string" use="required"/>
	<xsd:attribute name="revision" type="xsd:string" />

	<xsd:attribute name="map-children" type="xsd:string" />
    </xsd:complexType>


    <!--
	filters
    -->
    <xsd:element 
	name="filter-definition" 
	substitutionGroup="sgDefinition"
    >
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    name="field"
		    minOccurs="0"
		    maxOccurs="unbounded"
		>
		    <xsd:complexType>
			<xsd:attribute 
			    name="regex" 
			    type="xsd:string" 
			    use="required"
			/>
			<xsd:attribute 
			    name="permissions" 
			    type="xsd:string" 
			    use="required"
			/>
		    </xsd:complexType>
		</xsd:element>
	    </xsd:sequence>
	    <xsd:attribute 
		name="name" type="xsd:string" use="required" 
	    />
	    <xsd:attribute 
		name="type" type="xsd:string" use="required" 
	    />
	    <xsd:attribute 
		name="add" type="xsd:boolean" use="required" 
	    />
	    <xsd:attribute 
		name="remove" type="xsd:boolean" use="required" 
	    />
	</xsd:complexType>
    </xsd:element>


    <!--

	EXPRESSIONS

    -->

    <xsd:element name="sequence" substitutionGroup="sgExpression" >
        <xsd:annotation>
            <xsd:documentation>
The 'sequence' expression defines a list of children expressions that have to be evaluated sequentially.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch06s02.html#expression_sequence
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="0" 
		    maxOccurs="unbounded" />
	    </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="interleaved" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="0" 
		    maxOccurs="unbounded" />
	    </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="concurrence" substitutionGroup="sgExpression" >
        <xsd:annotation>
            <xsd:documentation>
The children of this expression will be executed in parallel.
Concurrence has various attributes for determining how the synchronization at the end of the parallel executions has to happen.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch07s03.html
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="0" 
		    maxOccurs="unbounded"
                />
	    </xsd:sequence>

	    <xsd:attribute name="sync" type="xsd:string" />
	    <!--<xsd:attribute name="count" type="xsd:nonNegativeInteger" />-->
	    <xsd:attribute name="count" type="xsd:string" />
	    <xsd:attribute name="merge" type="syncMerge" />
	    <xsd:attribute name="merge-type" type="syncMergeType" />
	    <xsd:attribute name="remaining" type="syncRemaining" />

	</xsd:complexType>
    </xsd:element>

    <xsd:element name="iterator" substitutionGroup="sgExpression" >
        <xsd:annotation>
            <xsd:documentation>
An iterator takes care of executing its children one or more item. It's the equivalent of the 'for' loop in classical programmation.
'concurrent-iterator' will execute all its iterations concurrently whereas 'iterator' will execute them sequentially.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch07s14.html#pat_expression_iterator
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="0" 
		    maxOccurs="unbounded"
                />
	    </xsd:sequence>
	    <xsd:attribute name="on-value" type="xsd:string" />
	    <xsd:attribute name="on-field-value" type="xsd:string" />
	    <xsd:attribute name="on-variable-value" type="xsd:string" />
	    <xsd:attribute name="to-field" type="xsd:string" />
	    <xsd:attribute name="to-variable" type="xsd:string" />
	    <xsd:attribute name="valueSeparator" type="xsd:string" default=", *"/>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="concurrent-iterator" substitutionGroup="sgExpression" >
        <xsd:annotation>
            <xsd:documentation>
The 'concurrent-iterator' executes all of its iteration concurrently, it's like a concurrent 'for' loop.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch07s13.html
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="0" 
		    maxOccurs="unbounded" />
	    </xsd:sequence>
	    <xsd:attribute name="on-value" type="xsd:string" />
	    <xsd:attribute name="on-field-value" type="xsd:string" />
	    <xsd:attribute name="on-variable-value" type="xsd:string" />
	    <xsd:attribute name="to-field" type="xsd:string" />
	    <xsd:attribute name="to-variable" type="xsd:string" />
	    <xsd:attribute name="valueSeparator" type="xsd:string" default=", *"/>
	    <!-- also a sync for the concurrent-iterator -->
	    <xsd:attribute name="sync" type="xsd:string" />
	    <!--<xsd:attribute name="count" type="xsd:nonNegativeInteger" />-->
	    <xsd:attribute name="count" type="xsd:string" />
	    <xsd:attribute name="merge" type="syncMerge" />
	    <xsd:attribute name="merge-type" type="syncMergeType" />
	    <xsd:attribute name="remaining" type="syncRemaining" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="participant" substitutionGroup="sgExpression" >
        <xsd:annotation>
            <xsd:documentation>
A participant is anyone/anything taking part in a process. Participants are usually defined in the file etc/engine/participant-map.xml
The main attribute of a participant expression is 'ref' which refers to a participant name in the participant map.
Engines are participant too.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch06s02.html#expression_participant
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
	<xsd:complexType>
	    <xsd:attribute name="ref" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
An absolute reference to a participant (by its name in the participant map).
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	    <xsd:attribute name="field-ref" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
The name of the participant that will receive the workitem is the value of the given field.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	    <xsd:attribute name="variable-ref" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
The given variable should hold the name of the participant that will receive the workitem.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	    <xsd:attribute name="default-ref" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
If 'ref' isn't present and if neither 'field-ref' nor 'variable-ref' holds a value for the participant name, this attribute holds the 'default' participant name.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	    <xsd:attribute name="else-ref" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
A comma separated list of participant names that are tried one after the other until delivery succeeds to one of them. This list is tried only if other references yielded failed deliveries to their participant. This attribute helps define 'fail-over participants'.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>

	    <xsd:attribute name="filter" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
A filter determines which permissions are set on the fields of a workitem emitted to the participant. The attribute filter should contain the name of a filter defined by a 'filter-definition' expression.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	    <xsd:attribute name="timeout" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
As engines deliver workitem to participants, they lose control over the workitem. The participant may never reply. This attribute sets locally after how much time the engine shall consider the workitem as 'lost' and resume the flow.
If the timeout is set to '-1', 'no' or 'none', the engine will never consider the workitem as lost.
The flow will resume with a copy of the workitem as it was just before being sent to the participant.
The flow will not be considered as failed and 'else-ref' participants won't get triggered.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	    <xsd:attribute name="description" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
A small help attribute. Its value is set as the content of the field named '__description__' just before being sent to the engine. When the workitem comes back, the field is cleaned (removed).
This attribute is useful for setting task descriptions for the participant (could be useful for a human participant as well as for an 'automatic' participant).
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	    <xsd:attribute name="forget" type="xsd:boolean">
                <xsd:annotation>
                    <xsd:documentation>
If this attribute is present and set to 'true', the engine will resume the flow and 'forget' about having sent a workitem to the participant.
Can be useful for implementing advanced notification mechanisms.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="set" substitutionGroup="sgExpression" >
	<xsd:complexType mixed="true">

            <xsd:sequence>
                <xsd:element 
                    ref="sgExpression"
                    minOccurs="0"
                    maxOccurs="1"
                />
            </xsd:sequence>

	    <xsd:attribute name="field" type="xsd:string" />
	    <xsd:attribute name="variable" type="xsd:string" />
	    <xsd:attribute name="value" type="xsd:string" />
	    <xsd:attribute name="field-value" type="xsd:string" />
	    <xsd:attribute name="variable-value" type="xsd:string" />
	    <xsd:attribute name="function-value" type="xsd:string" />
	    <xsd:attribute name="override" type="xsd:boolean" default="true" />
	    <xsd:attribute name="type" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="unset" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:attribute name="field" type="xsd:string" />
	    <xsd:attribute name="variable" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="include" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:attribute name="url" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="sleep" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:attribute name="for" type="xsd:string" />
	    <xsd:attribute name="until" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="cancel-process" substitutionGroup="sgExpression" >
        <xsd:annotation>
            <xsd:documentation>
The 'cancel-process' expression will cancel the whole workflow instance upon being evaluated. Use it with care : it's explicit termination of a flow.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch06s09.html#expression_cancel_process
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
	<xsd:complexType/>
    </xsd:element>

    <xsd:element name="forget" substitutionGroup="sgExpression" >
        <xsd:annotation>
            <xsd:documentation>
The 'forget' expression simply applies its child expression (in a separate execution thread) and immediately replies. It may be seen as a way of forking an independent process branch.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch06s09.html#expression_forget
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
	<xsd:complexType>
            <xsd:sequence>
                <xsd:element
                    ref="sgExpression"
                    minOccurs="0"
                    maxOccurs="1"
                />
            </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="lose" substitutionGroup="sgExpression" >
        <xsd:annotation>
            <xsd:documentation>
'lose' will apply its child expression but will never reply, it may still get cancelled (whereas a 'forget' branch having immediately replied, cannot get cancelled).
'lose' makes sense within a concurrence to tag a branch as 'we don't care about its reply and we'll cancel it when the non-lost branch will have replied.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch06s09.html#expression_lose
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
	<xsd:complexType>
            <xsd:sequence>
                <xsd:element
                    ref="sgExpression"
                    minOccurs="0"
                    maxOccurs="1"
                />
            </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="rotate" substitutionGroup="sgExpression" >
        <xsd:annotation>
            <xsd:documentation>
The 'rotate' expression turns a vertical workitem field into an horizontal one and vice-versa. A typical horizontal workitem field is a list of strings stored with comma separators. The typical vertical workitem field is an instance of ListAttribute.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch06s09.html#expression_rotate
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
	<xsd:simpleType>
	    <xsd:attribute name="field" type="xsd:string" use="required">
                <xsd:annotation>
                    <xsd:documentation>
This attribute is mandatory, it points to the field whose value should get rotated. If the attribute 'to-field' is not present. The field named here will be the source and the target of the rotation operation.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	    <xsd:attribute name="to-field" type="xsd:string" >
                <xsd:annotation>
                    <xsd:documentation>
If this attribute is present, the rotation operation will store its result in the field named here.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	    <xsd:attribute name="trim" type="xsd:string" >
                <xsd:annotation>
                    <xsd:documentation>
If this field is set to 'yes' or 'true', the rotated strings will be trimmed.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	    <xsd:attribute name="separator" type="xsd:string" >
                <xsd:annotation>
                    <xsd:documentation>
The default separator is the comma ",". This attribute may be used to specify another one. Do not use a regular expression here.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	</xsd:simpleType>
    </xsd:element>

    <xsd:element name="save" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:attribute name="to-variable" type="xsd:string" use="required" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="restore" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:attribute name="from-variable" type="xsd:string" use="required" />
	    <xsd:attribute name="merge-lead" type="xsd:string" />
	    <xsd:attribute name="to-field" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="inc" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:attribute name="field" type="xsd:string" />
	    <xsd:attribute name="variable" type="xsd:string" />
	    <xsd:attribute name="value" type="xsd:string" />
	    <xsd:attribute name="field-value" type="xsd:string" />
	    <xsd:attribute name="variable-value" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="subprocess" substitutionGroup="sgExpression" >
	<xsd:complexType>

            <xsd:sequence>
                <xsd:element
                    ref="sgExpression"
                    minOccurs="0"
                    maxOccurs="unbounded"
                />
            </xsd:sequence>

	    <xsd:attribute name="ref" type="xsd:string" />
	    <xsd:attribute name="field-ref" type="xsd:string" />
	    <xsd:attribute name="variable-ref" type="xsd:string" />
	    <xsd:attribute name="forget" type="xsd:boolean" />

	</xsd:complexType>
    </xsd:element>

    <xsd:element name="if" substitutionGroup="sgExpression" >
	<xsd:complexType>
                <!-- if test is set, then there should be no conditional -->
	    <xsd:sequence>
		<!-- the conditional -->
		<xsd:element 
		    ref="sgConditional"
                    minOccurs="0"
                    maxOccurs="1"
		/>
		<!-- 'then' and perhaps 'else' -->
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="1" 
		    maxOccurs="2"
                />
	    </xsd:sequence>

	    <xsd:attribute name="test" type="xsd:string" />

	</xsd:complexType>
    </xsd:element>

    <xsd:element name="when" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:sequence>
		<!-- the conditional -->
		<xsd:element 
		    ref="sgConditional"
		/>
		<!-- 'then' and no 'else' -->
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="1" 
		    maxOccurs="1" />
	    </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="cron" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="1" 
		    maxOccurs="1" />
	    </xsd:sequence>
	    <xsd:attribute name="tab" type="xsd:string" use="required" />
	    <xsd:attribute name="level" type="cronLevelType" />
	    <xsd:attribute name="name" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

	<xsd:simpleType name="cronLevelType">
	    <xsd:restriction base="xsd:string">
		<xsd:enumeration value="" />
		<xsd:enumeration value="/" />
		<xsd:enumeration value="//" />
	    </xsd:restriction>
	</xsd:simpleType>

    <xsd:element name="log" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:attribute name="message" type="xsd:string" />
	    <xsd:attribute name="level" type="logLevelType" />
	    <xsd:attribute name="engine-level" type="xsd:boolean" />
	</xsd:complexType>
    </xsd:element>

	<xsd:simpleType name="logLevelType">
	    <xsd:restriction base="xsd:string">
		<xsd:enumeration value="debug" />
		<xsd:enumeration value="info" />
		<xsd:enumeration value="warn" />
	    </xsd:restriction>
	</xsd:simpleType>

    <xsd:element name="do" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="1" 
		    maxOccurs="1" />
	    </xsd:sequence>
	    <xsd:attribute name="name" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="undo" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:attribute name="ref" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="redo" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:attribute name="ref" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <!--
    <xsd:element name="break" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:attribute name="ref" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>
    -->

    <xsd:element name="print" substitutionGroup="sgExpression" >
	<xsd:complexType mixed="true">
	    <xsd:sequence>
		<xsd:element 
                    ref="sgExpression"
                    minOccurs="0"
                    maxOccurs="unbounded"
                />
	    </xsd:sequence>
	    <xsd:attribute name="text" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>


    <!--
	cursor, loop and the 'cursor commands'
    -->

    <xsd:element name="cursor" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="0" 
		    maxOccurs="unbounded" />
	    </xsd:sequence>

	    <xsd:attribute name="disallow" type="xsd:string" />
                <!-- 
                    contains a comma-separated list of cursor commands 
                    disallowed.
                    possible values set : "back, rewind, break"
                -->

	</xsd:complexType>
    </xsd:element>

    <!--
    <xsd:simpleType name="cursorDisallowType">
	<xsd:restriction base="xsd:string">
	    <xsd:enumeration value="back" />
	    <xsd:enumeration value="rewind" />
	    <xsd:enumeration value="continue" />
	    <xsd:enumeration value="break" />
	    <xsd:enumeration value="cancel" />
	</xsd:restriction>
    </xsd:simpleType>
    -->

    <xsd:element name="loop" substitutionGroup="sgExpression" >
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgExpression" 
		    minOccurs="0" 
		    maxOccurs="unbounded" />
	    </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="while" substitutionGroup="sgExpression">
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element ref="sgConditional" />
	    </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="until" substitutionGroup="sgExpression">
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element ref="sgConditional" />
	    </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="break" substitutionGroup="sgExpression">
	<xsd:complexType />
    </xsd:element>
    <xsd:element name="cancel" substitutionGroup="sgExpression">
	<xsd:complexType />
    </xsd:element>

    <xsd:element name="rewind" substitutionGroup="sgExpression">
	<xsd:complexType />
    </xsd:element>
    <xsd:element name="continue" substitutionGroup="sgExpression">
	<xsd:complexType />
    </xsd:element>

    <xsd:element name="back" substitutionGroup="sgExpression">
	<xsd:complexType />
    </xsd:element>


    <!--
	conditionals
    -->

    <xsd:element name="not" substitutionGroup="sgConditional">
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element ref="sgConditional" />
	    </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="and" substitutionGroup="sgConditional">
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgConditional" 
		    minOccurs="1"
		    maxOccurs="unbounded"
		/>
	    </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="or" substitutionGroup="sgConditional">
	<xsd:complexType>
	    <xsd:sequence>
		<xsd:element 
		    ref="sgConditional" 
		    minOccurs="1"
		    maxOccurs="unbounded"
		/>
	    </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="equals" substitutionGroup="sgConditional" >
	<xsd:complexType>
	    <xsd:attribute name="value" type="xsd:string" />
	    <xsd:attribute name="field-value" type="xsd:string" />
	    <xsd:attribute name="variable-value" type="xsd:string" />
	    <xsd:attribute name="other-value" type="xsd:string" />
	    <xsd:attribute name="other-field-value" type="xsd:string" />
	    <xsd:attribute name="other-variable-value" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="greater-than" substitutionGroup="sgConditional" >
	<xsd:complexType>
	    <xsd:attribute name="value" type="xsd:string" />
	    <xsd:attribute name="field-value" type="xsd:string" />
	    <xsd:attribute name="variable-value" type="xsd:string" />
	    <xsd:attribute name="other-value" type="xsd:string" />
	    <xsd:attribute name="other-field-value" type="xsd:string" />
	    <xsd:attribute name="other-variable-value" type="xsd:string" />
	    <xsd:attribute name="equals" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="lesser-than" substitutionGroup="sgConditional" >
	<xsd:complexType>
	    <xsd:attribute name="value" type="xsd:string" />
	    <xsd:attribute name="field-value" type="xsd:string" />
	    <xsd:attribute name="variable-value" type="xsd:string" />
	    <xsd:attribute name="other-value" type="xsd:string" />
	    <xsd:attribute name="other-field-value" type="xsd:string" />
	    <xsd:attribute name="other-variable-value" type="xsd:string" />
	    <xsd:attribute name="equals" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="undefined" substitutionGroup="sgConditional" >
	<xsd:complexType>
	    <xsd:attribute name="value" type="xsd:string" />
	    <xsd:attribute name="field-value" type="xsd:string" />
	    <xsd:attribute name="variable-value" type="xsd:string" />
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="eval" substitutionGroup="sgExpression" >
        <xsd:annotation>
            <xsd:documentation>
The 'eval' expression may extract OpenWFE 'code' from a workitem field (see the 'field' attribute) or from a nested OpenWFE constuct and evaluate it on the fly.
            </xsd:documentation>
            <xsd:appinfo>
                <openwfe:documentationLink>
http://www.openwfe.org/docbook/build/ch06s09.html#expression_eval
                </openwfe:documentationLink>
            </xsd:appinfo>
        </xsd:annotation>
	<xsd:complexType mixed="true">
            <xsd:sequence>
                <xsd:any 
                    processContents="skip"
                    minOccurs="0" 
                    maxOccurs="unbounded" 
                />
            </xsd:sequence>
	    <xsd:attribute name="field" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
When the field attribute is set, the 'eval' expression will read the code to evaluate from the field named here. Any nested content will be ignored.
                    </xsd:documentation>
                </xsd:annotation>
	    </xsd:attribute>
	</xsd:complexType>
    </xsd:element>


    <!--
	sync stuff
    -->

    <!--
    <xsd:simpleType name="syncExpressionType">
	<xsd:restriction base="xsd:string">
	    <xsd:enumeration value="first-wins" />
	    <xsd:enumeration value="last-wins" />
	    <xsd:enumeration value="highest-wins" />
	    <xsd:enumeration value="first-merge" />
	    <xsd:enumeration value="last-merge" />
	    <xsd:enumeration value="deferred-choice" />
	</xsd:restriction>
    </xsd:simpleType>
    -->

    <xsd:simpleType name="syncMerge">
	<xsd:restriction base="xsd:string">
	    <xsd:enumeration value="first" />
	    <xsd:enumeration value="last" />
	    <xsd:enumeration value="highest" />
	    <xsd:enumeration value="lowest" />
	</xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="syncMergeType">
	<xsd:restriction base="xsd:string">
	    <xsd:enumeration value="mix" />
	    <xsd:enumeration value="override" />
	</xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="syncRemaining">
	<xsd:restriction base="xsd:string">
	    <xsd:enumeration value="cancel" />
	    <xsd:enumeration value="forget" />
	</xsd:restriction>
    </xsd:simpleType>


    <!--
        xeme (pool) expressions
    -->

    <xsd:element name="a" substitutionGroup="sgExpression" >
	<xsd:complexType>
            <xsd:sequence>
                <xsd:element 
                    ref="sgWorkitemAttribute" 
                    minOccurs="0"
                    maxOccurs="1"
                />
            </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="v" type="xsd:string" substitutionGroup="sgExpression" />
    <xsd:element name="variable" type="xsd:string" substitutionGroup="sgExpression" />

    <xsd:element name="f" type="xsd:string" substitutionGroup="sgExpression" />
    <xsd:element name="field" type="xsd:string" substitutionGroup="sgExpression" />

    <xsd:element name="q" substitutionGroup="sgExpression" >
	<xsd:complexType mixed="true">
            <xsd:sequence>
                <xsd:any 
                    processContents="skip"
                    minOccurs="0" 
                    maxOccurs="unbounded" 
                />
            </xsd:sequence>
	</xsd:complexType>
    </xsd:element>
    <xsd:element name="quote" substitutionGroup="sgExpression" >
	<xsd:complexType mixed="true">
            <xsd:sequence>
                <xsd:any 
                    processContents="skip"
                    minOccurs="0" 
                    maxOccurs="unbounded" 
                />
            </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="car" substitutionGroup="sgExpression" />
    <xsd:element name="cdr" substitutionGroup="sgExpression" />
    <xsd:element name="cons" substitutionGroup="sgExpression" />
    <xsd:element name="xar" substitutionGroup="sgExpression" />
    <xsd:element name="xdr" substitutionGroup="sgExpression" />
    <xsd:element name="xons" substitutionGroup="sgExpression" />

    <!--
    <xsd:element name="list" substitutionGroup="sgExpression" />
    -->

    <xsd:element name="is-null" substitutionGroup="sgExpression" />
    <xsd:element name="is-list" substitutionGroup="sgExpression" />
    <xsd:element name="is-atom" substitutionGroup="sgExpression" />
    <xsd:element name="is-empty" substitutionGroup="sgExpression" />


    <!--
        workitem fragments (for the 'set' expression)

        provided by Romina Torres
    -->

    <xsd:element 
        name="string" 
        type="xsd:string" 
        substitutionGroup="sgWorkitemAttribute" 
    />
    
    <xsd:element 
        name="integer" 
        type="xsd:integer" 
        substitutionGroup="sgWorkitemAttribute" 
    />

    <xsd:element 
        name="long" 
        type="xsd:long" 
        substitutionGroup="sgWorkitemAttribute" 
    />

    <xsd:element 
        name="boolean" 
        type="xsd:boolean" 
        substitutionGroup="sgWorkitemAttribute" 
    />

    <xsd:element 
        name="double" 
        type="xsd:double" 
        substitutionGroup="sgWorkitemAttribute" 
    />

    <xsd:element name="raw-xml" substitutionGroup="sgWorkitemAttribute" >
	<xsd:complexType mixed="true">
            <xsd:sequence>
                <xsd:any 
                    processContents="skip"
                    minOccurs="0" 
                    maxOccurs="unbounded" 
                />
            </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="list" substitutionGroup="sgWorkitemAttribute" >
	<xsd:complexType>
            <xsd:sequence>
                <xsd:element 
                    ref="sgWorkitemAttribute" 
                    minOccurs="0"
                    maxOccurs="unbounded"
                />
            </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="map" substitutionGroup="sgWorkitemAttribute">
	<xsd:complexType>
            <xsd:sequence>
                <xsd:element 
                    name="entry"
                    type="mapEntryType"
                    minOccurs="0" 
                    maxOccurs="unbounded" 
                />
            </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:element name="smap" substitutionGroup="sgWorkitemAttribute">
	<xsd:complexType>
            <xsd:sequence>
                <xsd:element 
                    name="entry"
                    type="smapEntryType"
                    minOccurs="0" 
                    maxOccurs="unbounded" 
                />
            </xsd:sequence>
	</xsd:complexType>
    </xsd:element>

    <xsd:complexType name="mapEntryType">
        <xsd:sequence>
	    <xsd:element 
		ref="sgWorkitemAttribute"
		minOccurs="1" 
		maxOccurs="1" 
	    />
	    <xsd:element 
		ref="sgWorkitemAttribute"
		minOccurs="1" 
		maxOccurs="1" 
	    />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="smapEntryType">
        <xsd:sequence>
	    <xsd:element 
		name="string"
                type="xsd:string"
		minOccurs="1" 
		maxOccurs="1" 
	    />
	    <xsd:element 
		ref="sgWorkitemAttribute"
		minOccurs="1" 
		maxOccurs="1" 
	    />
        </xsd:sequence>
    </xsd:complexType>

</xsd:schema>
