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
Related
I want to see if there's any possibillty to change Time Zone from GMT+1 to GMT+2 when daylight save activated and started in PDF file genreted from XSLT file now the value of time zone is hardcoded :
<xsl:value-of select="payment/#date-produce" />
(GMT+1)
so please can you help me to automatize this thanks.
There's no standard function in XSLT 1.0 that will help with this, and the EXSLT date/time library won't help either. You'll need to write your own extension.
In XSLT 2.0/3.0 the format-dateTime() function, if given a timezone such as "America/New_York" as the 5th argument, will adjust and display the value according to the local time in that place, including daylight savings time.
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.
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