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).
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?
This topic has been locked.
4 replies Latest Post - 2013-02-12T00:08:17Z by HermannSW
Pinned topic Dynamic Xpath
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2013-02-12T00:08:17Z at 2013-02-12T00:08:17Z by HermannSW
Re: Dynamic Xpath2013-02-11T17:20:20Z in response to SystemAdminposting 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']
kenhygh 120000PD1B764 Posts
Re: Dynamic Xpath2013-02-11T19:28:54Z in response to kenhyghHello Ken,
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.
HermannSW 2700006U542740 PostsACCEPTED ANSWER
Re: Dynamic Xpath2013-02-12T00:08:17Z in response to SystemAdmin> Hello Ken,
> /*[local-name()='Request']/*[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.
For example the namespace prefix "xs" is declared in xpath++,
and it can match int.xsd although there is "xsd" prefix:
$ grep xmlns:xs= ~/bin/xpath++
$ xpath++ "/xs:schema" int.xsd
<xsd:element name="num" type="xsd:int"/>