DataPower

 View Only
  • 1.  Use dp:variable into Conditional Action

    Posted 22 days ago

    Hi community:

    I am investigating how to use a conditional action with dp:variable to apply x or y condition into conditional action. Is it possible? Or only works with XML structure?

    Ej:

    if contains(dp:variable('var://service/URI'),'ABC') set variable 1

    if contains(dp:variable('var://service/URI'),'XYZ') set variable 2

    so on

    I would like to avoid use xsl to apply this condition

    Regards



    ------------------------------
    David Bonilla
    ------------------------------


  • 2.  RE: Use dp:variable into Conditional Action

    IBM Champion
    Posted 22 days ago

    I was trying this years ago and it wasn't working then (or I couldn't figure out how), and I suspect it has something to do with the lack of being able to define the 'dp' namespace in the conditional snippet.   I'll provide "my" solution, though I am interested to see if there are others.

    So, I developed a tiny XSLT to write a variable's value to a simple XML for use in conditionals.

    Here's the code below.  It has one parameter, into which you put the variable name without the "var://" prefix.  In your situation, you'd enter "service/URI" into the variable name field.   There are a couple of debugging statements to view in a debug level log when needed.

    <?xml version="1.0" encoding="UTF-8"?>
    <!--  ==================================================== --> 
    <!-- Converts a variable value to XML.  This is ideal for conditional processing   -->
    <!--  ==================================================== --> 
    <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:dp="http://www.datapower.com/extensions"
        xmlns:dpconfig="http://www.datapower.com/param/config" 
        extension-element-prefixes="dp dpconfig" 
        exclude-result-prefixes="dp">
    
      <!-- ================================================ -->
      <!-- Name of variable containing the value to put into the xml document --> 
      <!-- ================================================ -->
      <xsl:param name="dpconfig:variableName" /> 
      <dp:param name="dpconfig:variableName" type="dmString" xmlns="">
        <tab-override>basic</tab-override>
        <display>Variable Name</display> 
        <description>The name of the variable whose value will be stored in the xml content without the 'var://' part</description> 
      </dp:param>
      
      <xsl:template match="/">
    	  <xsl:variable name="dpVar" select="dp:variable(concat('var://', $dpconfig:variableName))"/>
    
    	  <xsl:message dp:priority="debug">Entered Variable Name: <xsl:value-of select="$dpconfig:variableName"/></xsl:message>
    	  <xsl:message dp:priority="debug">Entered Variable Value: <xsl:value-of select="$dpVar"/></xsl:message>
      
    	  <xsl:element name="xml">
    		  <xsl:element name="var">
    			  <xsl:value-of select="$dpVar"/>
    		  </xsl:element>
    	  </xsl:element>
      </xsl:template>
    </xsl:stylesheet>
    



    ------------------------------
    Joseph Morgan
    ------------------------------



  • 3.  RE: Use dp:variable into Conditional Action

    Posted 22 days ago

    "... and I suspect it has something to do with the lack of being able to define the 'dp' namespace in the conditional snippet. ..."
    That is correct.



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support, IBM DataPower Gateways
    IBM
    Boeblingen
    ------------------------------