Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Did required changes as specified in DOCUMENTATION-2473

The XQuery Mediator can be used to perform  performs an XQuery transformation . The key attribute specifies the registry key for looking up the XQuery script that can be used to define transformation. The optional target attribute specifies the node of the SOAP message that should be transformed. In cases where the target value is not specified, then the first child of the SOAP body is selected. The variable elements define a variable that could be bound to the dynamic context of the XQuery engine in order to access those variables during the XQuery script invocation.

In the variable definition, it is possible to specify just a "literal" value or an XPath expression over the payload. It is possible to even specify a registry key or a registry key combined with an XPath expression that selects the value of the variable. By using the key attribute of the variable, it is possible to bind an XML document located in the registry so that in the transformation, that too can be used. The name of the variable corresponds to the name of variable declaration in the XQuery script. The type of the variable must be a valid type defined by the JSR-000225 (XQJ API).

on messages. 

Info

The XQuery mediator is a content aware mediator.

...

Parameter NameDescription
Key Type

This parameter specifies whether the key which represents the XQuery transformation should be a static key or a dynamic key.

  • Static: If this is selected, the key would be a static value. This value should be selected from the Registry for the Key parameter.
  • Dynamic: If this is selected, the key would be a dynamic value which has to be evaluated via an XPath expression. The relevant XPath expression can be entered in the Key parameter.
Key

The key that represents the XQuery transformation. The value you enter depends on the value you selected for the Key Type parameter. If you selected Static for the Key Type parameter, click Configuration Registry or Governance Registry as relevant to select the key from the resource tree. If you selected Dynamic for the Key Type parameter, enter the XPatch expression which calculates the dynamic key.

 

Tip

You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. 


Target

This parameter specifies the node of the message to which the XQuery transformation should be applied. The node is evaluated via an XPath expression. If no value is specified for this parameter, the XQuery transformation is applied to the first child of the SOAP body.

Tip

You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. 

Add Variable

This link allows you to define one or more variables that could be bound to the dynamic context of the XQuery engine in order to be accessed during the XQuery script invocation.

Click Add Variable to add a variable to the XQuery mediator configuration. The page will expand to display parameters relating to variables. The parameters displayed would differ depending on whether you select Value or Expression as the variable value type. Click on the relevant tab below to view the relevant UI configuration for variables.

Localtabgroup
Localtab
titleValue

Parameter NameDescription
Variable TypeThe data type of the variable. This should be be a valid type defined by the JSR-000225 (XQJ API). Supported values are as follows.
  • INT
  • INTEGER
  • BOOLEAN
  • BYTE
  • DOUBLE
  • SHORT
  • LONG
  • FLOAT
  • STRING
  • DOCUMENT
  • DOCUMENT_ELEMENT
  • ELEMENT
Variable NameThe name of the variable. It should correspond to the name of the variable declaration in the XQuery script.
Value Type

This parameter specifies whether the variable value should be a static value or a dynamic value

  • Value: If this is selected, the variable value is a static value. The static value should be entered in the Value/Experession parameter.
  • Expression: If this is selected the variable value is a dynamic value. The XPath expression to calculate it should be entered in the Value/Experession parameter.
Value/ExpressionThis parameter is used to enter the variable value. This can be a static value or an expression based on the value you selected for the Value Type parameter.
ActionThis parameter allows the variable to be deleted.
Localtab
titleExpression

Parameter NameDescription
Variable TypeThe data type of the variable. This should be be a valid type defined by the JSR-000225 (XQJ API). Supported values are as follows.
  • INT
  • INTEGER
  • BOOLEAN
  • BYTE
  • DOUBLE
  • SHORT
  • LONG
  • FLOAT
  • STRINGDOCUMENT
  • DOCUMENT_ELEMENT
  • ELEMENT
Variable NameThe name of the variable. It should correspond to the name of the variable declaration in the XQuery script.
Value Type

This parameter specifies whether the variable value should be a static value or a dynamic value

  • Value: If this is selected, the variable value is a static value. The static value should be entered in the Value/Experession parameter.
  • Expression: If this is selected the variable value is a dynamic value. The XPath expression to calculate it should be entered in the Value/Experession parameter.
