Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何向现有xslt值添加5个工作日_Xslt_Ms Word_Xslt 1.0 - Fatal编程技术网

如何向现有xslt值添加5个工作日

如何向现有xslt值添加5个工作日,xslt,ms-word,xslt-1.0,Xslt,Ms Word,Xslt 1.0,我有一个名为“DateSet”的字符串,值为“16/10/2008”。我想增加5个工作日的价值。我假设我必须将值转换为某个值,以便它知道这是一个日期 我正在使用XSLT1.0,并使用自定义软件将xslt转换为word文档。 现在它显示: <w:p> <w:r> <w:t>Some text [DateSet]</w:t> </w:r> </w:p> 某些文本[日期集] 其中[日期集]16/10/2008

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

我正在使用XSLT1.0,并使用自定义软件将xslt转换为word文档。 现在它显示:

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

某些文本[日期集]
其中[日期集]16/10/2008

但我想展示的是:

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

某些文本[日期集+5个工作日]
其中[日期集+5个工作日]应显示2008年10月23日


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

根据您的描述,听起来好像您已将日期字符串与上下文隔离,以便您可以使用它并用新日期替换它。好。如果这不是真的,你的第一个问题将是使它成为现实

扩展函数ms:format-date()可能会对您有所帮助,但我看不出有什么帮助

