如何将 5 个工作日添加到现有值 xslt [英] How to add 5 business days to an existing value xslt

查看:25
本文介绍了如何将 5 个工作日添加到现有值 xslt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为DateSet"的字符串,其值为16/10/2008".我想为该值增加 5 个工作日.我假设我必须将该值转换为某个值,以便它知道这是一个日期.

I have a string called "DateSet" with the value "16/10/2008". I want to add 5 business days to that value. I assume i have to convert the value to something so that it knows it's a date.

我使用的是 xslt 1.0,并使用自定义软件将 xslt 转换为 Word 文档.现在显示:

I am using xslt 1.0, and using a custom software to convert xslt to a word document. Now it shows:

<w:p>
  <w:r>
    <w:t>Some text [DateSet]</w:t>
  </w:r>
</w:p>

凡 [DateSet] 16/10/2008

Where [DateSet] 16/10/2008

但我希望它显示的是:

<w:p>
  <w:r>
    <w:t>Some text [DateSet+5business days]</w:t>
  </w:r>
</w:p>

[DateSet+5 个工作日] 应该在哪里显示 23/10/2008

Where [DateSet+5business days] should be showing 23/10/2008

我需要使用 ms:format-date 并以某种方式转换它吗?

Do I need to use ms:format-date and convert it somehow?

推荐答案

我已尝试解决您的问题,但您需要增强此剪辑以满足您未来的需求.

I have tried to solve your problem, but you need to enhance this snipped for your future requirement.

对于 XSLT 1.0,您需要导入一些扩展库,您可以在 http://xsltsl.sourceforge.net/找到它,下载http://prdownloads.sourceforge.net/xsltsl/xsltsl-1.2.1.zip ZIP 文件并将其导入到我生成的 XSLT 中:

For XSLT 1.0 you need to import some extension library which you may find at http://xsltsl.sourceforge.net/, download http://prdownloads.sourceforge.net/xsltsl/xsltsl-1.2.1.zip ZIP file and import it as given here in my generated XSLT:

XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="http://xsltsl.org/xsl/documentation/1.0" xmlns:dt="http://xsltsl.org/date-time"
  xmlns:str="http://xsltsl.org/string" xmlns:dp="http://www.dpawson.co.uk"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes"
  extension-element-prefixes="doc str">

  <xsl:import href="xsltsl-1.2.1/stdlib.xsl"/>
  <xsl:import href="xsltsl-1.2.1/date-time.xsl"/>
  <xsl:param name="CurrentDate">21/08/2013</xsl:param>
  <xsl:param name="CurrentYear" select="substring-after(substring-after($CurrentDate,'/'),'/')"/>
  <xsl:param name="CurrentMonth" select="substring-before(substring-after($CurrentDate,'/'),'/')"/>
  <xsl:param name="CurrentDay" select="substring-before($CurrentDate,'/')"/>

  <xsl:template match="/">
    <xsl:text>Current given Date is : </xsl:text><xsl:value-of select="$CurrentDate"/><xsl:text>&#10;</xsl:text>
    <xsl:call-template name="GetCompleteUpdatedDate">
      <xsl:with-param name="UpdatedDay">
        <xsl:call-template name="UpdateDay">
          <xsl:with-param name="CurrentDay" select="$CurrentDay"/>
          <xsl:with-param name="LastDayOfMonth">
            <xsl:call-template name="dt:calculate-last-day-of-month">
              <xsl:with-param name="month" select="$CurrentMonth"/>
            </xsl:call-template>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="LastDayOfMonth">
        <xsl:call-template name="dt:calculate-last-day-of-month">
          <xsl:with-param name="month" select="$CurrentMonth"/>
        </xsl:call-template>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="UpdateDay">
    <xsl:param name="LastDayOfMonth"/>
    <xsl:param name="CurrentDay"/>
    <xsl:param name="RequiredDaysAddition">5</xsl:param>
    <xsl:param name="SaturdaySundayCount">0</xsl:param>
    <xsl:variable name="DayOfWeek">
      <xsl:call-template name="dt:calculate-day-of-the-week">
        <xsl:with-param name="year" select="$CurrentYear"/>
        <xsl:with-param name="month" select="$CurrentMonth"/>
        <xsl:with-param name="day" select="$CurrentDay"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="DayAbbreviation">
      <xsl:call-template name="dt:get-day-of-the-week-abbreviation">
        <xsl:with-param name="day-of-the-week" select="$DayOfWeek"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$RequiredDaysAddition != 0">
        <xsl:choose>
          <xsl:when test="$DayAbbreviation = 'Sun' or $DayAbbreviation = 'Sat'">
            <xsl:call-template name="UpdateDay">
              <xsl:with-param name="LastDayOfMonth" select="$LastDayOfMonth"/>
              <xsl:with-param name="CurrentDay" select="$CurrentDay + 1"/>
              <xsl:with-param name="RequiredDaysAddition" select="$RequiredDaysAddition - 1"/>
              <xsl:with-param name="SaturdaySundayCount" select="$SaturdaySundayCount + 1"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="UpdateDay">
              <xsl:with-param name="LastDayOfMonth" select="$LastDayOfMonth"/>
              <xsl:with-param name="CurrentDay" select="$CurrentDay + 1"/>
              <xsl:with-param name="RequiredDaysAddition" select="$RequiredDaysAddition - 1"/>
              <xsl:with-param name="SaturdaySundayCount" select="$SaturdaySundayCount"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$CurrentDay + $SaturdaySundayCount"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="GetCompleteUpdatedDate">
    <xsl:param name="UpdatedDay"/>
    <xsl:param name="LastDayOfMonth"/>
    <xsl:variable name="NewMonth">
      <xsl:choose>
        <xsl:when test="$UpdatedDay &gt; $LastDayOfMonth">
          <xsl:choose>
            <xsl:when test="($CurrentMonth + 1) = 12 or ($CurrentMonth + 1) &lt; 12">
              <xsl:value-of select="$CurrentMonth + 1"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="($CurrentMonth + 1) - 12"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$CurrentMonth"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="NewYear">
      <xsl:choose>
        <xsl:when test="($CurrentMonth + 1) &gt; 12">
          <xsl:value-of select="$CurrentYear + 1"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$CurrentYear"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="IsNewYearLeapYear">
      <xsl:call-template name="IsYearLeapYear"><xsl:with-param name="Year" select="$NewYear"/></xsl:call-template>
    </xsl:variable>
    <xsl:variable name="NewDay">
      <xsl:choose>
        <xsl:when test="$UpdatedDay &gt; $LastDayOfMonth">
          <xsl:value-of select="$UpdatedDay - $LastDayOfMonth"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$UpdatedDay"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:text>Updated date is : </xsl:text><xsl:value-of select="concat(format-number($NewDay,'00'), '/', format-number($NewMonth,'00'), '/', $NewYear)"/>
  </xsl:template>

  <xsl:template name="IsYearLeapYear">
    <xsl:param name="Year"/>
    <xsl:choose>
      <xsl:when test="($Year mod 4 = 0 and $Year mod 100 != 0) or $Year mod 400 = 0">True</xsl:when>
      <xsl:otherwise>False</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

您只需要更改 $CurrentDate 值即可检查其输出.

You just need to change $CurrentDate value to check its output.

输入:

21/08/2013

输出:

Current given Date is : 21/08/2013
Updated date is : 28/08/2013

输入:

16/10/2008

输出:

Current given Date is : 16/10/2008
Updated date is : 23/10/2008

这篇关于如何将 5 个工作日添加到现有值 xslt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