Value/ExpressionThis parameter is used to enter the variable value. This can be a static value or an expression based on the value you selected for the Value Type parameter.
Registry KeyThe key to acces the variable value if it is
Registry Browser 
NS Editor 
ActionThis parameter allows the variable to be deleted.

 

...

Target -Specifies the node of the message that should be transformed using an XPath expression.

Info
titleTip

Default to the first child of the SOAP body.

...

titleTip

...

saved in the Registry. Click either Configuration Registry or Governance Registry in the Registry Browser parameter as relevant to select the required key from the resource tree.
Registry BrowserIf the variable value is saved in the Registry, click either Configuration Registry or Governance Registry in the Registry Browser parameter as relevant to select the required key from the resource tree.
NS EditorYou can click NameSpaces to add namespaces if you are providing an expression.

...

Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and

...

URLs used in the XPath expression.

...

  • Variables for the XQuery Mediator- Defines values/expressions that could be bound to the dynamic context of the XQuery engine in order to access those variables through the XQuery script.
    • Variable Type -The "type" of the variable must be a valid type defined by the JSR-000225 (XQJ API). Supported Types:
      • XQItemType.XQBASETYPE_INT -> INT
      • XQItemType.XQBASETYPE_INTEGER -> INTEGER
      • XQItemType.XQBASETYPE_BOOLEAN -> BOOLEAN
      • XQItemType.XQBASETYPE_BYTE - > BYTE
      • XQItemType.XQBASETYPE_DOUBLE -> DOUBLE
      • XQItemType.XQBASETYPE_SHORT -> SHORT
      • XQItemType.XQBASETYPE_LONG -> LONG
      • XQItemType.XQBASETYPE_FLOAT -> FLOAT
      • XQItemType.XQBASETYPE_STRING -> STRING
      • XQItemType.XQITEMKIND_DOCUMENT -> DOCUMENT
      • XQItemType.XQITEMKIND_DOCUMENT_ELEMENT -> DOCUMENT_ELEMENT
      • XQItemType.XQITEMKIND_ELEMENT -> ELEMENT
    • Variable Name - The name of the variable. It should correspond to the name of the variable declaration in the XQuery script.
    • Value Type - Whether the value of the variable is a static value or an expression.
    • Value / Expression - Static value or the expression.
    • Action - Deletes the variable.
 
ActionThis parameter allows the variable to be deleted.
Info
titleNote

You can configure the Mediator mediator using XML. Click on "switch to source view " in the "Mediator" window.

...

Examples

1.

...

...

<xquery key="xquery\example.xq">
      <variable name="payload" type="ELEMENT"/>
</xquery>

In the above configuration, In this configuration, the XQuery script is saved in the registry, and that script it can be picked by key accessed via the xquery\example.xq. There is key. The XQuery configuration has one variable name payload and type as named payload of which the variable type is ELEMENT. As   As there is no expression in the variable definitions, the default value of the first child of the SOAP Body is used as the value of the variable payload. Within the XQuery script, you can access this variable by defining defining declare variable $payload as document-node() external;.

2.

Code Block
XML
XML
<xquery key="xquery\example.xq">
      <variable name="commissionpayload" type="ELEMENT" key="misc/commission.xml"></variable>

...

/>
</xquery>

Variables

The following variable picks an XML resource from the registry using key key misc/commission.xml and  and binds into XQuery Runtime so that it can be accessed within the XQuery script.3

Code Block
XML
XML
<variable name="commission" type="ELEMENT" key="misc/commission.xml"></variable>


The value of the following variable is calculated from the current message SOAP Payload using an expression. The value type of the variable is DOUBLE.

Code Block
XML
XML
<variable name="price" type="DOUBLE" expression="self::node()//m0:return/m0:last/child::text()" xmlns:m0="http://services.samples/xsd"/>

...

Excerpt
hiddentrue

Description of the XQuery Mediator in WSO2 ESB.