1

I have following request

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

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

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

If no payments for the date scheduled then insert the payment to table

Finally do the first select query again and retrieve the value

I am trying to do it using XSLT and datapower

but I am not getting the logic correct.

Here is what I have tried

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


<xsl:template match="/">

<AccountNumber><xsl:value-of select="dp:http-request-header('X-account-number')"/></AccountNumber>
<PaymentDate><xsl:value-of select="dp:http-request-header('X-payment-date')"/></PaymentDate>
<PaymentOption><xsl:value-of select="dp:http-request-header('X-payment-option')"/></PaymentOption>
<Amount><xsl:value-of select="dp:http-request-header('X-amount')"/></Amount>
<AccountType><xsl:value-of select="dp:http-request-header('X-dda-account-type')"/></AccountType>

<xsl:variable name="timestamp" select="date:date-time()"/> 

<xsl:variable name="dateDifference" select="date:difference($timestamp,$PaymentDate)"/>

<xsl:if "$dateDifference" < '180' AND "$PaymentDate" != NULL>

<xsl:variable name="LookUp" Select PAYMENT_STATUS_CODE FROM TABLE WHERE WHERE ACCT_NBR ='$ACCOUNTNUMBER' AND AND PMT_DATE = '$PaymentDate'/>
<xsl:variable name ="RunQuery1">
<dp:sql-execute
    source="'XXXXX'"
    statement="$Lookup">
</dp:sql-execute>
<xsl:variable name="test" copy-of select ="$RunQuery1"/>
<xsl:if test = NULL>

<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'/>
<xsl:variable name="RunQuery2">
<dp:sql-execute
    source="'XXXXX'"
    statement="$InsertQuery">
</dp:sql-execute>
</xsl:variable>
</xsl:if>
<xsl:variable name="RetrieveQuery" SELECT PAYMENT_STATUS_CODE from TABLE/>
<xsl:variable name="RunQuery3">
<dp:sql-execute
    source="'XXXXX'"
    statement="$RetrieveQuery">
</dp:sql-execute>
</xsl:variable>
<xsl:copy-of select="$RunQuery3"/>

</xsl:if>
</xsl:template>
</xsl:stylesheet>

What I am doing incorrect?

Uselesssss
  • 2,127
  • 6
  • 28
  • 37

2 Answers2

1

Well, not sure about the entire script, but since the if statement is not correct, here is something that should be a starting point:

<xsl:if test="fn:days-from-duration($dateDifference) &lt; 180 and $PaymentDate != null">

the conversion function used is this.

The SQL variables are not correct. Please check the syntax on both how to define the queries and how to test the result of the SQL operation. There are many good examples on the Datapower info center.

Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
  • As we were told in [OP's other question](http://stackoverflow.com/a/22396335/3016153), IBM DataPower has an XSLT 1.0 processor, with substantial support for EXSLT extension functions. However, days-from-duration() is not part of EXSLT and is unavailable to any XSLT 1.0 processor. – michael.hor257k Mar 16 '14 at 18:00
  • XSLT 2.0 functions works just fine in IBM DataPower - actually, tested the sheet with this statement (without all SQL statements that require a database and are badly formatted) on a XI52.6.0.0.3 with good result. The XML managers Compile option policy of course has to be set to allow XSLT 2.0 sheets, but thats details. – Petter Nordlander Mar 16 '14 at 19:22
  • Well, I have no first-hand knowledge of it. I just looked at the PDF linked to in the aforementioned answer. – michael.hor257k Mar 16 '14 at 19:37
0
"$dateDifference" < '180'

Two Three things jump out:

  1. You cannot use < as a comparison operator; you need to use &lt; instead.

  2. The result of date:difference() is not a number.

  3. The syntax of the <xsl:if> statement is entirely wrong.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51