Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT / XPATh / DateTime algebra possible?

Reply
Thread Tools

XSLT / XPATh / DateTime algebra possible?

 
 
blabla120@gmx.net
Guest
Posts: n/a
 
      05-05-2006
Hello,

I have a source file with

<StartEvent starttime="2006-04-19T20:15:00Z"/>

I want to transform it with XSLT into

<Starttime>2006-04-21T20:15:00Z</Starttime>

The clue:
Onto the date, there should be added 2 days.

Is that possible?

Thanks.
Bernd

 
Reply With Quote
 
 
 
 
Johannes Koch
Guest
Posts: n/a
 
      05-05-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I have a source file with
>
> <StartEvent starttime="2006-04-19T20:15:00Z"/>
>
> I want to transform it with XSLT into
>
> <Starttime>2006-04-21T20:15:00Z</Starttime>
>
> The clue:
> Onto the date, there should be added 2 days.


Use string functions (substring...) to get the parts of the date, then
add 2 to the day, and concatenate the (new) parts.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
 
Reply With Quote
 
 
 
 
blabla120@gmx.net
Guest
Posts: n/a
 
      05-05-2006
Hi Johannes,

this would not work properly, e.g. when you have 31 as the day, your
function would make a 33 of it.....

Bernd

 
Reply With Quote
 
Johannes Koch
Guest
Posts: n/a
 
      05-05-2006
(E-Mail Removed) wrote:

> this would not work properly, e.g. when you have 31 as the day, your
> function would make a 33 of it.....


Then add this to your algorithm.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      05-05-2006
XSLT 1.0 doesn't have date arithmetic built into it.

You can implement it yourself (algorithms are available on the net; I'm
fond of working in terms of astronomical/Julian day numbers though that
may be overkill for your needs), or if you don't care about portability
to other processors you may want to do this by calling out to extension
functions that leverage existing implementations (eg Java's date classes).

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      05-05-2006


(E-Mail Removed) wrote:


> I have a source file with
>
> <StartEvent starttime="2006-04-19T20:15:00Z"/>
>
> I want to transform it with XSLT into
>
> <Starttime>2006-04-21T20:15:00Z</Starttime>
>
> The clue:
> Onto the date, there should be added 2 days.
>
> Is that possible?


XSLT/XPath 2.0 can do that, here is an example stylesheet

<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlnss="http://www.w3.org/2001/XMLSchema"
xmlnsdt="http://www.w3.org/2005/xpath-datatypes"
exclude-result-prefixes="xs xdt"
version="2.0">

<xslutput indent="yes" />

<xsl:template match="StartEvent">
<Starttime><xsl:value-of select="xs:dateTime(@starttime) +
xdt:dayTimeDuration('P2D')" /></Starttime>
</xsl:template>

</xsl:stylesheet>

Result with Saxon 8 from <http://www.saxonica.com/> is e.g.

<Starttime>2006-04-21T20:15:00Z</Starttime>

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
blabla120@gmx.net
Guest
Posts: n/a
 
      05-05-2006
That's what I needed, thanks a lot Martin!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [2.4.4] creating a datetime.datetime from an XML xs:dateTime skip@pobox.com Python 2 01-06-2009 01:31 PM
[2.4.4] creating a datetime.datetime from an XML xs:dateTime Martin Python 0 12-27-2008 08:08 PM
mx.DateTime to datetime.datetime mp Python 1 07-28-2006 10:57 PM
datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Christos TZOTZIOY Georgiou Python 3 09-13-2003 10:44 AM
RE: datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Tim Peters Python 0 09-09-2003 12:57 AM



Advertisments