Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
4 replies Latest Post - ‏2013-02-12T00:08:17Z by HermannSW
SystemAdmin
SystemAdmin
6772 Posts
ACCEPTED ANSWER

Pinned topic Dynamic Xpath

‏2013-02-11T17:18:42Z |
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?

regards
UI
Updated on 2013-02-12T00:08:17Z at 2013-02-12T00:08:17Z by HermannSW
  • SystemAdmin
    SystemAdmin
    6772 Posts
    ACCEPTED ANSWER

    Re: Dynamic Xpath

    ‏2013-02-11T17:20:20Z  in response to SystemAdmin
    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']
    
    Updated on 2014-03-25T02:40:29Z at 2014-03-25T02:40:29Z by iron-man
    • kenhygh
      kenhygh
      1475 Posts
      ACCEPTED ANSWER

      Re: Dynamic Xpath

      ‏2013-02-11T18:55:25Z  in response to SystemAdmin
      can you just use
      /*[local-name()='Request']/*[local-name()='Operation]
      


      Ken
      Updated on 2014-03-25T02:40:24Z at 2014-03-25T02:40:24Z by iron-man
      • SystemAdmin
        SystemAdmin
        6772 Posts
        ACCEPTED ANSWER

        Re: Dynamic Xpath

        ‏2013-02-11T19:28:54Z  in response to kenhygh
        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.
        Updated on 2014-03-25T02:40:20Z at 2014-03-25T02:40:20Z by iron-man
        • HermannSW
          HermannSW
          4513 Posts
          ACCEPTED ANSWER

          Re: Dynamic Xpath

          ‏2013-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++
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          $
          $ xpath++ "/xs:schema" int.xsd
          <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <xsd:element name="num" type="xsd:int"/>
          </xsd:schema>
          $
          {code}
          Hermann <myXsltBlog/> <myXsltTweets/>
          Updated on 2014-03-25T02:40:12Z at 2014-03-25T02:40:12Z by iron-man