DataPower

DataPower

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

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

    Posted Wed June 12, 2024 12:51 PM

    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

    Posted Wed June 12, 2024 01:52 PM

    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 Thu June 13, 2024 02:52 AM

    "... 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
    ------------------------------