1

私は datapower の xslt を作成しており、その中で日付 (支払日) を取得しています。その日付 (支払日) が現在の日付から 180 日以内であるかどうかを確認する必要があります。

次の方法で現在の日付を取得しています

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

今すぐ180日間の状態を確認する方法

以下は私のxsltです

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dp="http://www.datapower.com/extensions"
    xmlns:date="http://exslt.org/dates-and-times"
    xmlns:dpconfig="http://www.datapower.com/param/config"
    extension-element-prefixes="dp"
    exclude-result-prefixes="dp dpconfig"
>

  <xsl:output method="xml"/>

  <xsl:template match="/">
<PaymentDate><xsl:value-of select="dp:http-request-header('X-payment-date')"/></PaymentDate>  (From request I am getting payment date)

<xsl:variable name="timestamp" select="date:date-time()"/>        (From here I am getting present date)

<xsl:if  (this is what I am confused)

ありがとう

4

3 に答える 3

3

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>

次の入力 XML に適用した場合:

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

結果は次のようになります。

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

変換が今日、2014 年 3 月 13 日に実行された場合。

于 2014-03-13T11:27:18.413 に答える