What is greex syntax?

Using the Greex syntax you can create advanced XML conditions or Greex rules. An advanced XML condition is used to evaluate certain conditions on the input data. The Greex syntax is an XML based. This style of condition evaluation enables you to use the input data in multiple ways, rather than just a Boolean output.

The Greex syntax provides Greex constructs that are capable of being nested using multiple IF, and ELSE blocks, and also allows to group expressions using an AND or OR operator. Each expression comprises one or more function calls. You can include functions in a nested loop, which means parameters to functions can be other function calls. These contain basic IF ELSE conditions. The following table describes various elements of an If/Else construct.

Element

Description

Condition

The Condition element provides a logical grouping of all expressions that need to be evaluated by operating on an input XML.

Return

Every condition defined under the If/Else construct must return a value. A condition can return an XML element, string, or boolean value. It returns the appropriate value for an If/Else condition in the Return element. For example,
  • If you want to return an XML document, the Return element can be:
     <Return>
        <Value output="&lt;Order
               type=&quot;Web&quot;
               discount=&quot;5&quot;/&gt;"/>
     </Return>
  • If you want to return a string, the Return element can be:
    <Return>
       <Value output="Draft Order Created"/>
    </Return>
  • If you want to return a Boolean value, the Return element can be:
    <Return>
        <Value output="true"/>
    </Return>
  • If you want to return an PureXML element as a result of the evaluation, the Return element can be:
    <Return>
             <Value output="&lt;Date"/>
    </Return>
    The output of the above will be:
    <Date/>

The Condition element contains various Expression elements. Each Expression element defines the expression that you want to evaluate for the specified condition. The following table describes the various elements of a condition:

Element

Description

Expression

The Expression element contains the expressions that you want to evaluate for a condition to satisfy. To make function calls in the expression, prefix the function name with "fn:". For example, define the following Expression element which makes a function call:

<Expression>fn:equals(@ZipCode,"01876")</Expression>

You can also pass functions as parameters to other functions. For example, you can define the following Expression element to pass functions as parameters to other functions:

<Expression>fn:intGreater
(fn:count(OrderLines/OrderLine), "100")</Expression>

Group

This is an optional element. If you want to evaluate a set of expressions together, you must group the set of expressions together.

The Group element's "op" attribute indicates the operation you want to perform on the set of expressions. The valid values are: "or" and "and". You can define more than one expression in a Group element. If the Group element's op value is "and", then the condition satisfies only if ALL expressions that are part of the Group element evaluates to "true". Likewise, if the Group element's "op" attribute is "or", then the condition satisfies only if ONE of the expressions that are part of the Group element evaluates to "true".

You can create any level of nested Group and Expression elements.

Note: If you want to evaluate a single expression, define a single Expression element under the Condition element, without creating the Group element.

A sample IF ELSE construct for defining an advanced XML condition or Greex rule can be:
<If>    
  <Condition name="isWebOrder?">
    <Group op="and">
      <Expression>fn:!equals(@orderType,"WEB")</Expression>
      <Expression>fn:equals(address::@ZipCode, "01876")</Expression>
    </Group>
  </Condition>
  <Return>
     <Value output="&lt;Order type=&quot;Web&quot; 
            discount=&quot;5&quot;/&gt;"/>
  </Return>
</If>
  <Else>
    <Return>
       <Value output="&lt;Order type=&quot;Catalog&quot; 
              discount=&quot;2&quot;/&gt;"/>
     </Return>
  </Else>