Passing values to the Xpath 2.0 function - fn:avg

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing values to the Xpath 2.0 function - fn:avg

sohani
Hi All,

I am validating the Xpath 2.0 functions support in ESB ( please refer [1]) and I am using below configuration in defining 'avg' function (Referred [2]), but it seems I am using the wrong syntax. 

                      xmlns:test="http://test"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:avg((3,4,5))"/>

Can someone please point the correct syntax?

Since avg function requires a single parameter, is there a way to define the integer values externally ( may be using a property mediator ) and use it inside the function ?

If this syntax is correct, is this function not supported in ESB?

Really appreciate your input on this

FYI: When saving the proxy, I'm getting below exception:

[2016-08-01 11:41:11,718] ERROR - ProxyServiceAdmin Unable to save changes made for the proxy service : testProxy. Restored the existing proxy... :: Invalid XPapth expression : fn:avg((3,4,5))
org.apache.synapse.SynapseException: Invalid XPapth expression : fn:avg((3,4,5))
at org.apache.synapse.config.xml.MediatorPropertyFactory.getMediatorProperties(MediatorPropertyFactory.java:106)
at org.apache.synapse.config.xml.LogMediatorFactory.createSpecificMediator(LogMediatorFactory.java:111)
.......



[1] Xpath 2.0.0 functions supported by ESB
[2] https://www.w3.org/TR/xpath-functions/#func-avg
Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : +94 716439774

_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Passing values to the Xpath 2.0 function - fn:avg

sohani
Hi All,

It seems, the " Invalid XPapth expression" comes when we use two brackets in the function as below

fn:codepoints-to-string((2309, 2358, 2378, 2325))
fn:string-join(('a', 'c'), 'bbb')






Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : +94 716439774

On Mon, Aug 1, 2016 at 12:06 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

I am validating the Xpath 2.0 functions support in ESB ( please refer [1]) and I am using below configuration in defining 'avg' function (Referred [2]), but it seems I am using the wrong syntax. 

                      xmlns:test="http://test"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:avg((3,4,5))"/>

Can someone please point the correct syntax?

Since avg function requires a single parameter, is there a way to define the integer values externally ( may be using a property mediator ) and use it inside the function ?

If this syntax is correct, is this function not supported in ESB?

Really appreciate your input on this

FYI: When saving the proxy, I'm getting below exception:

[2016-08-01 11:41:11,718] ERROR - ProxyServiceAdmin Unable to save changes made for the proxy service : testProxy. Restored the existing proxy... :: Invalid XPapth expression : fn:avg((3,4,5))
org.apache.synapse.SynapseException: Invalid XPapth expression : fn:avg((3,4,5))
at org.apache.synapse.config.xml.MediatorPropertyFactory.getMediatorProperties(MediatorPropertyFactory.java:106)
at org.apache.synapse.config.xml.LogMediatorFactory.createSpecificMediator(LogMediatorFactory.java:111)
.......



[1] Xpath 2.0.0 functions supported by ESB
[2] https://www.w3.org/TR/xpath-functions/#func-avg
Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774


_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Passing values to the Xpath 2.0 function - fn:avg

sohani



Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : +94 716439774

On Mon, Aug 1, 2016 at 1:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

It seems, the " Invalid XPapth expression" comes when we use two brackets in the function as below


While I was testing further I found that below function works perfectly even it has two brackets, so that means the syntax of the above mentioned functions are correct. 

So, are these functions not supported in ESB? Appreciate your input on this

fn:dateTime(xs:date('2006-08-15'), xs:time('12:30:45-05:00')) 


fn:codepoints-to-string((2309, 2358, 2378, 2325))
fn:string-join(('a', 'c'), 'bbb')






Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 12:06 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

I am validating the Xpath 2.0 functions support in ESB ( please refer [1]) and I am using below configuration in defining 'avg' function (Referred [2]), but it seems I am using the wrong syntax. 

                      xmlns:test="http://test"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:avg((3,4,5))"/>

Can someone please point the correct syntax?

Since avg function requires a single parameter, is there a way to define the integer values externally ( may be using a property mediator ) and use it inside the function ?

If this syntax is correct, is this function not supported in ESB?

Really appreciate your input on this

FYI: When saving the proxy, I'm getting below exception:

[2016-08-01 11:41:11,718] ERROR - ProxyServiceAdmin Unable to save changes made for the proxy service : testProxy. Restored the existing proxy... :: Invalid XPapth expression : fn:avg((3,4,5))
org.apache.synapse.SynapseException: Invalid XPapth expression : fn:avg((3,4,5))
at org.apache.synapse.config.xml.MediatorPropertyFactory.getMediatorProperties(MediatorPropertyFactory.java:106)
at org.apache.synapse.config.xml.LogMediatorFactory.createSpecificMediator(LogMediatorFactory.java:111)
.......



[1] Xpath 2.0.0 functions supported by ESB
[2] https://www.w3.org/TR/xpath-functions/#func-avg
Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774



_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Passing values to the Xpath 2.0 function - fn:avg

sohani
According to [1] if I test the distinct-values function,it behaves as explained below:


1. If I use a rest mock service to get the response and then get the distinct values :

Rest mock service response:

<catalog xml:base="http://example.org/ACC/"> <product dept="WMN"> <number>557</number> <number>44</number>
<number>44</number> </product> </catalog>

Rest API:

<api xmlns="http://ws.apache.org/ns/synapse" name="sample123" context="/test123"> <resource methods="POST GET"> <inSequence> <send> <endpoint> <address uri="http://localhost:8080/getResult"/> </endpoint> </send> </inSequence> <outSequence> <log level="custom"> <property xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns="http://org.apache.synapse/xsd" xmlns:base="http://test" name="testValue" expression="fn:distinct-values(//product/*)"/>
</log> </outSequence> </resource> </api>


Then expected result is : 557, 44

But I am getting only 557

Am I missing something here?

2. If I directly use this function as below

       name="testProxy"
       transports="http https"
       startOnLoad="true">
   <description/>
   <target>
      <inSequence>
         <log level="custom">
            <property xmlns:fn="http://www.w3.org/2005/xpath-functions"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:distinct-values(('a', 'b', 'a'))"/>
         </log>
      </inSequence>
      <outSequence/>
   </target>
</proxy>

Then I'm getting the exception "invalid XPapth expression" in saving the proxy

But according to [1] it seems both ways are correct



Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : +94 716439774

On Mon, Aug 1, 2016 at 3:54 PM, Sohani Weerasinghe <[hidden email]> wrote:



Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 1:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

It seems, the " Invalid XPapth expression" comes when we use two brackets in the function as below


While I was testing further I found that below function works perfectly even it has two brackets, so that means the syntax of the above mentioned functions are correct. 

So, are these functions not supported in ESB? Appreciate your input on this

fn:dateTime(xs:date('2006-08-15'), xs:time('12:30:45-05:00')) 


fn:codepoints-to-string((2309, 2358, 2378, 2325))
fn:string-join(('a', 'c'), 'bbb')






Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 12:06 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

I am validating the Xpath 2.0 functions support in ESB ( please refer [1]) and I am using below configuration in defining 'avg' function (Referred [2]), but it seems I am using the wrong syntax. 

                      xmlns:test="http://test"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:avg((3,4,5))"/>

Can someone please point the correct syntax?

Since avg function requires a single parameter, is there a way to define the integer values externally ( may be using a property mediator ) and use it inside the function ?

If this syntax is correct, is this function not supported in ESB?

Really appreciate your input on this

FYI: When saving the proxy, I'm getting below exception:

[2016-08-01 11:41:11,718] ERROR - ProxyServiceAdmin Unable to save changes made for the proxy service : testProxy. Restored the existing proxy... :: Invalid XPapth expression : fn:avg((3,4,5))
org.apache.synapse.SynapseException: Invalid XPapth expression : fn:avg((3,4,5))
at org.apache.synapse.config.xml.MediatorPropertyFactory.getMediatorProperties(MediatorPropertyFactory.java:106)
at org.apache.synapse.config.xml.LogMediatorFactory.createSpecificMediator(LogMediatorFactory.java:111)
.......



[1] Xpath 2.0.0 functions supported by ESB
[2] https://www.w3.org/TR/xpath-functions/#func-avg
Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774




_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Passing values to the Xpath 2.0 function - fn:avg

sohani
Hi ESB Team,

Please find the summary of issues encountered while testing the XPath 2.0 functions at [1] ( referred [2] & [3] for syntax) and really appreciate your input on this


1. "Invalid XPath Syntax" occurs when saving the synapse configuration in management console

This error occurs for below functions:
  • avg- fn:avg((1,2,3,4,5))
  • codepoints-to-string - fn:codepoints-to-string((97, 32, 98, 32, 99)))
  • distinct-values - fn:distinct-values( ('a', 'b', 'a') ) -This is supported when passing the value as an xml payload
  • id - //book/section/secRef/fn:id(@refs)
  • idref - //book/idref('language')/string(.)
  • index-of - fn:index-of( (4, 5, 6, 4), 4)
  • max- fn:max((2,3,5))
  • min - fn:min((2,3,5))
  • remove - fn:remove( ('a', 'b', 'c'), 2)
  • reverse - fn:reverse((1, 2, 3, 4, 5))  -This is supported when passing the value as an xml payload
  • string-join - string-join( ('a', 'b', 'c'), '')
  • subsequence - fn:subsequence(('a', 'b', 'c', 'd', 'e'), 3)

