This documentation is for WSO2 Enterprise Service Bus version 4.7.0 . View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

The XQuery Mediator can be used to perform 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).


<xquery key="string" [target="xpath"]>
    <variable name="string" type="string" [key="string"] [expression="xpath"] [value="string"]/>?

UI Configuration

  • Key Type - Specifies either Static or Dynamic Key type.
  • Key - The key that represents the XQuery transformation. It can be chosen either from the Configuration Registry or Governance Registry. For more information on the registry, see Working with the Registry.
  • Target -Specifies the node of the message that should be transformed using an XPath expression.


    Default to the first child of the SOAP body.


    You can click the Namespaces link to add namespaces if you are providing an expression. You will be provided another panel named "Namespace Editor," where you can provide any number of namespace prefixes and URL that you have 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
    • 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.


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



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

In the above configuration, XQuery script is in the registry and that script can be picked by key xquery\example.xq. There is one variable name payload and type as ELEMENT. 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 declare variable $payload as document-node() external;.


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

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


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

A variable that value is calculated from the current message SOAP Payload using an expression. The value is of type"double" in this case.

  • No labels