Evaluating xpath expressions

This week we were messing around with a routing problem in one of the Oracle Service Bus projects.
We had an if-then-else construction which selects on the payload to see what transformation is needed and which business service it needs to call.

Example payload


result : node SYNTAX_ID with value ‘VALUE1’

test2 : count(/EDI/CONF_UNB/SYNTAX_ID) = 1
result : xs:boolean = true

result : xs:boolean = true

test4 : count(/EDI/CONF_UNB/SYNTAX_ID = ‘VALUE1’)
result : xs:integer = 1
This is the approach we used, but looking at the result of test5, you will see it will always evaluate to true or 1 in this case.

test5 : count(/EDI/CONF_UNB/SYNTAX_ID = ‘VALUE2’)
result : xs:integer = 1

test6 : count(/EDI/CONF_UNB/SYNTAX_ID[text() = ‘VALUE2’])
result : xs:integer = 0

test7 : count(/EDI/CONF_UNB/SYNTAX_ID[text() = ‘VALUE1’])
result : xs:integer = 1

So for evaluation the xpath expression without being it embedded in an xquery function you can just select the node and compair it with a textvalue (/EDI/CONF_UNB/SYNTAX_ID = ‘VALUE1’).
When you want to compair the xpath expression with a textvalue from within a call to a xquery function you need to select the text-value of the node to which you compair (count(/EDI/CONF_UNB/SYNTAX_ID[text() = ‘VALUE2’])).

Routing works again!
Original blog

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>