SimpleDateFormat and Date:new how can I simply report a date in the future? XSLT, XML1.0, Java

后端 未结 2 2000
無奈伤痛
無奈伤痛 2021-01-24 01:08

I need to add 90 days to the current date populated in the 2nd half of this code. I\'ve attached the resulting XML below (using xml1.0 and xalan 2.7.1), it looks great i just ne

相关标签:
2条回答
  • 2021-01-24 02:08

    I see you are trying to do this with Java extensions. I don't know if and how this can work, but I can suggest a purely (almost) XSLT 1.0 solution. The following stylesheet:

    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:variable name="today" select="date:date()" />
    
    <xsl:template match="/">
        <output>
            <start>
                <xsl:value-of select="concat(substring($today, 6, 2), '-', substring($today, 9, 2), '-', substring($today, 1, 4))" />
            </start>
            <end>
                <xsl:call-template name="add-days-to-today">
                    <xsl:with-param name="days-to-add" select="90" />
                </xsl:call-template>
            </end>
        </output>
    </xsl:template> 
    
    <xsl:template name="add-days-to-today">
        <xsl:param name="days-to-add"/>
        <xsl:param name="year" select="substring($today, 1, 4)"/>
        <xsl:param name="month" select="substring($today, 6, 2)"/>
        <xsl:param name="day" select="substring($today, 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:param name="JDN" select="$day + floor((153*$m + 2) div 5) + 365*$y + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045 + $days-to-add" />
        <xsl:param name="f" select="$JDN + 1401 + floor((floor((4 * $JDN + 274277) div 146097) * 3) div 4) - 38"/>
        <xsl:param name="e" select="4*$f + 3"/>
        <xsl:param name="g" select="floor(($e mod 1461) div 4)"/>
        <xsl:param name="h" select="5*$g + 2"/>
        <xsl:param name="D" select="floor(($h mod 153) div 5 ) + 1"/>
        <xsl:param name="M" select="(floor($h div 153) + 2) mod 12 + 1"/>
        <xsl:param name="Y" select="floor($e div 1461) - 4716 + floor((14 - $M) div 12)"/>
        <xsl:param name="MM" select="format-number($M, '00')"/>
        <xsl:param name="DD" select="format-number($D, '00')"/>
        <xsl:value-of select="concat($MM, '-', $DD, '-', $Y)" />
    </xsl:template>     
    
    </xsl:stylesheet>
    

    when applied to any XML input (on Dec 11, 2014), returns:

    <?xml version="1.0" encoding="UTF-8"?>
    <output>
       <start>12-11-2014</start>
       <end>03-11-2015</end>
    </output>
    
    0 讨论(0)
  • 2021-01-24 02:11
    <xsl:element name="App_Data">
                        <xsl:attribute name="App">MOD</xsl:attribute> 
                        <xsl:attribute name="Name">Licensing_Window_Start</xsl:attribute> 
                        <xsl:attribute name="Value">
                            <xsl:variable name="today" select="date:date()" />
                            <xsl:choose>
                                <xsl:when test="add:FlightStart"><xsl:value-of select="substring(add:FlightStart,1,10)"/></xsl:when>
                                <xsl:otherwise>
                                    <output>
                                        <Licensing_Window_Start>
                                            <xsl:value-of select="concat(substring($today, 6, 2), '-', substring($today, 9, 2), '-', substring($today, 1, 4))" />
                                        </Licensing_Window_Start>
                                    </output>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                    </xsl:element>
                    <xsl:element name="App_Data">
                        <xsl:attribute name="App">MOD</xsl:attribute> 
                        <xsl:attribute name="Name">Licensing_Window_End</xsl:attribute> 
                        <xsl:attribute name="Value">
                            <xsl:variable name="today" select="date:date()" />
                            <xsl:choose>
                                <xsl:when test="add:FlightEnd"><xsl:value-of select="substring(add:FlightEnd,1,10)"/></xsl:when>
                                <xsl:otherwise>
                                        <output>
                                            <Licensing_Window_End>
                                                <xsl:call-template name="add-days-to-today">
                                                    <xsl:with-param name="days-to-add" select="90" />
                                                </xsl:call-template>
                                            </Licensing_Window_End>
                                        </output>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                    </xsl:element>
    

    Positioned the Variable Today and Template of Add-Day-To_Today at the top of the style sheet. Works Great. Thanks Again.

    0 讨论(0)
提交回复
热议问题