title: Conditions monitoring in datapower
body: <p>I have following request</p>
  
  <pre><code>URI: /IP/{Version}/Account/Payment
  HTTP Method: POST
  
  Custom Headers: 
  
   X-account-number
   X- account-type
   X-user-initials,
   X-dda-number
   X-dda-account-type
   X-number-of-days-gap
   X-send-ch-letter-flag 
   X-payment-date
   X-payment-option
  </code></pre>
  
  <p>Now what I have to do is I have to get the Payment date from the request  and then I have to check the following conditions</p>
  
  <blockquote>
    <p>if the payment date is not null and is a future date and is within 180
    days from today. If so then first do a lookup to make sure there is no
    future payment scheduled for this date</p>
    
    <p>If no payments for the date scheduled then insert the payment to 
    table</p>
    
    <p>Finally do the first select query again and retrieve the value</p>
  </blockquote>
  
  <p>I am trying to do it using XSLT and datapower</p>
  
  <p>but I am not getting the logic correct.</p>
  
  <p>Here is what I have tried</p>
  
  <pre><code>    &lt;xsl:stylesheet 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:dp="http://www.datapower.com/extensions"
   xmlns:dpconfig="http://www.datapower.com/param/config"
   xmlns:date="http://exslt.org/dates-and-times"
   extension-element-prefixes="dp date"
   exclude-result-prefixes="dp dpconfig"
   version="1.0" &gt;
  
  
  &lt;xsl:template match="/"&gt;
  
  &lt;AccountNumber&gt;&lt;xsl:value-of select="dp:http-request-header('X-account-number')"/&gt;&lt;/AccountNumber&gt;
  &lt;PaymentDate&gt;&lt;xsl:value-of select="dp:http-request-header('X-payment-date')"/&gt;&lt;/PaymentDate&gt;
  &lt;PaymentOption&gt;&lt;xsl:value-of select="dp:http-request-header('X-payment-option')"/&gt;&lt;/PaymentOption&gt;
  &lt;Amount&gt;&lt;xsl:value-of select="dp:http-request-header('X-amount')"/&gt;&lt;/Amount&gt;
  &lt;AccountType&gt;&lt;xsl:value-of select="dp:http-request-header('X-dda-account-type')"/&gt;&lt;/AccountType&gt;
  
  &lt;xsl:variable name="timestamp" select="date:date-time()"/&gt; 
  
  &lt;xsl:variable name="dateDifference" select="date:difference($timestamp,$PaymentDate)"/&gt;
  
  &lt;xsl:if "$dateDifference" &lt; '180' AND "$PaymentDate" != NULL&gt;
  
  &lt;xsl:variable name="LookUp" Select PAYMENT_STATUS_CODE FROM TABLE WHERE WHERE ACCT_NBR ='$ACCOUNTNUMBER' AND AND PMT_DATE = '$PaymentDate'/&gt;
  &lt;xsl:variable name ="RunQuery1"&gt;
  &lt;dp:sql-execute
      source="'XXXXX'"
      statement="$Lookup"&gt;
  &lt;/dp:sql-execute&gt;
  &lt;xsl:variable name="test" copy-of select ="$RunQuery1"/&gt;
  &lt;xsl:if test = NULL&gt;
  
  &lt;xsl:variable name="InsertQuery" Insert into TABLE(CREATED_DATE,ACCT_NBR,PMT_AMT_OPTION_CODE,AMOUNT,PMT_DATE,ACCOUNT_TYPE_CODE,PAYMENT_STATUS_CODE)
   VALUES('$timestamp','$ACCOUNTNUMBER','$PaymentOption','$Amount','$PaymentDate','$AccountType','P'/&gt;
  &lt;xsl:variable name="RunQuery2"&gt;
  &lt;dp:sql-execute
      source="'XXXXX'"
      statement="$InsertQuery"&gt;
  &lt;/dp:sql-execute&gt;
  &lt;/xsl:variable&gt;
  &lt;/xsl:if&gt;
  &lt;xsl:variable name="RetrieveQuery" SELECT PAYMENT_STATUS_CODE from TABLE/&gt;
  &lt;xsl:variable name="RunQuery3"&gt;
  &lt;dp:sql-execute
      source="'XXXXX'"
      statement="$RetrieveQuery"&gt;
  &lt;/dp:sql-execute&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:copy-of select="$RunQuery3"/&gt;
  
  &lt;/xsl:if&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>What I am doing incorrect?</p>