0

In my inSequence of a proxy I'm filtering with a xpath query in the filter mediator. But I want to use XPath functions like exists() or count(). But this does not work and always creates an exception. Here my example:

<filter xpath="count($body/myElement)>2">
 <drop/>
</filter>

And the exception I always get:

ERROR - FilterMediator Error evaluating XPath expression : n:exists($body/avintis:Exception)
        org.jaxen.UnresolvableException: No Such Function exists

How can I make these functions work?

Community
  • 1
  • 1
Philipp
  • 4,645
  • 3
  • 47
  • 80

2 Answers2

2

You can use xpath functions with filter mediator as modifying your synapse segment as shown below.

<filter xpath="fn:exists($body/myElement)">
 <drop/>
</filter>

You can refer for Sample 156: Service Integration with specifying the receiving sequence available at [1] for further sample.

 <filter xpath="fn:number(get-property('SIMPLE_SER_AMT')) > fn:number(get-property('SECURE_SER_AMT'))">

[1]. http://wso2.org/project/esb/java/4.0.3/docs/samples/proxy_samples.html

Thank You, Dharshana

Dharshana
  • 1,212
  • 1
  • 9
  • 18
  • This just solves the exists() function - but how do I make a count() in the xpath - this functio won't work either... – Philipp Feb 21 '13 at 11:55
  • And fn:number does not work! I get the same exception as for count() or exists(). – Philipp Feb 21 '13 at 12:01
  • I tested sample 156 it works fine with number() function please post your synapse to see where gone wrong – Dharshana Feb 21 '13 at 13:21
0

For those wondering how to use fn:count, you could try:

<property name="itemCount" expression="fn:count(//*[local-name()='item'])"/>
<filter xpath="fn:number(get-property('itemCount')) > fn:number(0)">

This works for me.

Erno Marks
  • 91
  • 1
  • 5
  • 1
    Your're absolutely correct. I found out that the xpath="" in inside the does not support many functions. Since I had may first problems, I now do the whole logic inside the property expression. So you could even do the number() inside the property. – Philipp Jan 16 '14 at 16:53