给定一个日期,我认为执行XSLT 1.0中所需的日期算法的最简单方法是:

  • 将日期转换为整数(例如朱利安日)
  • 执行日期算术
  • 将恢复整数转换为日期
  • 要将日期转换为整数,可以使用以下模板;它基于Robert G.Tantzen,“算法199:日历日期和朱利安日数之间的转换”CACM 6.8(1963年8月):444。它要求您从日期字符串中解析出年、月和日的数字,并将它们传递到参数中

    <xsl:template name="jday">
      <!--* JDay:  convert a triple of integers representing
      * Gregorian year, month, and day numbers to the
      * number of the Julian day beginning at noon on that
      * date.
      * Transcribed from Robert G. Tantzen, "Algorithm
      * 199:  Conversions between calendar date and Julian
      * day number" CACM 6.8 (Aug 1963): 444.
          *-->
      <xsl:param name="year" select="1963"/>
      <xsl:param name="month" select="08"/>
      <xsl:param name="day" select="13"/>
    
      <xsl:variable name="y">
    <xsl:choose>
      <xsl:when test="$month > 2">
        <xsl:value-of select="$year"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$year - 1"/>
      </xsl:otherwise>
    </xsl:choose>
      </xsl:variable>
      <xsl:variable name="m">
    <xsl:choose>
      <xsl:when test="$month > 2">
        <xsl:value-of select="$month - 3"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$month + 9"/>
      </xsl:otherwise>
    </xsl:choose>
      </xsl:variable>
      <xsl:variable name="d" select="$day"/>
      <xsl:variable name="c" select="floor($y div 100)"/>
      <xsl:variable name="ya" select="$y - 100 * $c"/>
    
      <!--* H holds the offset between Julian day 0
          * and the beginning of the common era.
          *-->
      <xsl:variable name="H" select="1721119"/>
      <!--* Calculate the Julian day that begins on the 
          * given date.
          *-->
      <xsl:value-of select="floor(($c * 146097) div 4) 
                + floor(($ya * 1461) div 4) 
                + floor((($m * 153) + 2) div 5) 
                + $d 
                + $H"/>
    
    </xsl:template>
    
    
    
    执行日期算术可能有点棘手:对于工作日,五个工作日之后的日期(我猜)是七个日历日之后的日期,除非该期间有假日。对于周末,我想五个工作日后的日期是下周五。给定一个儒略日数$j,您可以通过计算$j mod 7:0=周一,1=周二,…,6=周日得到一周中的哪一天。所以你的计算可能看起来像

    <xsl:choose>
      <xsl:when test="$j mod 7 = 5">
        <xsl:value-of select="$j + 6"/>
      </xsl:when>
      <xsl:when test="$j mod 7 = 6">
        <xsl:value-of select="$j + 5"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$j + 7"/>
      </xsl:otherwise>
    </xsl:choose>
    
    
    
    对于假期,你必须咨询一些你感兴趣的时期的外部信息来源;祝你好运

    可以使用以下模板将生成的日数转换回日历日期,该模板同样来自Tantzen 1963:

    <xsl:template name="jdate">
      <!--* JDate:  given a Julian day number, return an ISO
      * 8601 date.  
      * Transcribed from Robert G. Tantzen, "Algorithm
      * 199:  Conversions between calendar date and Julian
      * day number" CACM 6.8 (Aug 1963): 444.
          *-->
      <xsl:param name="j" select="2438255"/>
    
      <!--* dce:  days in the common era (i.e. since 
          * 0000-03-01; Tantzen uses 1 Mar, not 1 Jan,
          * as his epoch to simplify calculations). *-->
      <xsl:variable name="dce" select="$j - 1721119"/>
    
      <!--* cce:  full centuries in the common era. *-->
      <xsl:variable name="cce" 
                    select="floor((4 * $dce - 1) div 146097)"/>
    
      <!--* dcc4:  days in current century, times 4. *-->
      <xsl:variable name="dcc4" 
                    select="(4 * $dce - 1) - (146097 * $cce)"/>
    
      <!--* dcc:  days in current century. *-->
      <xsl:variable name="dcc4" 
                    select="floor($dcc4 div 4)"/>
    
      <!--* ycc:  years in current century. *-->
      <xsl:variable name="ycc" 
                    select="floor((4 * $dcc + 3) div 1461)"/>
    
      <!--* dcy4:  days in current year, times 4. *-->
      <xsl:variable name="dcy4" 
                    select="(4 * $dcc + 3) - (1461 * $ycc)"/>
    
      <!--* dcy:  days in current year. *-->
      <xsl:variable name="dcy" 
                    select="floor(($dcy4 + 4) div 4)"/>
    
      <!--* rgtm:  RGT month number (0 Mar, 1 Apr ... 12 Feb). *-->
      <xsl:variable name="rgtm" 
                    select="floor((5 * $dcy - 3) div 153)"/>
    
      <!--* dcm5:  days in current month (minus 1) times 5. *-->
      <xsl:variable name="dcm5" 
                    select="5 * $dcy - 3 - 153 * $rgtm"/>
    
      <!--* d:  day number in current month. *-->
      <xsl:variable name="d" 
                    select="floor(($dcm5 + 5) div 5)"/>
    
      <!--* rgty:  RGT year number. *-->
      <xsl:variable name="rgty" 
                    select="100 * $cce + $ycc"/>
    
      <!--* y:  Gregorian year number. *-->
      <xsl:variable name="y">
    <xsl:choose>
      <xsl:when test="$rgtm &lt; 10">
        <xsl:value-of select="$rgty"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$rgty + 1"/>
      </xsl:otherwise>
    </xsl:choose>
      </xsl:variable>
    
      <!--* m:  Gregorian month number. *-->
      <xsl:variable name="m">
    <xsl:choose>
      <xsl:when test="$rgtm &lt; 10">
        <xsl:value-of select="$rgtm + 3"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$rgtm - 9"/>
      </xsl:otherwise>
    </xsl:choose>
      </xsl:variable>
    
      <!--* Return value in ISO 8601 format *-->
      <xsl:value-of select="concat(
                format-number($y,'0000'),
                '-',
                format-number($m,'00'),
                '-',
                format-number($d,'00')
                )"/>
    </xsl:template>
    
    
    
    请注意,如前所述,它以ISO格式返回日期;如果需要dd/mm/yyyy或mm/dd/yyyy或其他格式,则需要更改它


    祝您好运。

    我已尝试解决您的问题,但您需要根据您未来的需求加强此功能

    对于XSLT 1.0,您需要导入一些扩展库,您可以在中找到,下载ZIP文件并导入它,如我生成的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>
    
    输出:

    21/08/2013
    
    Current given Date is : 21/08/2013
    Updated date is : 28/08/2013
    
    Current given Date is : 16/10/2008
    Updated date is : 23/10/2008
    
    输入:

    16/10/2008
    
    输出:

    21/08/2013
    
    Current given Date is : 21/08/2013
    Updated date is : 28/08/2013
    
    Current given Date is : 16/10/2008
    Updated date is : 23/10/2008
    

    这似乎很管用!对于新手来说,代码更容易理解。谢谢你!这个解决方案有一个bug。例如,如果您输入的日期是星期五(例如,2016年11月18日),并为RequiredDaysAddition指定“1”,则返回2016年11月19日,此时应返回2016年11月21日。完美解决方案,它可以工作!!