2. Issues in using error() function

According to https://www.w3.org/TR/xpath-functions-30/#ERRFOER0000 , calling the function with empty parameters should give an unidentified error. But when invoking the service it gives below exception

Is this accepted?

ERROR - SynapseXPath Evaluation of the XPath expression fn:error() resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Error signalled by application call on error()
at net.sf.saxon.functions.Error.error(Error.java:98)
at net.sf.saxon.functions.Error.evaluateItem(Error.java:55)
at net.sf.saxon.expr.Expression.iterate(Expression.java:429)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:326)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:389)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:533)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)


3. "System function is not available with this host language/version" occurs when invoking the service

According to https://sourceforge.net/p/saxon/mailman/saxon-help/thread/50F7F8B9.4090108@.../, it seems this is an XSLT function, is that the reason for getting the below error?  but at [1] this function is declared as an XPath function


[2016-08-02 12:47:27,875] ERROR - SynapseXPath Evaluation of the XPath expression fn:format-date(fn:current-date(), '[Y01]/[M01]/[D01]') resulted in an error
net.sf.saxon.trans.XPathException: System function format-date#2 is not available with this host language/version
at net.sf.saxon.expr.parser.ExpressionParser.grumble(ExpressionParser.java:263)
at net.sf.saxon.expr.parser.ExpressionParser.parseFunctionCall(ExpressionParser.java:2375)
at net.sf.saxon.expr.parser.ExpressionParser.parseBasicStep(ExpressionParser.java:1731)
at net.sf.saxon.expr.parser.ExpressionParser.parseStepExpression(ExpressionParser.java:1654)
at net.sf.saxon.expr.parser.ExpressionParser.parseRelativePath(ExpressionParser.java:1573)
at net.sf.saxon.expr.parser.ExpressionParser.parsePathExpression(ExpressionParser.java:1557)
at net.sf.saxon.expr.parser.ExpressionParser.parseUnaryExpression(ExpressionParser.java:1447)
at net.sf.saxon.expr.parser.ExpressionParser.parseExprSingle(ExpressionParser.java:517)
at net.sf.saxon.expr.parser.ExpressionParser.parseExpression(ExpressionParser.java:455)
at net.sf.saxon.expr.parser.ExpressionParser.parse(ExpressionParser.java:391)
at net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:94)
at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:235)
at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

4. Error in using insert-before() function


According to https://docs.marklogic.com/fn:insert-before if the function written as 
fn:insert-before('a', 0, 'x'), then it gives the below error when invoking the service

If the position casts to xs:integer as fn:insert-before('a', xs:integer(0), 'x') and invoke the service then the result only has 'x' but the expected result should be 'x,a'


[2016-08-02 14:39:23,625] ERROR - SynapseXPath Evaluation of the XPath expression fn:insert-before('a', 1, 'x') resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Required item type of second argument of fn:insert-before() is xs:integer; supplied value has item type xs:decimal
        at net.sf.saxon.expr.parser.TypeChecker.staticTypeCheck(TypeChecker.java:404)
        at net.sf.saxon.functions.SystemFunction.checkArgument(SystemFunction.java:117)
        at net.sf.saxon.functions.SystemFunction.checkArguments(SystemFunction.java:100)
        at net.sf.saxon.expr.FunctionCall.typeCheck(FunctionCall.java:134)
        at net.sf.saxon.expr.parser.ExpressionVisitor.typeCheck(ExpressionVisitor.java:206)
        at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:239)
        at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
        at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
        at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
        at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
        at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
        at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
        at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
        at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
        at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)



5. nilled() function always gives the result as false


payload:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <child>12</child> <child xsi:nil="true"></child> <child></child> <child/> <child xsi:nil="false"></child> </root>

function: fn:nilled(//child[1])

For all child elements it gives false ( even for the elements which has xsi:nil)


6. root() function does not give the root element


payload:

<a>
  <x>123</x>
</a>

function: fn:root(//x)

result : 123

expected result : 
<a>
  <x>123</x>
</a>


7. Using the function static-base-uri()


Can someone please mention how to define the function and the usage?



8. Using the function unordered()


payload :

<a>
  <x>1</x>
 <x>2</x>
 <x>3</x>
</a>

function: fn:unordered(//x)

result : 1

Can someone please explain the usage of this function? it seems the expected result should be a sequence of items




-more information on the testing results can be found at [4]

-Further, when going through the functions at [1] it seems below functions are only supported for XSLT ( I guess we don't need to support those functions when considering the XPath 2.0 functions, please correct me if I'm wrong)


functions:
  • current
  • current-group
  • current-grouping-key
  • document
  • element-available
  • function-available
  • generate-id(http://www.xsltfunctions.com/xsl/fn_generate-id.html)
  • regex-group
  • system-property
  • type-available
  • unparsed-entity-public-id
  • unparsed-entity-uri
  • unparsed-text
  • unparsed-text-available

- XPath 3.0 functions listed at [1]

acos ,analyze-string,asin,atan,ata2,available-environment-variables,cos,element-with-id,environment-variable,exp,exp10,filter,fold-left,fold-right,format-integer,function-arity,function-lookup,function-name,has-children,head,innermost,log,log10,map,map-pairs,outermost,parse-json,parse-xml ,path,pi,pow,round,serialize,serialize-json,sin,sqrt,tail,tan,unparsed-text-lines,uri-collection




Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : +94 716439774

On Mon, Aug 1, 2016 at 4:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
According to [1] if I test the distinct-values function,it behaves as explained below:


1. If I use a rest mock service to get the response and then get the distinct values :

Rest mock service response:

<catalog xml:base="http://example.org/ACC/"> <product dept="WMN"> <number>557</number> <number>44</number>
<number>44</number> </product> </catalog>

Rest API:

<api xmlns="http://ws.apache.org/ns/synapse" name="sample123" context="/test123"> <resource methods="POST GET"> <inSequence> <send> <endpoint> <address uri="http://localhost:8080/getResult"/> </endpoint> </send> </inSequence> <outSequence> <log level="custom"> <property xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns="http://org.apache.synapse/xsd" xmlns:base="http://test" name="testValue" expression="fn:distinct-values(//product/*)"/>
</log> </outSequence> </resource> </api>


Then expected result is : 557, 44

But I am getting only 557

Am I missing something here?

2. If I directly use this function as below

       name="testProxy"
       transports="http https"
       startOnLoad="true">
   <description/>
   <target>
      <inSequence>
         <log level="custom">
            <property xmlns:fn="http://www.w3.org/2005/xpath-functions"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:distinct-values(('a', 'b', 'a'))"/>
         </log>
      </inSequence>
      <outSequence/>
   </target>
</proxy>

Then I'm getting the exception "invalid XPapth expression" in saving the proxy

But according to [1] it seems both ways are correct



Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 3:54 PM, Sohani Weerasinghe <[hidden email]> wrote:



Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 1:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

It seems, the " Invalid XPapth expression" comes when we use two brackets in the function as below


While I was testing further I found that below function works perfectly even it has two brackets, so that means the syntax of the above mentioned functions are correct. 

So, are these functions not supported in ESB? Appreciate your input on this

fn:dateTime(xs:date('2006-08-15'), xs:time('12:30:45-05:00')) 


fn:codepoints-to-string((2309, 2358, 2378, 2325))
fn:string-join(('a', 'c'), 'bbb')






Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 12:06 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

I am validating the Xpath 2.0 functions support in ESB ( please refer [1]) and I am using below configuration in defining 'avg' function (Referred [2]), but it seems I am using the wrong syntax. 

                      xmlns:test="http://test"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:avg((3,4,5))"/>

Can someone please point the correct syntax?

Since avg function requires a single parameter, is there a way to define the integer values externally ( may be using a property mediator ) and use it inside the function ?

If this syntax is correct, is this function not supported in ESB?

Really appreciate your input on this

FYI: When saving the proxy, I'm getting below exception:

[2016-08-01 11:41:11,718] ERROR - ProxyServiceAdmin Unable to save changes made for the proxy service : testProxy. Restored the existing proxy... :: Invalid XPapth expression : fn:avg((3,4,5))
org.apache.synapse.SynapseException: Invalid XPapth expression : fn:avg((3,4,5))
at org.apache.synapse.config.xml.MediatorPropertyFactory.getMediatorProperties(MediatorPropertyFactory.java:106)
at org.apache.synapse.config.xml.LogMediatorFactory.createSpecificMediator(LogMediatorFactory.java:111)
.......



[1] Xpath 2.0.0 functions supported by ESB
[2] https://www.w3.org/TR/xpath-functions/#func-avg
Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774





_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Passing values to the Xpath 2.0 function - fn:avg

Shafreen Anfar
Hi Sohanai,

[+ Asanthi]

We are using Saxon: HE (Home Edition) for XAPTH 2 functions. AFAIK, we don't select functionality to support so anything supported by library should already be there, which means it's likely HE edition does not contain function you're looking for. Please have a look at [1].


On Thu, Aug 4, 2016 at 6:57 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi ESB Team,

Please find the summary of issues encountered while testing the XPath 2.0 functions at [1] ( referred [2] & [3] for syntax) and really appreciate your input on this


1. "Invalid XPath Syntax" occurs when saving the synapse configuration in management console

This error occurs for below functions:
  • avg- fn:avg((1,2,3,4,5))
  • codepoints-to-string - fn:codepoints-to-string((97, 32, 98, 32, 99)))
  • distinct-values - fn:distinct-values( ('a', 'b', 'a') ) -This is supported when passing the value as an xml payload
  • id - //book/section/secRef/fn:id(@refs)
  • idref - //book/idref('language')/string(.)
  • index-of - fn:index-of( (4, 5, 6, 4), 4)
  • max- fn:max((2,3,5))
  • min - fn:min((2,3,5))
  • remove - fn:remove( ('a', 'b', 'c'), 2)
  • reverse - fn:reverse((1, 2, 3, 4, 5))  -This is supported when passing the value as an xml payload
  • string-join - string-join( ('a', 'b', 'c'), '')
  • subsequence - fn:subsequence(('a', 'b', 'c', 'd', 'e'), 3)

2. Issues in using error() function

According to https://www.w3.org/TR/xpath-functions-30/#ERRFOER0000 , calling the function with empty parameters should give an unidentified error. But when invoking the service it gives below exception

Is this accepted?

ERROR - SynapseXPath Evaluation of the XPath expression fn:error() resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Error signalled by application call on error()
at net.sf.saxon.functions.Error.error(Error.java:98)
at net.sf.saxon.functions.Error.evaluateItem(Error.java:55)
at net.sf.saxon.expr.Expression.iterate(Expression.java:429)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:326)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:389)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:533)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)


