I have a dateTime in this format: 2015-04-29T01:30:27.058Z and time difference of 5000milliseconds. Is there any XSLT function which can deduct this time difference and produce an output of a dateTime?
In XSLT 2.0 or later (requires an XSLT 2.0 processor like Saxon 9 or XmlPrime) you can use arithmetic with xs:dateTime and xs:dayTimeDuration, for instance
xs:dateTime('2015-04-29T01:30:27.058Z') + xs:dayTimeDuration('-PT0.058S')
computes a new xs:dateTime 2015-04-29T01:30:27Z.
The XML schema namespace assumed for the prefix xs is http://www.w3.org/2001/XMLSchema.
See http://www.datypic.com/sc/xsd/t-xsd_dayTimeDuration.html on how dayTimeDurations can be written.
So with that version of the language my suggestion is to make use of those two data types and the arithmetic operations provided instead of going to milliseconds for computations.
In XSLT 2.0,
(xs:dateTime($timeStamp) - xs:dateTime('2000-01-01T00:00:00Z'))
div xs:dayTimeDuration('PT0.001S')
gives the number of milliseconds since the start of the current century.
Related
I am trying to compare to date values that are being passed into XSLT with the format of MMDDYY, for example: 01022020 (Jan 2, 2020). I am using the below snippet of code in the test:
<xsl:if test="(E_Payclass ='FT') and (E_Status ='TERMINATED') and (E_TermDate < E_PayEnd_Date)">
In an example, the dates are:
E_TermDate: 072017
E_PayEnd_Date: 020120
When running this file, I get the 072017 appearing even though it is actually less than the current date. It seems to me that the file is actually taking the number literally (which is most likely what is supposed to happen) and returning it since its technically greater than 020120.
Overall I am trying to accomplish an outcome in the test that basically would take the E_PayEnd_Date as an actual date, and only return E_TermDate if it is within 15 days prior to it.
Does anyone know how to do that in XSLT 1.0 within an if test statement?
I am trying to convert date which is in milliseconds , e.g. the input xml has 1088499889000 that corresponds to the date 2004-06-29 09:04:49.000GMT.
To try and do this within XSLT they do not seem to have functions for this. Are there any extensions available that I could use for this conversion using xslt 1.0.
Thanks
currently I'm using xsl to get the min and max value of #last_updated_time in a sharepoint list, the type is string (like 9/14/2012 1:26:23 PM)
so how can I display the earliest and latest time?
P.S. I try to remove all things but number,then convert to the int, then do the compare, but how to convert that, can anybody show me an approach?
You'll find it much easier to manipulate dates and times in XSLT (especially in XSLT 2.0) if you use international format (2012-14-09T13:26:23) rather than US localized format. So first, if your data is in US format, write code to translate it to ISO format. (That's a simple exercise in string manipulation).
Once you're there, you can use the XSLT 2.0 min() and max() functions to find the earliest and latest in a set of dates or date/time values. Or in XSLT 1.0, you can sort them and select the first and last in sorted order.
In XSLT 1.0 (using Xalan), outputting the result of:
<xsl:variable name="source0" select="number(num3)"/>
<xsl:value-of select="$source0"/>
was the number spelled out as 2011234. But in XSLT 2.0 (using Saxon), it shows up as 2.011234E6. I want it to always display as 2011234 in the Saxon/2.0 case.
Is there a way to set the default picture string for whenever it outputs a number?
I saw decimal-format, but that just affects picture strings, it doesn't set number formatting. I can't just throw format-number everywhere since then I'd have to check datatypes everywhere and... it would be a mess.
There is no way to express in XSLT 2.0 (or XSLT 1.0) that every time a number value is output it must be in a "default" format, without ussing fn:format-number() or xsl:decimal-format or op:cast or built-in type constructors. The only way that every number will be consider of some specific type is that a schema has been declared for the input (so it's a PSVI) and you run the transformation with schema-awere processor.
Id like to be able to convert the following XML
<itunes:duration>00:09:54</itunes:duration>
To a total of minutes, I currently just output the complete value but I would like to just display: 0hr 9min 54sec
Or possibly round up to the nearest minute?
If you're using an XPath 2.0 supporting processor, there are built in functions you can use. Here's a list, scroll down to the date/time functions.
You probably want something like: minutes-from-time(time)
Watch out for namespace prefixes etc. A prefix isn't required for the functions if your processor dows support XPath 2.0
If you just want to round up you can substring minutes and seconds, and if seconds > 30 -> minutes += 1