Topic
  • 3 replies
  • Latest Post - ‏2012-03-22T20:16:45Z by SystemAdmin
SystemAdmin
SystemAdmin
6772 Posts

Pinned topic Datapower XSLT Xpath function

‏2012-03-21T18:25:26Z |
hello,
What function can be used in the stylesheet that is getting executed in DataPower for below requirement

Xpath is stored in xsl variable (ex <xsl:variable name="xpaction" select="'/Math/Operation/Action"/>)

now i want to evaluate the xpath " /Math/Operation/Action" using variable "xpaction".

what DP extension function can be used so that if incoming message

<Math><Operation><Action>Add</Action></Operation></Math>

will return "Add"

thank you
regards
IU
Updated on 2012-03-22T20:16:45Z at 2012-03-22T20:16:45Z by SystemAdmin
  • swlinn
    swlinn
    1348 Posts

    Re: Datapower XSLT Xpath function

    ‏2012-03-21T20:16:09Z  
    dyn:evaluate(string) where string is your xpath. It's documented in the extension guide. Don't forget to add the dyn namespace to your stylesheet. I've always been cautious about using evaluate as I'd thought there could be some performance concerns. Another approach to a dynamic xpath, if the xpath depth were the same, would be

    /*[local-name() = $level1]/*[local-name() = $level2] ... etc
    


    Regards,
    Steve
    Updated on 2014-03-25T02:59:17Z at 2014-03-25T02:59:17Z by iron-man
  • HermannSW
    HermannSW
    4903 Posts

    Re: Datapower XSLT Xpath function

    ‏2012-03-22T01:23:07Z  
    • swlinn
    • ‏2012-03-21T20:16:09Z
    dyn:evaluate(string) where string is your xpath. It's documented in the extension guide. Don't forget to add the dyn namespace to your stylesheet. I've always been cautious about using evaluate as I'd thought there could be some performance concerns. Another approach to a dynamic xpath, if the xpath depth were the same, would be

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">/*[local-name() = $level1]/*[local-name() = $level2] ... etc </pre>

    Regards,
    Steve
    Steve is right, you need dyn:evaluate().
    As for all EXSLT extension functions the DataPower documentation is minimal.
    Find specific documentation on exslt.org, especially:
    http://exslt.org/dyn/functions/evaluate/index.html

    Here you see dyn:evaluate() in action for your sample and the stylesheet dyn4.xsl:
    
    $ echo 
    "<Math><Operation><Action>Add</Action></Operation></Math>" | \ > coproc2 dyn4.xsl - http:
    //dp5-l3:2223; echo <result>Add</result> $ $ cat dyn4.xsl <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dyn=
    "http://exslt.org/dynamic" exclude-result-prefixes=
    "dyn" > <xsl:output omit-xml-declaration=
    "yes"/>   <xsl:variable name=
    "xpaction" select=
    "'/Math/Operation/Action'"/>   <xsl:template match=
    "/"> <result><xsl:value-of select=
    "dyn:evaluate($xpaction)"/></result> </xsl:template>   </xsl:stylesheet> $
    


     
    Hermann<myXsltBlog/>
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Datapower XSLT Xpath function

    ‏2012-03-22T20:16:45Z  
    thank you both. it is really helpful.