3. "System function is not available with this host language/version" occurs when invoking the service

According to https://sourceforge.net/p/saxon/mailman/saxon-help/thread/50F7F8B9.4090108@falutin.net/, it seems this is an XSLT function, is that the reason for getting the below error?  but at [1] this function is declared as an XPath function


[2016-08-02 12:47:27,875] ERROR - SynapseXPath Evaluation of the XPath expression fn:format-date(fn:current-date(), '[Y01]/[M01]/[D01]') resulted in an error
net.sf.saxon.trans.XPathException: System function format-date#2 is not available with this host language/version
at net.sf.saxon.expr.parser.ExpressionParser.grumble(ExpressionParser.java:263)
at net.sf.saxon.expr.parser.ExpressionParser.parseFunctionCall(ExpressionParser.java:2375)
at net.sf.saxon.expr.parser.ExpressionParser.parseBasicStep(ExpressionParser.java:1731)
at net.sf.saxon.expr.parser.ExpressionParser.parseStepExpression(ExpressionParser.java:1654)
at net.sf.saxon.expr.parser.ExpressionParser.parseRelativePath(ExpressionParser.java:1573)
at net.sf.saxon.expr.parser.ExpressionParser.parsePathExpression(ExpressionParser.java:1557)
at net.sf.saxon.expr.parser.ExpressionParser.parseUnaryExpression(ExpressionParser.java:1447)
at net.sf.saxon.expr.parser.ExpressionParser.parseExprSingle(ExpressionParser.java:517)
at net.sf.saxon.expr.parser.ExpressionParser.parseExpression(ExpressionParser.java:455)
at net.sf.saxon.expr.parser.ExpressionParser.parse(ExpressionParser.java:391)
at net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:94)
at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:235)
at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

4. Error in using insert-before() function


According to https://docs.marklogic.com/fn:insert-before if the function written as 
fn:insert-before('a', 0, 'x'), then it gives the below error when invoking the service

If the position casts to xs:integer as fn:insert-before('a', xs:integer(0), 'x') and invoke the service then the result only has 'x' but the expected result should be 'x,a'


[2016-08-02 14:39:23,625] ERROR - SynapseXPath Evaluation of the XPath expression fn:insert-before('a', 1, 'x') resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Required item type of second argument of fn:insert-before() is xs:integer; supplied value has item type xs:decimal
        at net.sf.saxon.expr.parser.TypeChecker.staticTypeCheck(TypeChecker.java:404)
        at net.sf.saxon.functions.SystemFunction.checkArgument(SystemFunction.java:117)
        at net.sf.saxon.functions.SystemFunction.checkArguments(SystemFunction.java:100)
        at net.sf.saxon.expr.FunctionCall.typeCheck(FunctionCall.java:134)
        at net.sf.saxon.expr.parser.ExpressionVisitor.typeCheck(ExpressionVisitor.java:206)
        at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:239)
        at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
        at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
        at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
        at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
        at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
        at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
        at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
        at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
        at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)



5. nilled() function always gives the result as false


payload:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <child>12</child> <child xsi:nil="true"></child> <child></child> <child/> <child xsi:nil="false"></child> </root>

function: fn:nilled(//child[1])

For all child elements it gives false ( even for the elements which has xsi:nil)


6. root() function does not give the root element


payload:

<a>
  <x>123</x>
</a>

function: fn:root(//x)

result : 123

expected result : 
<a>
  <x>123</x>
</a>


7. Using the function static-base-uri()


Can someone please mention how to define the function and the usage?



8. Using the function unordered()


payload :

<a>
  <x>1</x>
 <x>2</x>
 <x>3</x>
</a>

function: fn:unordered(//x)

result : 1

Can someone please explain the usage of this function? it seems the expected result should be a sequence of items




-more information on the testing results can be found at [4]

-Further, when going through the functions at [1] it seems below functions are only supported for XSLT ( I guess we don't need to support those functions when considering the XPath 2.0 functions, please correct me if I'm wrong)


functions:
  • current
  • current-group
  • current-grouping-key
  • document
  • element-available
  • function-available
  • generate-id(http://www.xsltfunctions.com/xsl/fn_generate-id.html)
  • regex-group
  • system-property
  • type-available
  • unparsed-entity-public-id
  • unparsed-entity-uri
  • unparsed-text
  • unparsed-text-available

- XPath 3.0 functions listed at [1]

acos ,analyze-string,asin,atan,ata2,available-environment-variables,cos,element-with-id,environment-variable,exp,exp10,filter,fold-left,fold-right,format-integer,function-arity,function-lookup,function-name,has-children,head,innermost,log,log10,map,map-pairs,outermost,parse-json,parse-xml ,path,pi,pow,round,serialize,serialize-json,sin,sqrt,tail,tan,unparsed-text-lines,uri-collection




Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 4:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
According to [1] if I test the distinct-values function,it behaves as explained below:


1. If I use a rest mock service to get the response and then get the distinct values :

Rest mock service response:

<catalog xml:base="http://example.org/ACC/"> <product dept="WMN"> <number>557</number> <number>44</number>
<number>44</number> </product> </catalog>

Rest API:

<api xmlns="http://ws.apache.org/ns/synapse" name="sample123" context="/test123"> <resource methods="POST GET"> <inSequence> <send> <endpoint> <address uri="http://localhost:8080/getResult"/> </endpoint> </send> </inSequence> <outSequence> <log level="custom"> <property xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns="http://org.apache.synapse/xsd" xmlns:base="http://test" name="testValue" expression="fn:distinct-values(//product/*)"/>
</log> </outSequence> </resource> </api>


Then expected result is : 557, 44

But I am getting only 557

Am I missing something here?

2. If I directly use this function as below

       name="testProxy"
       transports="http https"
       startOnLoad="true">
   <description/>
   <target>
      <inSequence>
         <log level="custom">
            <property xmlns:fn="http://www.w3.org/2005/xpath-functions"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:distinct-values(('a', 'b', 'a'))"/>
         </log>
      </inSequence>
      <outSequence/>
   </target>
</proxy>

Then I'm getting the exception "invalid XPapth expression" in saving the proxy

But according to [1] it seems both ways are correct



Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 3:54 PM, Sohani Weerasinghe <[hidden email]> wrote:



Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 1:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

It seems, the " Invalid XPapth expression" comes when we use two brackets in the function as below


While I was testing further I found that below function works perfectly even it has two brackets, so that means the syntax of the above mentioned functions are correct. 

So, are these functions not supported in ESB? Appreciate your input on this

fn:dateTime(xs:date('2006-08-15'), xs:time('12:30:45-05:00')) 


fn:codepoints-to-string((2309, 2358, 2378, 2325))
fn:string-join(('a', 'c'), 'bbb')






Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 12:06 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

I am validating the Xpath 2.0 functions support in ESB ( please refer [1]) and I am using below configuration in defining 'avg' function (Referred [2]), but it seems I am using the wrong syntax. 

                      xmlns:test="http://test"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:avg((3,4,5))"/>

Can someone please point the correct syntax?

Since avg function requires a single parameter, is there a way to define the integer values externally ( may be using a property mediator ) and use it inside the function ?

If this syntax is correct, is this function not supported in ESB?

Really appreciate your input on this

FYI: When saving the proxy, I'm getting below exception:

[2016-08-01 11:41:11,718] ERROR - ProxyServiceAdmin Unable to save changes made for the proxy service : testProxy. Restored the existing proxy... :: Invalid XPapth expression : fn:avg((3,4,5))
org.apache.synapse.SynapseException: Invalid XPapth expression : fn:avg((3,4,5))
at org.apache.synapse.config.xml.MediatorPropertyFactory.getMediatorProperties(MediatorPropertyFactory.java:106)
at org.apache.synapse.config.xml.LogMediatorFactory.createSpecificMediator(LogMediatorFactory.java:111)
.......



[1] Xpath 2.0.0 functions supported by ESB
[2] https://www.w3.org/TR/xpath-functions/#func-avg
Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774







--
Regards,
Shafreen
Software Engineer
WSO2 Inc
Mobile : 077-556-395-1

_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Passing values to the Xpath 2.0 function - fn:avg

sohani

Hi Shafreen,

I have used [1] in testing the functions, since there is no proper reference to get a list of functions supported by the Saxon 9.4 HE. Based on this, can we confirm that the mentioned functions in the above thread are not supported in HE? (so that we can conclude with the functions we are supporting in ESB)


Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : +94 716439774

On Fri, Aug 5, 2016 at 10:21 AM, Shafreen Anfar <[hidden email]> wrote:
Hi Sohanai,

[+ Asanthi]

We are using Saxon: HE (Home Edition) for XAPTH 2 functions. AFAIK, we don't select functionality to support so anything supported by library should already be there, which means it's likely HE edition does not contain function you're looking for. Please have a look at [1].


On Thu, Aug 4, 2016 at 6:57 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi ESB Team,

Please find the summary of issues encountered while testing the XPath 2.0 functions at [1] ( referred [2] & [3] for syntax) and really appreciate your input on this


1. "Invalid XPath Syntax" occurs when saving the synapse configuration in management console

This error occurs for below functions:
  • avg- fn:avg((1,2,3,4,5))
  • codepoints-to-string - fn:codepoints-to-string((97, 32, 98, 32, 99)))
  • distinct-values - fn:distinct-values( ('a', 'b', 'a') ) -This is supported when passing the value as an xml payload
  • id - //book/section/secRef/fn:id(@refs)
  • idref - //book/idref('language')/string(.)
  • index-of - fn:index-of( (4, 5, 6, 4), 4)
  • max- fn:max((2,3,5))
  • min - fn:min((2,3,5))
  • remove - fn:remove( ('a', 'b', 'c'), 2)
  • reverse - fn:reverse((1, 2, 3, 4, 5))  -This is supported when passing the value as an xml payload
  • string-join - string-join( ('a', 'b', 'c'), '')
  • subsequence - fn:subsequence(('a', 'b', 'c', 'd', 'e'), 3)

2. Issues in using error() function

According to https://www.w3.org/TR/xpath-functions-30/#ERRFOER0000 , calling the function with empty parameters should give an unidentified error. But when invoking the service it gives below exception

Is this accepted?

ERROR - SynapseXPath Evaluation of the XPath expression fn:error() resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Error signalled by application call on error()
at net.sf.saxon.functions.Error.error(Error.java:98)
at net.sf.saxon.functions.Error.evaluateItem(Error.java:55)
at net.sf.saxon.expr.Expression.iterate(Expression.java:429)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:326)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:389)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:533)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)


