Calculating Date Difference In XSL

怎甘沉沦 提交于 2019-12-13 07:36:24

问题


Note: Please don't mark this as duplicate, hear my question out please

I'm completely new here and I've been running down a mental breakdown on getting a simple date difference between 2 dates from past 2 hours, every answer on the internet doesn't seem to work for me.

Can someone please provide exactly what do i have to put in the XML file and what goes in the XSL file to get the simplistic date difference possible?

Every answer out there just throws one segment of the code but with being new I have no idea where and how to implement it so thanks for understanding my issue :) Hope you can help me

Even if you mark this as duplicate, atleast put it in comment what exactly I have to put in XML file and what exactly goes in XSL file


回答1:


One of the simplest XSLT 2.0-date-compare is like this:

XML:

<dates>
    <date id="1">2016-09-15</date>
    <date id="2">2016-09-10</date>
</dates>

XSLT 2.0:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">

    <xsl:template match="dates">
        <xsl:element name="difference">
            <xsl:value-of select="days-from-duration(xs:date(date[@id=1]) - xs:date(date[@id=2]))"/>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

If this does not work, your problem is somewhere other located than the stylesheet. Then you have to state your environment like xslt-processor, software, programming language you are using.



来源:https://stackoverflow.com/questions/39502587/calculating-date-difference-in-xsl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!