gpt4 book ai didi

xslt - 无法放置格式化日期的逻辑

转载 作者:行者123 更新时间:2023-12-05 00:13:25 25 4
gpt4 key购买 nike

我正在尝试实现一个格式规则,其中我有一个日期为“1918-12-31T24:00:00Z”的输入字符串,我需要将其显示为“1/1/1918”。实现代码如下:

请注意值 relement="1918-12-31T24:00:00Z"或类似格式。

    <xsl:choose> 
<xsl:when test="not($relement)"/>
<xsl:when test="$relement = ''"/>
<xsl:otherwise>
<xsl:variable name="rdate" select="substring-before('$relement','T')"/>
<xsl:variable name="month" select="substring-before(substring-after($rdate,'-'),'-')"/>
<xsl:variable name="day" select="substring-after(substring-after($rdate,'-'),'-')"/>
<xsl:variable name="year" select="substring-before($rdate,'-')"/>
<xsl:variable name="time" select="substring-after('$relement','T')"/>

<xsl:variable name="lastdate">
<xsl:choose>
<xsl:when test="$month = 2 and not($year mod 4) and ($year mod 100 or not($year mod 400))">
<xsl:value-of select="29"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring('312831303130313130313031', 2 * $month - 1,2)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="dayadj">
<xsl:choose>
<xsl:when test="contains($time,'24:00:00Z')"> 2011-12-31T24:00:00Z
<xsl:value-of select="$day + '1'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$day"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="finaldate">
<xsl:choose>
<xsl:when test="$dayadj > $lastdate and ($month = 12)">
<xsl:value-of select="concat('1','/','1','/',$year + '1')"/>
</xsl:when>
<xsl:when test="$dayadj > $lastdate and ($month != 12)">
<xsl:value-of select="concat($month + '1','/','1','/',$year)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($month,'/',$dayadj,'/',$year)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:attribute name="internal"><xsl:value-of select="$arg1/@internal"/></xsl:attribute>
<xsl:value-of select="$finaldate"/>
</xsl:otherwise>
</xsl:choose>

上面的代码无法给出输出,因为我也找不到在月份和年份的最后一天应用验证的逻辑。

在所有情况下,我得到的错误输出都是:“////”。

最佳答案

两个问题:

1) 有两个地方可以引用 $relement变量,但你引用了它:'$relement' .这是使用文字字符串“$relement”而不是引用变量。

2) 你有看似随机的日期 2011-12-31T24:00:00Z在以 <xsl:when test="contains($time,'24:00:00Z')"> 开头的行的末尾

查看此 XSLTCake工作版本的演示。

关于xslt - 无法放置格式化日期的逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18332797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com