XQuery Mediator

The XQuery mediator can be used to perform an XQuery transformation. The 'key' attribute specifies the registry key for looking up XQuery script that going to be used for define transformation. The optional 'target' attribute specifies the node of the SOAP message that should be transformed. In case 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, or even specify a registry key or a registry key combined with an XPath expression that selects the value of the variable.Using 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).

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

Syntax

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

UI Configuration

Figure1: XQuery Mediator

  • Key: The key that represent the xquery transformation.
  • Target: (optional) Specify the node of the message that should be transformed using an xpath expression. ( default to the first child of the SOAP body ) The namespace prefixes used in the expression can be defined by clicking the namespaces link in front of the 'Target' input field.

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.

Figure2: XQuery Mediator - Adding Variables

You have the following option in a variable.
  • Variable Type: The 'type' of the variable must be a valid type defined by the JSR-000225 (XQJ API).

    The supported types are defined in the Supported Types section

  • Variable Name: The name of the variable should correspond to the name of variable declaration in the XQuery script.
  • Value Type: Whether the value of the variable is a static value or an expession.
  • Value/Expression: Static value or the expression.
  • Registry Key: Key, if the value is retrieved from the registry.
  • NSEditor: Defines the namespaces for the prefixes used in the xpath query.
  • Action: Delete the variable.

Examples

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

    In the above configuration, XQuery script is in the registry and that script can be picked by key xquery\example.xq. There is a one variable name payload and type as ELEMENT. As there is no expression in the variable definitions, default value - the first child of SOAP Body is used as the value of variable payload. . Within XQuery script, you can access this variable by defining declare variable $payload as document-node() external; . Refer sample 390 and 391 for more information.

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

    A variable definitions that pick a XML resource from the registry using key misc/commission.xml and bind in to XQuery Runtime so that it can be accessed with in XQuery script. Refer sample 391 for more information.

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

    A variable whose value is calculated from current message SOAP Payload using an expression. Here , value is a type of double.