xslt与日期相关的功能

时间:2017-10-21 10:20:46

标签: date xslt

我想显示每天的总量spilttup。我尝试使用以下代码。 functx:next-day 功能用于设置日期归档。
                                                                                                                               输入
   起始日期= “2017年4月12日”

NoDays = 6

价格= 15540

但我想显示如下所示的结果。是否有任何其他功能需要设置日期字段值。

Current output:


                   <Night>
                        <Price Amount="2590" NightDate="2017-12-05" />
                        <Price Amount="2590" NightDate="2017-12-06" />
                        <Price Amount="2590" NightDate="2017-12-07" />
                        <Price Amount="2590" NightDate="2017-12-08" />
                        <Price Amount="2590" NightDate="2017-12-09" />
                        <Price Amount="2590" NightDate="2017-12-10" />
                    </Night>




Expected Output:

                     <Night>
                        <Price Amount="2590" NightDate="2017-12-04" />
                        <Price Amount="2590" NightDate="2017-12-05" />
                        <Price Amount="2590" NightDate="2017-12-06" />
                        <Price Amount="2590" NightDate="2017-12-07" />
                        <Price Amount="2590" NightDate="2017-12-08" />
                        <Price Amount="2590" NightDate="2017-12-09" />
                    </Night> 



Currently used Logic:

 <Night>                                                                                                
     <xsl:for-each select="1 to $NoDays">

       <Price>                                                                                                                

           <xsl:attribute name="Amount">

              <xsl:value-of select="$Price div $NoDays"/>

         </xsl:attribute>

          <xsl:attribute name="NightDate">

            <xsl:value-of select="functx:next-
                     day(xs:date($StartDate),position())"/>

        </xsl:attribute>

    </Price>

 </xsl:for-each>

1 个答案:

答案 0 :(得分:0)

我想你只想要

    <xsl:variable name="NoDays" select="6"/>
    <xsl:variable name="Price" select="15540"/>
    <xsl:variable name="StartDate">04-12-2017</xsl:variable>
    <xsl:variable name="date" as="xs:date" 
                  select="xs:date(replace($StartDate, 
                                          '([0-9]{2})-([0-9]{2})-([0-9]{4})', 
                                          '$3-$2-$1'))"/>
    <xsl:for-each select="0 to $NoDays - 1">
        <Price Amount="{$Price div $NoDays}" 
               NightDate="{$date + xs:dayTimeDuration('P1D') * .}"/>
    </xsl:for-each>

利用可以将持续时间与整数相乘并将其添加到日期。

http://xsltransform.net/bEzjRKT

上的在线示例