首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xslt日期相关函数

问xslt日期相关函数
EN

Stack Overflow用户
提问于 2017-10-21 10:20:46
回答 1查看 29关注 0票数 0

我想显示每天的总溢出量。我尝试了下面的代码.functx:next-day函数用于设置日期文件。

代码语言:javascript
复制
                                                                                                                            Input
代码语言:javascript
复制
StartDate="04-12-2017"

NoDays =6

Price=15540

但我想显示如下所示的结果。是否有其他函数请求设置日期字段值。

代码语言:javascript
复制
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>

​

EN

回答 1

Stack Overflow用户

发布于 2017-10-21 10:47:20

我觉得你只是想

代码语言:javascript
复制
    <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在线样品

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46862266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档