How do we test whether a date is within 180 days from today in xslt in datapower

前端 未结 3 787
生来不讨喜
生来不讨喜 2020-12-12 04:39

I am writing an xslt for datapower and in that I am getting a date(Payment Date).I have to check whether that date(Paymentt Date) is within 180 days of current date

相关标签:
3条回答
  • 2020-12-12 05:07

    IBM Datapower provides extension to existing EXSLT function. There is a function called 'difference' with following signature.

    difference() Returns the duration between the first date and the second date. Syntax date:difference(start-dateTime, end-dateTime)

    You can utilize this function to find out the date-difference. For more information about extension function available in datapower see below link. Go to Chapter 5 and look for functions for manipulating 'date time'.

    http://pic.dhe.ibm.com/infocenter/wsdatap/v3r8m1/topic/xm70/ExtensionFunctions.pdf

    -Ajitabh

    0 讨论(0)
  • 2020-12-12 05:15

    Calculating date difference in XSLT 1.0:

    <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:date="http://exslt.org/dates-and-times"
    extension-element-prefixes="date">
    
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    
    <xsl:template match="/">
        <output>
            <difference>
                <xsl:call-template name="date-difference">
                    <xsl:with-param name="date1" select="input/originalDate" />
                    <xsl:with-param name="date2" select="date:date-time()" />
                </xsl:call-template>
            </difference>
        </output>
    </xsl:template> 
    
    <xsl:template name="date-difference">
        <xsl:param name="date1"/>
        <xsl:param name="date2"/>
        <xsl:param name="JDN1">
            <xsl:call-template name="JDN">
                <xsl:with-param name="date" select="$date1" />
            </xsl:call-template>
        </xsl:param>
        <xsl:param name="JDN2">
            <xsl:call-template name="JDN">
                <xsl:with-param name="date" select="$date2" />
            </xsl:call-template>
        </xsl:param>
        <xsl:value-of select="$JDN2 - $JDN1"/>
    </xsl:template> 
    
    <xsl:template name="JDN">
        <xsl:param name="date"/>
        <xsl:param name="year" select="substring($date, 1, 4)"/>
        <xsl:param name="month" select="substring($date, 6, 2)"/>
        <xsl:param name="day" select="substring($date, 9, 2)"/>
        <xsl:param name="a" select="floor((14 - $month) div 12)"/>
        <xsl:param name="y" select="$year + 4800 - $a"/>
        <xsl:param name="m" select="$month + 12*$a - 3"/>
        <xsl:value-of select="$day + floor((153*$m + 2) div 5) + 365*$y + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045" />
    </xsl:template> 
    
    </xsl:stylesheet>
    

    When applied to the following input XML:

    <input>
        <originalDate>2013-09-15</originalDate>
    </input>
    

    The result will be:

    <?xml version="1.0" encoding="UTF-8"?>
    <output>
      <difference>179</difference>
    </output>
    

    if the transformation is performed today, 2014-03-13.

    0 讨论(0)
  • 2020-12-12 05:26

    DataPower Supports Date:Difference

    difference()

    Returns the duration between the first date and the second date. Syntax

    date:difference(start-dateTime, end-dateTime)

    You can pass current date as end-DateTime , date which wants to check as start-DateTime

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
    xmlns:date="http://exslt.org/dates-and-times" version="1.0">
    <!--<xsl:key name="lang" match="element" use="@language"></xsl:key>-->
    <xsl:template match="/">
        <xsl:variable name="date1" select="date:date-time()"/>
        <xsl:variable name="date2" select="'2013-09-15'"/>
        <output>
            <difference>
        <xsl:value-of select="translate(date:difference($date2, $date1),'PD','')"/>
            </difference>
        </output>
    </xsl:template>
    </xsl:stylesheet>
    
    0 讨论(0)
提交回复
热议问题