3. "System function is not available with this host language/version" occurs when invoking the service

According to https://sourceforge.net/p/saxon/mailman/saxon-help/thread/50F7F8B9.4090108@.../, it seems this is an XSLT function, is that the reason for getting the below error?  but at [1] this function is declared as an XPath function


[2016-08-02 12:47:27,875] ERROR - SynapseXPath Evaluation of the XPath expression fn:format-date(fn:current-date(), '[Y01]/[M01]/[D01]') resulted in an error
net.sf.saxon.trans.XPathException: System function format-date#2 is not available with this host language/version
at net.sf.saxon.expr.parser.ExpressionParser.grumble(ExpressionParser.java:263)
at net.sf.saxon.expr.parser.ExpressionParser.parseFunctionCall(ExpressionParser.java:2375)
at net.sf.saxon.expr.parser.ExpressionParser.parseBasicStep(ExpressionParser.java:1731)
at net.sf.saxon.expr.parser.ExpressionParser.parseStepExpression(ExpressionParser.java:1654)
at net.sf.saxon.expr.parser.ExpressionParser.parseRelativePath(ExpressionParser.java:1573)
at net.sf.saxon.expr.parser.ExpressionParser.parsePathExpression(ExpressionParser.java:1557)
at net.sf.saxon.expr.parser.ExpressionParser.parseUnaryExpression(ExpressionParser.java:1447)
at net.sf.saxon.expr.parser.ExpressionParser.parseExprSingle(ExpressionParser.java:517)
at net.sf.saxon.expr.parser.ExpressionParser.parseExpression(ExpressionParser.java:455)
at net.sf.saxon.expr.parser.ExpressionParser.parse(ExpressionParser.java:391)
at net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:94)
at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:235)
at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

4. Error in using insert-before() function


According to https://docs.marklogic.com/fn:insert-before if the function written as 
fn:insert-before('a', 0, 'x'), then it gives the below error when invoking the service

If the position casts to xs:integer as fn:insert-before('a', xs:integer(0), 'x') and invoke the service then the result only has 'x' but the expected result should be 'x,a'


[2016-08-02 14:39:23,625] ERROR - SynapseXPath Evaluation of the XPath expression fn:insert-before('a', 1, 'x') resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Required item type of second argument of fn:insert-before() is xs:integer; supplied value has item type xs:decimal
        at net.sf.saxon.expr.parser.TypeChecker.staticTypeCheck(TypeChecker.java:404)
        at net.sf.saxon.functions.SystemFunction.checkArgument(SystemFunction.java:117)
        at net.sf.saxon.functions.SystemFunction.checkArguments(SystemFunction.java:100)
        at net.sf.saxon.expr.FunctionCall.typeCheck(FunctionCall.java:134)
        at net.sf.saxon.expr.parser.ExpressionVisitor.typeCheck(ExpressionVisitor.java:206)
        at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:239)
        at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
        at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
        at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
        at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
        at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
        at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
        at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
        at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
        at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)



5. nilled() function always gives the result as false


payload:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <child>12</child> <child xsi:nil="true"></child> <child></child> <child/> <child xsi:nil="false"></child> </root>

