473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

XSLT / XPATh / DateTime algebra possible?

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

May 5 '06 #1
6 1526
bl*******@gmx.net 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.)
May 5 '06 #2
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

May 5 '06 #3
bl*******@gmx.net 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.)
May 5 '06 #4
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
May 5 '06 #5


bl*******@gmx.net 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
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
exclude-result-prefixes="xs xdt"
version="2.0">

<xsl:output 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/
May 5 '06 #6
That's what I needed, thanks a lot Martin!

May 5 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
3
by: Justine Hlista | last post by:
I'm using xalan-j_2_6_0 and trying to get an example from Michael Kay's book to work: <xsl:template match="/"> <xsl:variable name="rainbow"> <color>red</color> <color>blue</color>...
4
by: Thomas Mann | last post by:
Hi, how can I make my XSLT-stylesheet insert a timestamp (date/time) into the output file ? Regards Thomas
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
1
by: Sonu Kapoor | last post by:
Hi, I would like to use xpath with xslt. I know that this should be possible, but I dont get it ! Here is what I have tried so far: ==================================== my xml file:...
3
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION>...
3
by: Greg | last post by:
Hi, I want to create a web based interface that uses a form + Javascript (in an XHTML namespace) to construct an XPath to query and modify the attributes of some SVG (in an SVG namespace). ...
1
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.