Pinned topicDynamic Xpath

‏2013-02-11T17:18:42Z
|Tags:

Answered question
This question has been answered.

Unanswered question
This question has not been answered yet.

Hello,
I need to execute dynamic xpath (xpath is stored in variable) on incoming message, which is perfectly working using dyn:evaluate($xpath_Variable) function, but the problem is this requires the xpath to be in specific format as it include new namespace prefixs and URI which are not declared in stylesheet (not known at design time).

Ex:
If I need to execute /ma:Request/ma:operation where ma is : http://rp.bankofamerica.com/canonical/MathCalculatorV001 which is not known to stylesheet then my dynamic xpath variable should look like
“
/*/
*

“

Which becomes more ugly or difficult to read/construct if my xpath contains 10 levels deep.

So provided that if I know this URI (reading some xml file) and given xpath as “/ma:Request/ma:operation” is there better way of executing the dynamic xpath without constructing something like above. are there any other datapower extension functions available to this job?

Re: Dynamic Xpath

‏2013-02-11T17:20:20Z

This is the accepted answer.
This is the accepted answer.

posting missing expression in above query

/*[namespace-uri()='http://rp.bankofamerica.com/canonical/MathCalculatorV001' and local-name()=’Request’]/ *[namespace-uri()='http://rp.bankofamerica.com/canonical/MathCalculatorV001' and local-name()='Operation']

>
> this approach will work only when executing stylesheet have namespaces already defined but in my case executing stylesheet will not have namespace URI's defined at the top.
>
No, Ken's XPath statement does not use namespace prefixes which have to be defined.

You can even use eg. "namespace-uri()='http://blah'" as part of the XPath without problems.

Whenever you use namespace prefixes, they need to be defined in the stylesheet.
This is a basic XPath/XSLT requirement.

The reason is that the namespace URI for prefixes will be resolved to do the match.

> Hello Ken,
>
<pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">> /*[local-name()='Request']/*[local-name()='Operation] > >
</pre>
>
> this approach will work only when executing stylesheet have namespaces already defined but in my case executing stylesheet will not have namespace URI's defined at the top.
>
No, Ken's XPath statement does not use namespace prefixes which have to be defined.

You can even use eg. "namespace-uri()='http://blah'" as part of the XPath without problems.

Whenever you use namespace prefixes, they need to be defined in the stylesheet.
This is a basic XPath/XSLT requirement.

The reason is that the namespace URI for prefixes will be resolved to do the match.