function: fn:nilled(//child[1])

For all child elements it gives false ( even for the elements which has xsi:nil)


6. root() function does not give the root element


payload:

<a>
  <x>123</x>
</a>

function: fn:root(//x)

result : 123

expected result : 
<a>
  <x>123</x>
</a>


7. Using the function static-base-uri()


Can someone please mention how to define the function and the usage?



8. Using the function unordered()


payload :

<a>
  <x>1</x>
 <x>2</x>
 <x>3</x>
</a>

function: fn:unordered(//x)

result : 1

Can someone please explain the usage of this function? it seems the expected result should be a sequence of items




-more information on the testing results can be found at [4]

-Further, when going through the functions at [1] it seems below functions are only supported for XSLT ( I guess we don't need to support those functions when considering the XPath 2.0 functions, please correct me if I'm wrong)


functions:
  • current
  • current-group
  • current-grouping-key
  • document
  • element-available
  • function-available
  • generate-id(http://www.xsltfunctions.com/xsl/fn_generate-id.html)
  • regex-group
  • system-property
  • type-available
  • unparsed-entity-public-id
  • unparsed-entity-uri
  • unparsed-text
  • unparsed-text-available

- XPath 3.0 functions listed at [1]

acos ,analyze-string,asin,atan,ata2,available-environment-variables,cos,element-with-id,environment-variable,exp,exp10,filter,fold-left,fold-right,format-integer,function-arity,function-lookup,function-name,has-children,head,innermost,log,log10,map,map-pairs,outermost,parse-json,parse-xml ,path,pi,pow,round,serialize,serialize-json,sin,sqrt,tail,tan,unparsed-text-lines,uri-collection




Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 4:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
According to [1] if I test the distinct-values function,it behaves as explained below:


1. If I use a rest mock service to get the response and then get the distinct values :

Rest mock service response:

<catalog xml:base="http://example.org/ACC/"> <product dept="WMN"> <number>557</number> <number>44</number>
<number>44</number> </product> </catalog>

Rest API:

<api xmlns="http://ws.apache.org/ns/synapse" name="sample123" context="/test123"> <resource methods="POST GET"> <inSequence> <send> <endpoint> <address uri="http://localhost:8080/getResult"/> </endpoint> </send> </inSequence> <outSequence> <log level="custom"> <property xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns="http://org.apache.synapse/xsd" xmlns:base="http://test" name="testValue" expression="fn:distinct-values(//product/*)"/>
</log> </outSequence> </resource> </api>


Then expected result is : 557, 44

But I am getting only 557

Am I missing something here?

2. If I directly use this function as below

       name="testProxy"
       transports="http https"
       startOnLoad="true">
   <description/>
   <target>
      <inSequence>
         <log level="custom">
            <property xmlns:fn="http://www.w3.org/2005/xpath-functions"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:distinct-values(('a', 'b', 'a'))"/>
         </log>
      </inSequence>
      <outSequence/>
   </target>
</proxy>

Then I'm getting the exception "invalid XPapth expression" in saving the proxy

But according to [1] it seems both ways are correct



Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 3:54 PM, Sohani Weerasinghe <[hidden email]> wrote:



Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 1:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

It seems, the " Invalid XPapth expression" comes when we use two brackets in the function as below


While I was testing further I found that below function works perfectly even it has two brackets, so that means the syntax of the above mentioned functions are correct. 

So, are these functions not supported in ESB? Appreciate your input on this

fn:dateTime(xs:date('2006-08-15'), xs:time('12:30:45-05:00')) 


fn:codepoints-to-string((2309, 2358, 2378, 2325))
fn:string-join(('a', 'c'), 'bbb')






Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 12:06 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

I am validating the Xpath 2.0 functions support in ESB ( please refer [1]) and I am using below configuration in defining 'avg' function (Referred [2]), but it seems I am using the wrong syntax. 

                      xmlns:test="http://test"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:avg((3,4,5))"/>

Can someone please point the correct syntax?

Since avg function requires a single parameter, is there a way to define the integer values externally ( may be using a property mediator ) and use it inside the function ?

If this syntax is correct, is this function not supported in ESB?

Really appreciate your input on this

FYI: When saving the proxy, I'm getting below exception:

[2016-08-01 11:41:11,718] ERROR - ProxyServiceAdmin Unable to save changes made for the proxy service : testProxy. Restored the existing proxy... :: Invalid XPapth expression : fn:avg((3,4,5))
org.apache.synapse.SynapseException: Invalid XPapth expression : fn:avg((3,4,5))
at org.apache.synapse.config.xml.MediatorPropertyFactory.getMediatorProperties(MediatorPropertyFactory.java:106)
at org.apache.synapse.config.xml.LogMediatorFactory.createSpecificMediator(LogMediatorFactory.java:111)
.......



[1] Xpath 2.0.0 functions supported by ESB
[2] https://www.w3.org/TR/xpath-functions/#func-avg
Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774







--
Regards,
Shafreen
Software Engineer
WSO2 Inc
Mobile : 077-556-395-1


_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Passing values to the Xpath 2.0 function - fn:avg

Shafreen Anfar
Hi Sohani,

Sorry for the delayed response. IMO, ideally we should try writing a simple java program with HE and see if it supports that particular function or not. Anyways, since it is not working in ESB. I think it is OK to conclude that is not supported in our ESB.

On Fri, Aug 5, 2016 at 10:52 AM, Sohani Weerasinghe <[hidden email]> wrote:

Hi Shafreen,

I have used [1] in testing the functions, since there is no proper reference to get a list of functions supported by the Saxon 9.4 HE. Based on this, can we confirm that the mentioned functions in the above thread are not supported in HE? (so that we can conclude with the functions we are supporting in ESB)


Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Fri, Aug 5, 2016 at 10:21 AM, Shafreen Anfar <[hidden email]> wrote:
Hi Sohanai,

[+ Asanthi]

We are using Saxon: HE (Home Edition) for XAPTH 2 functions. AFAIK, we don't select functionality to support so anything supported by library should already be there, which means it's likely HE edition does not contain function you're looking for. Please have a look at [1].


On Thu, Aug 4, 2016 at 6:57 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi ESB Team,

Please find the summary of issues encountered while testing the XPath 2.0 functions at [1] ( referred [2] & [3] for syntax) and really appreciate your input on this


1. "Invalid XPath Syntax" occurs when saving the synapse configuration in management console

This error occurs for below functions:
  • avg- fn:avg((1,2,3,4,5))
  • codepoints-to-string - fn:codepoints-to-string((97, 32, 98, 32, 99)))
  • distinct-values - fn:distinct-values( ('a', 'b', 'a') ) -This is supported when passing the value as an xml payload
  • id - //book/section/secRef/fn:id(@refs)
  • idref - //book/idref('language')/string(.)
  • index-of - fn:index-of( (4, 5, 6, 4), 4)
  • max- fn:max((2,3,5))
  • min - fn:min((2,3,5))
  • remove - fn:remove( ('a', 'b', 'c'), 2)
  • reverse - fn:reverse((1, 2, 3, 4, 5))  -This is supported when passing the value as an xml payload
  • string-join - string-join( ('a', 'b', 'c'), '')
  • subsequence - fn:subsequence(('a', 'b', 'c', 'd', 'e'), 3)

2. Issues in using error() function

According to https://www.w3.org/TR/xpath-functions-30/#ERRFOER0000 , calling the function with empty parameters should give an unidentified error. But when invoking the service it gives below exception

Is this accepted?

ERROR - SynapseXPath Evaluation of the XPath expression fn:error() resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Error signalled by application call on error()
at net.sf.saxon.functions.Error.error(Error.java:98)
at net.sf.saxon.functions.Error.evaluateItem(Error.java:55)
at net.sf.saxon.expr.Expression.iterate(Expression.java:429)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:326)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:389)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:533)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)


3. "System function is not available with this host language/version" occurs when invoking the service

According to https://sourceforge.net/p/saxon/mailman/saxon-help/thread/50F7F8B9.4090108@.../, it seems this is an XSLT function, is that the reason for getting the below error?  but at [1] this function is declared as an XPath function


[2016-08-02 12:47:27,875] ERROR - SynapseXPath Evaluation of the XPath expression fn:format-date(fn:current-date(), '[Y01]/[M01]/[D01]') resulted in an error
net.sf.saxon.trans.XPathException: System function format-date#2 is not available with this host language/version
at net.sf.saxon.expr.parser.ExpressionParser.grumble(ExpressionParser.java:263)
at net.sf.saxon.expr.parser.ExpressionParser.parseFunctionCall(ExpressionParser.java:2375)
at net.sf.saxon.expr.parser.ExpressionParser.parseBasicStep(ExpressionParser.java:1731)
at net.sf.saxon.expr.parser.ExpressionParser.parseStepExpression(ExpressionParser.java:1654)
at net.sf.saxon.expr.parser.ExpressionParser.parseRelativePath(ExpressionParser.java:1573)
at net.sf.saxon.expr.parser.ExpressionParser.parsePathExpression(ExpressionParser.java:1557)
at net.sf.saxon.expr.parser.ExpressionParser.parseUnaryExpression(ExpressionParser.java:1447)
at net.sf.saxon.expr.parser.ExpressionParser.parseExprSingle(ExpressionParser.java:517)
at net.sf.saxon.expr.parser.ExpressionParser.parseExpression(ExpressionParser.java:455)
at net.sf.saxon.expr.parser.ExpressionParser.parse(ExpressionParser.java:391)
at net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:94)
at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:235)
at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

4. Error in using insert-before() function


According to https://docs.marklogic.com/fn:insert-before if the function written as 
fn:insert-before('a', 0, 'x'), then it gives the below error when invoking the service

If the position casts to xs:integer as fn:insert-before('a', xs:integer(0), 'x') and invoke the service then the result only has 'x' but the expected result should be 'x,a'


[2016-08-02 14:39:23,625] ERROR - SynapseXPath Evaluation of the XPath expression fn:insert-before('a', 1, 'x') resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Required item type of second argument of fn:insert-before() is xs:integer; supplied value has item type xs:decimal
        at net.sf.saxon.expr.parser.TypeChecker.staticTypeCheck(TypeChecker.java:404)
        at net.sf.saxon.functions.SystemFunction.checkArgument(SystemFunction.java:117)
        at net.sf.saxon.functions.SystemFunction.checkArguments(SystemFunction.java:100)
        at net.sf.saxon.expr.FunctionCall.typeCheck(FunctionCall.java:134)
        at net.sf.saxon.expr.parser.ExpressionVisitor.typeCheck(ExpressionVisitor.java:206)
        at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:239)
        at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
        at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
        at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
        at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
        at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
        at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
        at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
        at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
        at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)



5. nilled() function always gives the result as false


payload:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <child>12</child> <child xsi:nil="true"></child> <child></child> <child/> <child xsi:nil="false"></child> </root>

