Search code examples
xmlxsltxsdwsdlmule

if -else condition in .xslt file in MULE


In my configuration.xml in MULE server 3.3.0 I pass MULE_REMOTE_CLIENT_ADDRESS to .xslt file, below I copied my codes :

<logger 
  message="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" 
  level="INFO" doc:name="Logger"/>

To pass IP address to XSLT, store it in a variable and pass that.

<set-variable 
  variableName="remoteClientAddress" 
  value = "#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]"/>

Pass it to XSLT as:

<xm:xslt-transformer xsl-file="xsltFileName.xslt">
  <xm:context-property 
    key="remoteClientAddress" 
    value="#[remoteClientAddress]"/>
</xm:xslt-transformer>

In my XSLT, declared a param variable

<xsl:param  name="remoteClientAddress" />

and then use this variable as

<xsl:value-of select="$remoteClientAddress" />

Now I want to check $remoteClientAddress in .xslt file, that if it was equal to specific ip_address, then I could change in my XML(WSDL) file and if it wasn't equal nothing happen in my XML(WSDL) file.

How can I do it?


Solution

  • Based on previous posts you've made, my understanding is that you want to omit a particular part of the input XML if this match is true. In that case, the following should be able to accomplish that (when added to your existing XSLT):

    <xsl:template match="wsdl:operation[@name = 'GetISD']">
       <xsl:variable name="rcaTrimmed" 
              select="substring-before(substring-after($remoteClientAddress, '/'), ':')" />
       <xsl:if test="$rcaTrimmed != '123.12.12.123'">
          <xsl:copy>
             <xsl:apply-templates select="@* | node()" />
          </xsl:copy>
       </xsl:if>
    </xsl:template>
    

    This will include the operation only if the $remoteClientAddress is not equal to the specified address.