Xslt将日语时间输出转换为英语时间

时间:2015-11-05 09:59:24

标签: xslt sharepoint

我有一个共享点列表,其中日期时间存储为“平成27/7/14”,当我使用行显示日期列的xsl时

<xsl:value-of select="ddwrt:FormatDateTime(concat(substring(string(@PeriodFrom),4,3),substring(string(@PeriodFrom),1,3),substring(string(@PeriodFrom),7,4)),1033,'yyyy/MM/dd')"></xsl:value-of>**

我收到空白输出。请求帮助我这方面

1 个答案:

答案 0 :(得分:0)

以下XSLT 1.0模板会将日本帝国日期转换为格里高利,并将其输出为YYYY-MM-DD

<xsl:template name="imperial-to-gregorian">
    <xsl:param name="imperial-date"/>

    <xsl:variable name="era" select="substring-before($imperial-date, ' ')"/>
    <xsl:variable name="date" select="substring-after($imperial-date, ' ')"/>

    <xsl:variable name="imperial-year" select="substring-before($date, '/')"/>
    <xsl:variable name="month" select="substring-before(substring-after($date, '/'), '/')"/>
    <xsl:variable name="day" select="substring-after(substring-after($date, '/'), '/')"/>

    <xsl:variable name="offset">
        <xsl:choose>
            <xsl:when test="$era='平成'">1988</xsl:when>
            <xsl:when test="$era='昭和'">1925</xsl:when>
            <xsl:when test="$era='大正'">1911</xsl:when>
            <xsl:when test="$era='明治'">1867</xsl:when>
            <xsl:when test="$era='慶応'">1864</xsl:when>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="year" select="$imperial-year + $offset"/>

    <xsl:value-of select="format-number($year, '0000')"/>
    <xsl:value-of select="format-number($month, '-00')"/>
    <xsl:value-of select="format-number($day, '-00')"/>
</xsl:template>

电话示例:

<start>
  <xsl:call-template name="imperial-to-gregorian">
      <xsl:with-param name="imperial-date" select="@PeriodFrom"/>
  </xsl:call-template>
</start>

PeriodFrom ="平成 27/7/14"时的结果:

<start>2015-07-14</start>