function: fn:nilled(//child[1])

For all child elements it gives false ( even for the elements which has xsi:nil)


6. root() function does not give the root element


payload:

<a>
  <x>123</x>
</a>

function: fn:root(//x)

result : 123

expected result : 
<a>
  <x>123</x>
</a>


7. Using the function static-base-uri()


Can someone please mention how to define the function and the usage?



8. Using the function unordered()


payload :

<a>
  <x>1</x>
 <x>2</x>
 <x>3</x>
</a>

function: fn:unordered(//x)

result : 1

Can someone please explain the usage of this function? it seems the expected result should be a sequence of items




-more information on the testing results can be found at [4]

-Further, when going through the functions at [1] it seems below functions are only supported for XSLT ( I guess we don't need to support those functions when considering the XPath 2.0 functions, please correct me if I'm wrong)


functions:
  • current
  • current-group
  • current-grouping-key
  • document
  • element-available
  • function-available
  • generate-id(http://www.xsltfunctions.com/xsl/fn_generate-id.html)
  • regex-group
  • system-property
  • type-available
  • unparsed-entity-public-id
  • unparsed-entity-uri
  • unparsed-text
  • unparsed-text-available

- XPath 3.0 functions listed at [1]

acos ,analyze-string,asin,atan,ata2,available-environment-variables,cos,element-with-id,environment-variable,exp,exp10,filter,fold-left,fold-right,format-integer,function-arity,function-lookup,function-name,has-children,head,innermost,log,log10,map,map-pairs,outermost,parse-json,parse-xml ,path,pi,pow,round,serialize,serialize-json,sin,sqrt,tail,tan,unparsed-text-lines,uri-collection




Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 4:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
According to [1] if I test the distinct-values function,it behaves as explained below:


1. If I use a rest mock service to get the response and then get the distinct values :

Rest mock service response:

<catalog xml:base="http://example.org/ACC/"> <product dept="WMN"> <number>557</number> <number>44</number>
<number>44</number> </product> </catalog>

Rest API:

<api xmlns="http://ws.apache.org/ns/synapse" name="sample123" context="/test123"> <resource methods="POST GET"> <inSequence> <send> <endpoint> <address uri="http://localhost:8080/getResult"/> </endpoint> </send> </inSequence> <outSequence> <log level="custom"> <property xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns="http://org.apache.synapse/xsd" xmlns:base="http://test" name="testValue" expression="fn:distinct-values(//product/*)"/>
</log> </outSequence> </resource> </api>


Then expected result is : 557, 44

But I am getting only 557

Am I missing something here?

2. If I directly use this function as below

       name="testProxy"
       transports="http https"
       startOnLoad="true">
   <description/>
   <target>
      <inSequence>
         <log level="custom">
            <property xmlns:fn="http://www.w3.org/2005/xpath-functions"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:distinct-values(('a', 'b', 'a'))"/>
         </log>
      </inSequence>
      <outSequence/>
   </target>
</proxy>

Then I'm getting the exception "invalid XPapth expression" in saving the proxy

But according to [1] it seems both ways are correct



Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 3:54 PM, Sohani Weerasinghe <[hidden email]> wrote:



Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 1:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

It seems, the " Invalid XPapth expression" comes when we use two brackets in the function as below


While I was testing further I found that below function works perfectly even it has two brackets, so that means the syntax of the above mentioned functions are correct. 

So, are these functions not supported in ESB? Appreciate your input on this

fn:dateTime(xs:date('2006-08-15'), xs:time('12:30:45-05:00')) 


fn:codepoints-to-string((2309, 2358, 2378, 2325))
fn:string-join(('a', 'c'), 'bbb')






Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 12:06 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

I am validating the Xpath 2.0 functions support in ESB ( please refer [1]) and I am using below configuration in defining 'avg' function (Referred [2]), but it seems I am using the wrong syntax. 

                      xmlns:test="http://test"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:avg((3,4,5))"/>

Can someone please point the correct syntax?

Since avg function requires a single parameter, is there a way to define the integer values externally ( may be using a property mediator ) and use it inside the function ?

If this syntax is correct, is this function not supported in ESB?

Really appreciate your input on this

FYI: When saving the proxy, I'm getting below exception:

[2016-08-01 11:41:11,718] ERROR - ProxyServiceAdmin Unable to save changes made for the proxy service : testProxy. Restored the existing proxy... :: Invalid XPapth expression : fn:avg((3,4,5))
org.apache.synapse.SynapseException: Invalid XPapth expression : fn:avg((3,4,5))
at org.apache.synapse.config.xml.MediatorPropertyFactory.getMediatorProperties(MediatorPropertyFactory.java:106)
at org.apache.synapse.config.xml.LogMediatorFactory.createSpecificMediator(LogMediatorFactory.java:111)
.......



[1] Xpath 2.0.0 functions supported by ESB
[2] https://www.w3.org/TR/xpath-functions/#func-avg
Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774







--
Regards,
Shafreen
Software Engineer
WSO2 Inc
Mobile : 077-556-395-1




--
Regards,
Shafreen
Software Engineer
WSO2 Inc
Mobile : 077-556-395-1

_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Passing values to the Xpath 2.0 function - fn:avg

sohani
Thanks Shafreen for the input. 

@Nisrin: Please note

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : +94 716439774

On Tue, Aug 9, 2016 at 11:21 AM, Shafreen Anfar <[hidden email]> wrote:
Hi Sohani,

Sorry for the delayed response. IMO, ideally we should try writing a simple java program with HE and see if it supports that particular function or not. Anyways, since it is not working in ESB. I think it is OK to conclude that is not supported in our ESB.

On Fri, Aug 5, 2016 at 10:52 AM, Sohani Weerasinghe <[hidden email]> wrote:

Hi Shafreen,

I have used [1] in testing the functions, since there is no proper reference to get a list of functions supported by the Saxon 9.4 HE. Based on this, can we confirm that the mentioned functions in the above thread are not supported in HE? (so that we can conclude with the functions we are supporting in ESB)


Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Fri, Aug 5, 2016 at 10:21 AM, Shafreen Anfar <[hidden email]> wrote:
Hi Sohanai,

[+ Asanthi]

We are using Saxon: HE (Home Edition) for XAPTH 2 functions. AFAIK, we don't select functionality to support so anything supported by library should already be there, which means it's likely HE edition does not contain function you're looking for. Please have a look at [1].


On Thu, Aug 4, 2016 at 6:57 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi ESB Team,

Please find the summary of issues encountered while testing the XPath 2.0 functions at [1] ( referred [2] & [3] for syntax) and really appreciate your input on this


1. "Invalid XPath Syntax" occurs when saving the synapse configuration in management console

This error occurs for below functions:
  • avg- fn:avg((1,2,3,4,5))
  • codepoints-to-string - fn:codepoints-to-string((97, 32, 98, 32, 99)))
  • distinct-values - fn:distinct-values( ('a', 'b', 'a') ) -This is supported when passing the value as an xml payload
  • id - //book/section/secRef/fn:id(@refs)
  • idref - //book/idref('language')/string(.)
  • index-of - fn:index-of( (4, 5, 6, 4), 4)
  • max- fn:max((2,3,5))
  • min - fn:min((2,3,5))
  • remove - fn:remove( ('a', 'b', 'c'), 2)
  • reverse - fn:reverse((1, 2, 3, 4, 5))  -This is supported when passing the value as an xml payload
  • string-join - string-join( ('a', 'b', 'c'), '')
  • subsequence - fn:subsequence(('a', 'b', 'c', 'd', 'e'), 3)

2. Issues in using error() function

According to https://www.w3.org/TR/xpath-functions-30/#ERRFOER0000 , calling the function with empty parameters should give an unidentified error. But when invoking the service it gives below exception

Is this accepted?

ERROR - SynapseXPath Evaluation of the XPath expression fn:error() resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Error signalled by application call on error()
at net.sf.saxon.functions.Error.error(Error.java:98)
at net.sf.saxon.functions.Error.evaluateItem(Error.java:55)
at net.sf.saxon.expr.Expression.iterate(Expression.java:429)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:326)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:389)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:533)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)


3. "System function is not available with this host language/version" occurs when invoking the service

According to https://sourceforge.net/p/saxon/mailman/saxon-help/thread/50F7F8B9.4090108@.../, it seems this is an XSLT function, is that the reason for getting the below error?  but at [1] this function is declared as an XPath function


[2016-08-02 12:47:27,875] ERROR - SynapseXPath Evaluation of the XPath expression fn:format-date(fn:current-date(), '[Y01]/[M01]/[D01]') resulted in an error
net.sf.saxon.trans.XPathException: System function format-date#2 is not available with this host language/version
at net.sf.saxon.expr.parser.ExpressionParser.grumble(ExpressionParser.java:263)
at net.sf.saxon.expr.parser.ExpressionParser.parseFunctionCall(ExpressionParser.java:2375)
at net.sf.saxon.expr.parser.ExpressionParser.parseBasicStep(ExpressionParser.java:1731)
at net.sf.saxon.expr.parser.ExpressionParser.parseStepExpression(ExpressionParser.java:1654)
at net.sf.saxon.expr.parser.ExpressionParser.parseRelativePath(ExpressionParser.java:1573)
at net.sf.saxon.expr.parser.ExpressionParser.parsePathExpression(ExpressionParser.java:1557)
at net.sf.saxon.expr.parser.ExpressionParser.parseUnaryExpression(ExpressionParser.java:1447)
at net.sf.saxon.expr.parser.ExpressionParser.parseExprSingle(ExpressionParser.java:517)
at net.sf.saxon.expr.parser.ExpressionParser.parseExpression(ExpressionParser.java:455)
at net.sf.saxon.expr.parser.ExpressionParser.parse(ExpressionParser.java:391)
at net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:94)
at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:235)
at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

4. Error in using insert-before() function


According to https://docs.marklogic.com/fn:insert-before if the function written as 
fn:insert-before('a', 0, 'x'), then it gives the below error when invoking the service

If the position casts to xs:integer as fn:insert-before('a', xs:integer(0), 'x') and invoke the service then the result only has 'x' but the expected result should be 'x,a'


[2016-08-02 14:39:23,625] ERROR - SynapseXPath Evaluation of the XPath expression fn:insert-before('a', 1, 'x') resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Required item type of second argument of fn:insert-before() is xs:integer; supplied value has item type xs:decimal
        at net.sf.saxon.expr.parser.TypeChecker.staticTypeCheck(TypeChecker.java:404)
        at net.sf.saxon.functions.SystemFunction.checkArgument(SystemFunction.java:117)
        at net.sf.saxon.functions.SystemFunction.checkArguments(SystemFunction.java:100)
        at net.sf.saxon.expr.FunctionCall.typeCheck(FunctionCall.java:134)
        at net.sf.saxon.expr.parser.ExpressionVisitor.typeCheck(ExpressionVisitor.java:206)
        at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:239)
        at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
        at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
        at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
        at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
        at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
        at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
        at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
        at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
        at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)



