Tuesday, May 19, 2015

Although XPATH 2.0 is supported in WSO2 ESB, it is not enabled by default. In order to use this you have to enable XPATH 2.0.

To enable XPath 2.0 functions, we have to uncomment following entry in the synapse.properties file. which is located at <ESB_HOME>/repository/conf directory


After enabling xpath 2.0, you will able to use xpath functions like "codepoint-equal()" in your synapse configuration.

If you are using synapse specific xpath functions like "get-property()" within a xpath 2.0 function you have to use them with the prefix "syn".

Following is an example for a such usage.

So in my case lets say I'm getting a request header like following

{org.apache.synapse.transport.http.wire} -  >> "Content-Type: application/xml; charset=UTF-8" {org.apache.synapse.transport.http.wire}

I want to extract the "application/xml" value from the "application/xml; charset=UTF-8". I can use the following expression to do this, Note that I'm tokenizing the mentioned value, extracting the relevent text and assigning it to a new property which can be referred later.

<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:fn="http://www.w3.org/2005/xpath-functions" name="NEW_CONTENT_TYPE" expression="fn:tokenize(syn:get-property('axis2','ContentType'),';')[1]" scope="default" type="STRING"/>

Thanks for reading and drop a comment if you have any queries.


1 comment:

  1. I have enabled xpath 2.0 from synapse prop file as mentioned above and trying to use tokenize fn in my proxy service.
    Still I get the below error and property where I used tokenize
    fn:tokenize(//xpath for the node, 'value ')


    SynapseXPath Evaluation of the XPath expression fn:tokenize(//SOAP-ENV:Envelope/SOAP-ENV:Body/m:subscribe/m:subscribe/m1:filter/m1:messageContent, ' and ') resulted in an error
    org.jaxen.UnresolvableException: No Such Function {http://www.w3.org/2005/xpath-functions}:tokenize


Subscribe to RSS Feed Follow me on Twitter!