5. nilled() function always gives the result as false


payload:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <child>12</child> <child xsi:nil="true"></child> <child></child> <child/> <child xsi:nil="false"></child> </root>

function: fn:nilled(//child[1])

For all child elements it gives false ( even for the elements which has xsi:nil)


6. root() function does not give the root element


payload:

<a>
  <x>123</x>
</a>

function: fn:root(//x)

result : 123

expected result : 
<a>
  <x>123</x>
</a>


7. Using the function static-base-uri()


Can someone please mention how to define the function and the usage?



8. Using the function unordered()


payload :

<a>
  <x>1</x>
 <x>2</x>
 <x>3</x>
</a>

function: fn:unordered(//x)

result : 1

Can someone please explain the usage of this function? it seems the expected result should be a sequence of items




-more information on the testing results can be found at [4]

-Further, when going through the functions at [1] it seems below functions are only supported for XSLT ( I guess we don't need to support those functions when considering the XPath 2.0 functions, please correct me if I'm wrong)


functions:
  • current
  • current-group
  • current-grouping-key
  • document
  • element-available
  • function-available
  • generate-id(http://www.xsltfunctions.com/xsl/fn_generate-id.html)
  • regex-group
  • system-property
  • type-available
  • unparsed-entity-public-id
  • unparsed-entity-uri
  • unparsed-text
  • unparsed-text-available

- XPath 3.0 functions listed at [1]

acos ,analyze-string,asin,atan,ata2,available-environment-variables,cos,element-with-id,environment-variable,exp,exp10,filter,fold-left,fold-right,format-integer,function-arity,function-lookup,function-name,has-children,head,innermost,log,log10,map,map-pairs,outermost,parse-json,parse-xml ,path,pi,pow,round,serialize,serialize-json,sin,sqrt,tail,tan,unparsed-text-lines,uri-collection




Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 4:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
According to [1] if I test the distinct-values function,it behaves as explained below:


1. If I use a rest mock service to get the response and then get the distinct values :

Rest mock service response:

<catalog xml:base="http://example.org/ACC/"> <product dept="WMN"> <number>557</number> <number>44</number>
<number>44</number> </product> </catalog>

Rest API:

<api xmlns="http://ws.apache.org/ns/synapse" name="sample123" context="/test123"> <resource methods="POST GET"> <inSequence> <send> <endpoint> <address uri="http://localhost:8080/getResult"/> </endpoint> </send> </inSequence> <outSequence> <log level="custom"> <property xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns="http://org.apache.synapse/xsd" xmlns:base="http://test" name="testValue" expression="fn:distinct-values(//product/*)"/>
</log> </outSequence> </resource> </api>


Then expected result is : 557, 44

But I am getting only 557

Am I missing something here?

2. If I directly use this function as below

       name="testProxy"
       transports="http https"
       startOnLoad="true">
   <description/>
   <target>
      <inSequence>
         <log level="custom">
            <property xmlns:fn="http://www.w3.org/2005/xpath-functions"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:distinct-values(('a', 'b', 'a'))"/>
         </log>
      </inSequence>
      <outSequence/>
   </target>
</proxy>

Then I'm getting the exception "invalid XPapth expression" in saving the proxy

But according to [1] it seems both ways are correct



Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 3:54 PM, Sohani Weerasinghe <[hidden email]> wrote:



Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 1:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

It seems, the " Invalid XPapth expression" comes when we use two brackets in the function as below


While I was testing further I found that below function works perfectly even it has two brackets, so that means the syntax of the above mentioned functions are correct. 

So, are these functions not supported in ESB? Appreciate your input on this

fn:dateTime(xs:date('2006-08-15'), xs:time('12:30:45-05:00')) 


fn:codepoints-to-string((2309, 2358, 2378, 2325))
fn:string-join(('a', 'c'), 'bbb')






Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 12:06 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

I am validating the Xpath 2.0 functions support in ESB ( please refer [1]) and I am using below configuration in defining 'avg' function (Referred [2]), but it seems I am using the wrong syntax. 

                      xmlns:test="http://test"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:avg((3,4,5))"/>

Can someone please point the correct syntax?

Since avg function requires a single parameter, is there a way to define the integer values externally ( may be using a property mediator ) and use it inside the function ?

If this syntax is correct, is this function not supported in ESB?

Really appreciate your input on this

FYI: When saving the proxy, I'm getting below exception:

[2016-08-01 11:41:11,718] ERROR - ProxyServiceAdmin Unable to save changes made for the proxy service : testProxy. Restored the existing proxy... :: Invalid XPapth expression : fn:avg((3,4,5))
org.apache.synapse.SynapseException: Invalid XPapth expression : fn:avg((3,4,5))
at org.apache.synapse.config.xml.MediatorPropertyFactory.getMediatorProperties(MediatorPropertyFactory.java:106)
at org.apache.synapse.config.xml.LogMediatorFactory.createSpecificMediator(LogMediatorFactory.java:111)
.......



[1] Xpath 2.0.0 functions supported by ESB
[2] https://www.w3.org/TR/xpath-functions/#func-avg
Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774







--
Regards,
Shafreen
Software Engineer
WSO2 Inc
Mobile : 077-556-395-1




--
Regards,
Shafreen
Software Engineer
WSO2 Inc
Mobile : 077-556-395-1


_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Passing values to the Xpath 2.0 function - fn:avg

Sashika Wijesinghe
Hi All,

I have added test cases [1] in Testlink to capture the XPath 2.0 and XSLT 2.0 functions supported by ESB. As mentioned in this mail thread some of the functions failed while saving them due to [2], and some other functions failed with "no such function" [3] exception. Test cases were included for the functions that worked successfully with ESB assuming that the other functions are not supported by ESB as concluded above. 

It would be better to add automated tests for the identified test cases [1] for XPath 2.0 and XSLT 2.0 functions.

@Documentation Team - Since we do not support all the available XPath 2.0 functions in ESB, better to include this point in the documentation.

[2] class org.jaxen.saxpath.XPathSyntaxException: fn:avg((1,2,3)): 9: Expected: ) 
[3] org.jaxen.UnresolvableException: No Such Function matches

Regards,
Sashika

On Tue, Aug 9, 2016 at 11:23 AM, Sohani Weerasinghe <[hidden email]> wrote:
Thanks Shafreen for the input. 

@Nisrin: Please note

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:+94%2071%20643%209774" value="+94716439774" target="_blank">+94 716439774

On Tue, Aug 9, 2016 at 11:21 AM, Shafreen Anfar <[hidden email]> wrote:
Hi Sohani,

Sorry for the delayed response. IMO, ideally we should try writing a simple java program with HE and see if it supports that particular function or not. Anyways, since it is not working in ESB. I think it is OK to conclude that is not supported in our ESB.

On Fri, Aug 5, 2016 at 10:52 AM, Sohani Weerasinghe <[hidden email]> wrote:

Hi Shafreen,

I have used [1] in testing the functions, since there is no proper reference to get a list of functions supported by the Saxon 9.4 HE. Based on this, can we confirm that the mentioned functions in the above thread are not supported in HE? (so that we can conclude with the functions we are supporting in ESB)


Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Fri, Aug 5, 2016 at 10:21 AM, Shafreen Anfar <[hidden email]> wrote:
Hi Sohanai,

[+ Asanthi]

We are using Saxon: HE (Home Edition) for XAPTH 2 functions. AFAIK, we don't select functionality to support so anything supported by library should already be there, which means it's likely HE edition does not contain function you're looking for. Please have a look at [1].


On Thu, Aug 4, 2016 at 6:57 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi ESB Team,

Please find the summary of issues encountered while testing the XPath 2.0 functions at [1] ( referred [2] & [3] for syntax) and really appreciate your input on this


1. "Invalid XPath Syntax" occurs when saving the synapse configuration in management console

This error occurs for below functions:
  • avg- fn:avg((1,2,3,4,5))
  • codepoints-to-string - fn:codepoints-to-string((97, 32, 98, 32, 99)))
  • distinct-values - fn:distinct-values( ('a', 'b', 'a') ) -This is supported when passing the value as an xml payload
  • id - //book/section/secRef/fn:id(@refs)
  • idref - //book/idref('language')/string(.)
  • index-of - fn:index-of( (4, 5, 6, 4), 4)
  • max- fn:max((2,3,5))
  • min - fn:min((2,3,5))
  • remove - fn:remove( ('a', 'b', 'c'), 2)
  • reverse - fn:reverse((1, 2, 3, 4, 5))  -This is supported when passing the value as an xml payload
  • string-join - string-join( ('a', 'b', 'c'), '')
  • subsequence - fn:subsequence(('a', 'b', 'c', 'd', 'e'), 3)

2. Issues in using error() function

According to https://www.w3.org/TR/xpath-functions-30/#ERRFOER0000 , calling the function with empty parameters should give an unidentified error. But when invoking the service it gives below exception

Is this accepted?

ERROR - SynapseXPath Evaluation of the XPath expression fn:error() resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Error signalled by application call on error()
at net.sf.saxon.functions.Error.error(Error.java:98)
at net.sf.saxon.functions.Error.evaluateItem(Error.java:55)
at net.sf.saxon.expr.Expression.iterate(Expression.java:429)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:326)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:389)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:533)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)


3. "System function is not available with this host language/version" occurs when invoking the service

According to https://sourceforge.net/p/saxon/mailman/saxon-help/thread/50F7F8B9.4090108@.../, it seems this is an XSLT function, is that the reason for getting the below error?  but at [1] this function is declared as an XPath function


[2016-08-02 12:47:27,875] ERROR - SynapseXPath Evaluation of the XPath expression fn:format-date(fn:current-date(), '[Y01]/[M01]/[D01]') resulted in an error
net.sf.saxon.trans.XPathException: System function format-date#2 is not available with this host language/version
at net.sf.saxon.expr.parser.ExpressionParser.grumble(ExpressionParser.java:263)
at net.sf.saxon.expr.parser.ExpressionParser.parseFunctionCall(ExpressionParser.java:2375)
at net.sf.saxon.expr.parser.ExpressionParser.parseBasicStep(ExpressionParser.java:1731)
at net.sf.saxon.expr.parser.ExpressionParser.parseStepExpression(ExpressionParser.java:1654)
at net.sf.saxon.expr.parser.ExpressionParser.parseRelativePath(ExpressionParser.java:1573)
at net.sf.saxon.expr.parser.ExpressionParser.parsePathExpression(ExpressionParser.java:1557)
at net.sf.saxon.expr.parser.ExpressionParser.parseUnaryExpression(ExpressionParser.java:1447)
at net.sf.saxon.expr.parser.ExpressionParser.parseExprSingle(ExpressionParser.java:517)
at net.sf.saxon.expr.parser.ExpressionParser.parseExpression(ExpressionParser.java:455)
at net.sf.saxon.expr.parser.ExpressionParser.parse(ExpressionParser.java:391)
at net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:94)
at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:235)
at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

4. Error in using insert-before() function


According to https://docs.marklogic.com/fn:insert-before if the function written as 
fn:insert-before('a', 0, 'x'), then it gives the below error when invoking the service

If the position casts to xs:integer as fn:insert-before('a', xs:integer(0), 'x') and invoke the service then the result only has 'x' but the expected result should be 'x,a'


[2016-08-02 14:39:23,625] ERROR - SynapseXPath Evaluation of the XPath expression fn:insert-before('a', 1, 'x') resulted in an error
; Line#: 1; Column#: -1
net.sf.saxon.trans.XPathException: Required item type of second argument of fn:insert-before() is xs:integer; supplied value has item type xs:decimal
        at net.sf.saxon.expr.parser.TypeChecker.staticTypeCheck(TypeChecker.java:404)
        at net.sf.saxon.functions.SystemFunction.checkArgument(SystemFunction.java:117)
        at net.sf.saxon.functions.SystemFunction.checkArguments(SystemFunction.java:100)
        at net.sf.saxon.expr.FunctionCall.typeCheck(FunctionCall.java:134)
        at net.sf.saxon.expr.parser.ExpressionVisitor.typeCheck(ExpressionVisitor.java:206)
        at net.sf.saxon.xpath.XPathEvaluator.createExpressionInternal(XPathEvaluator.java:239)
        at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:376)
        at org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:532)
        at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:367)
        at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
        at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:223)
        at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:146)
        at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:132)
        at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:101)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:54)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
        at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:210)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:398)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:145)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)



5. nilled() function always gives the result as false


payload:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <child>12</child> <child xsi:nil="true"></child> <child></child> <child/> <child xsi:nil="false"></child> </root>

function: fn:nilled(//child[1])

For all child elements it gives false ( even for the elements which has xsi:nil)


6. root() function does not give the root element


payload:

<a>
  <x>123</x>
</a>

function: fn:root(//x)

result : 123

expected result : 
<a>
  <x>123</x>
</a>


7. Using the function static-base-uri()


Can someone please mention how to define the function and the usage?



8. Using the function unordered()


payload :

<a>
  <x>1</x>
 <x>2</x>
 <x>3</x>
</a>

function: fn:unordered(//x)

result : 1

Can someone please explain the usage of this function? it seems the expected result should be a sequence of items




-more information on the testing results can be found at [4]

-Further, when going through the functions at [1] it seems below functions are only supported for XSLT ( I guess we don't need to support those functions when considering the XPath 2.0 functions, please correct me if I'm wrong)


functions:
  • current
  • current-group
  • current-grouping-key
  • document
  • element-available
  • function-available
  • generate-id(http://www.xsltfunctions.com/xsl/fn_generate-id.html)
  • regex-group
  • system-property
  • type-available
  • unparsed-entity-public-id
  • unparsed-entity-uri
  • unparsed-text
  • unparsed-text-available

- XPath 3.0 functions listed at [1]

acos ,analyze-string,asin,atan,ata2,available-environment-variables,cos,element-with-id,environment-variable,exp,exp10,filter,fold-left,fold-right,format-integer,function-arity,function-lookup,function-name,has-children,head,innermost,log,log10,map,map-pairs,outermost,parse-json,parse-xml ,path,pi,pow,round,serialize,serialize-json,sin,sqrt,tail,tan,unparsed-text-lines,uri-collection




Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 4:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
According to [1] if I test the distinct-values function,it behaves as explained below:


1. If I use a rest mock service to get the response and then get the distinct values :

Rest mock service response:

<catalog xml:base="http://example.org/ACC/"> <product dept="WMN"> <number>557</number> <number>44</number>
<number>44</number> </product> </catalog>

Rest API:

<api xmlns="http://ws.apache.org/ns/synapse" name="sample123" context="/test123"> <resource methods="POST GET"> <inSequence> <send> <endpoint> <address uri="http://localhost:8080/getResult"/> </endpoint> </send> </inSequence> <outSequence> <log level="custom"> <property xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns="http://org.apache.synapse/xsd" xmlns:base="http://test" name="testValue" expression="fn:distinct-values(//product/*)"/>
</log> </outSequence> </resource> </api>


Then expected result is : 557, 44

But I am getting only 557

Am I missing something here?

2. If I directly use this function as below

       name="testProxy"
       transports="http https"
       startOnLoad="true">
   <description/>
   <target>
      <inSequence>
         <log level="custom">
            <property xmlns:fn="http://www.w3.org/2005/xpath-functions"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:distinct-values(('a', 'b', 'a'))"/>
         </log>
      </inSequence>
      <outSequence/>
   </target>
</proxy>

Then I'm getting the exception "invalid XPapth expression" in saving the proxy

But according to [1] it seems both ways are correct



Thanks,
Sohani

Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 3:54 PM, Sohani Weerasinghe <[hidden email]> wrote:



Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 1:28 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

It seems, the " Invalid XPapth expression" comes when we use two brackets in the function as below


While I was testing further I found that below function works perfectly even it has two brackets, so that means the syntax of the above mentioned functions are correct. 

So, are these functions not supported in ESB? Appreciate your input on this

fn:dateTime(xs:date('2006-08-15'), xs:time('12:30:45-05:00')) 


fn:codepoints-to-string((2309, 2358, 2378, 2325))
fn:string-join(('a', 'c'), 'bbb')






Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774

On Mon, Aug 1, 2016 at 12:06 PM, Sohani Weerasinghe <[hidden email]> wrote:
Hi All,

I am validating the Xpath 2.0 functions support in ESB ( please refer [1]) and I am using below configuration in defining 'avg' function (Referred [2]), but it seems I am using the wrong syntax. 

                      xmlns:test="http://test"
                      xmlns:ns="http://org.apache.synapse/xsd"
                      name="testValue"
                      expression="fn:avg((3,4,5))"/>

Can someone please point the correct syntax?

Since avg function requires a single parameter, is there a way to define the integer values externally ( may be using a property mediator ) and use it inside the function ?

If this syntax is correct, is this function not supported in ESB?

Really appreciate your input on this

FYI: When saving the proxy, I'm getting below exception:

[2016-08-01 11:41:11,718] ERROR - ProxyServiceAdmin Unable to save changes made for the proxy service : testProxy. Restored the existing proxy... :: Invalid XPapth expression : fn:avg((3,4,5))
org.apache.synapse.SynapseException: Invalid XPapth expression : fn:avg((3,4,5))
at org.apache.synapse.config.xml.MediatorPropertyFactory.getMediatorProperties(MediatorPropertyFactory.java:106)
at org.apache.synapse.config.xml.LogMediatorFactory.createSpecificMediator(LogMediatorFactory.java:111)
.......



[1] Xpath 2.0.0 functions supported by ESB
[2] https://www.w3.org/TR/xpath-functions/#func-avg
Sohani Weerasinghe
Senior Software Engineer
WSO2, Inc: http://wso2.com

Mobile  : <a href="tel:%2B94%20716439774" value="+94716439774" target="_blank">+94 716439774







--
Regards,
Shafreen
Software Engineer
WSO2 Inc
Mobile : 077-556-395-1




--
Regards,
Shafreen
Software Engineer
WSO2 Inc
Mobile : 077-556-395-1


_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev




--
Sashika Wijesinghe
Software Engineer - QA Team

Mobile : +94 (0) 774537487

_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev