XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
tyler horathSubject: xsl date time adding...
Author: tyler horath
Date: 08 Oct 2008 02:20 PM
Ok so here is my situation. I am generating a wordpress (blog) import file from an xml file using xslt. I am trying to add an hour to each publish date node. So for example....

<title> Post 1 </title>
<pubdate>8-10-2008 5:00</pubdate> ( I realize the format may not be right)

<title> Post 2</title>
<pubdate>8-10-2009 6:00</pubdate>

You get the idea. This way I can import thousands of post and wordpress will automatically post them when their time comes up in the future. I have tried using the exslt date:add string with no luck.

Any ideas on how I can do this?

Postnext
tyler horathSubject: xsl date time adding...
Author: tyler horath
Date: 09 Oct 2008 02:39 PM
any ideas?

Postnext
Minollo I.Subject: xsl date time adding...
Author: Minollo I.
Date: 09 Oct 2008 02:51 PM
Using XSLT 2.0 (or Saxon 9.x, which understands some XSLT 2.0 concepts even when using XSLT 1.0), you can do:
xs:dateTime('2008-10-08T05:00:00')+xs:dayTimeDuration('PT1H')

You will need to format your date in the correct format to make xs:dateTime() digest it.

Postnext
tyler horathSubject: xsl date time adding...
Author: tyler horath
Date: 09 Oct 2008 03:36 PM
I am using xmlspy and when I try to debug it closes xmlspy.

Postnext
Minollo I.Subject: xsl date time adding...
Author: Minollo I.
Date: 09 Oct 2008 03:43 PM
...which seems to suggest you are either using the wrong tool or the wrong discussion forum.

Postnext
tyler horathSubject: xsl date time adding...
Author: tyler horath
Date: 09 Oct 2008 03:48 PM
ok I got it working, but when its inside my for each loop it just adds to hour to all of the nodes. I want it to add an hour to each from the current hour of the last node. so its 1:00 then 2:00 then 3:00 then 4:00, etc.

Postnext
tyler horathSubject: xsl date time adding...
Author: tyler horath
Date: 12 Oct 2008 04:07 PM
is there a way to do some sort of recursion with the datE to add it to the last?

like i = i + 1

Postnext
(Deleted User) Subject: Re: xsl date time adding...
Author: (Deleted User)
Date: 13 Oct 2008 06:10 AM
do you have a specific objective on why you wanted to do some sort of
recursion?.... So for me to know how may i help you.

On 10/13/08, stylus-studio-xslt Listmanager <
stylus-studio-xslt.listmanager@stylusstudio.com> wrote:
>
> From: tyler horath
>
> is there a way to do some sort of recursion with the datE to add it to the
> last?
>
> like i = i + 1
>
>
>
> --
> To reply:stylus-studio-xslt.25314@stylusstudio.com
> To start a new topic:stylus-studio-xslt@stylusstudio.com
> To login:http://www.stylusstudio.com/SSDN/
> To (un)subscribe:stylus-studio-xslt.list-request@stylusstudio.com
>



--
"We can observe and theorize. But we can never know how. Reality is
something we can only approach"-albert enstein

Postnext
tyler horathSubject: Re: xsl date time adding...
Author: tyler horath
Date: 13 Oct 2008 09:05 AM
anyway that will work is fine by me. I just want the date to start at the current time on the first node, then to keep adding an hour to each node.

<example>
<item>
<pubdate>10-13-2008 8:00</pubdate>
</item>
<item>
<pubdate>10-13-2008 9:00</pubdate>
</item>
<item>
<pubdate>10-13-2008 10:00</pubdate>
</item>
<item>
<pubdate>10-13-2008 11:00</pubdate>
</item>
<item>
<pubdate>10-13-2008 12:00</pubdate>
</item>
<item>
<pubdate>10-14-2008 1:00</pubdate>
</item>
</example>

and so on...

And in doing this hopefully the days will change as the hours pass 24 or whatever.

Postnext
(Deleted User) Subject: Re: xsl date time adding...
Author: (Deleted User)
Date: 13 Oct 2008 11:03 PM
oh i see, I'm still a newbie at this. But i got the same problem before
when I was tasked to convert the current time to the time based on GMT, so
with that , i had to add 8 hours each time i pull and transform the xml
date node required to be converted.
Take note that in xslt version 2, we can already use functions for
datetime manipulations etc , also, we can already use some datetime
functions like dateadd etc..
But in xslt version 1, we are ony limited in using templates, this was my
problem before becuase i was only limited to code using xslt version 1.
What i did was , I created my own set of templates that will be called
while I transform the date node. These templates will :
1. Select the current datetime node and converts it to a date-time format
that can be easily divided into :
a. Date, Time and Year
2. Get the time,day,month and year
(DoAddHour,DoAddDate,DoAddMonth,DoAddYear)
3. Pass the formatted current date as a variable to the DoAddTime, this
template should basically :
a.get the time in HH:mm:ss tt,
b. add 8 hours as per GMT requirement
c. Compare the resulting Time if this excedds 24 hours
d. if exceeds to 24 hours, call template DoAddDate

* .... do this until the DoAddYear template .... see the sample
templates below*
.. You can use a set of ms:format-date, ms:format-time, substring
-available functions in xslt version 1
the DoAddHour,DoaddDate, DoAddMonth, DoaddYear will depend on how it will be
used, as for me since I was tasked to display the output as, Monday, Feb
28, 2008, the template for DoAddHour,DoAddDate,DoAddMonth simply contained
a set of xsl:choose, xsl:when for days :Monday, Tuesday wednesday etc.. and
months: Jan, February, March , April.
ex..
* ** <xsl:template name="DoAddHour">
<xsl:param name='Hour'/>
<xsl:value-of select="$Hour +8"/>
</xsl:template>
<xsl:template name="DoAddDate">
<xsl:param name="Date"/>
<xsl:value-of select="$Date +1"/>
</xsl:template>
<xsl:template name="DoAddYear">
<xsl:param name="Year"/>
<xsl:value-of select="$Year+ 1"/>
</xsl:template>*
*<xsl:template name="DoAddOneDay">
<xsl:param name="DoDay"/>
<xsl:variable name="DayInAWeek" select="$DoDay"/>
<xsl:choose>
<xsl:when test="$DayInAWeek = 'Sun'">Mon</xsl:when>
<xsl:when test="$DayInAWeek = 'Mon'">Tue</xsl:when>
<xsl:when test="$DayInAWeek = 'Tue'">Wed</xsl:when>
<xsl:when test="$DayInAWeek = 'Wed'">Thu</xsl:when>
<xsl:when test="$DayInAWeek = 'Thu'">Fri</xsl:when>
<xsl:when test="$DayInAWeek = 'Fri'">Sat</xsl:when>
<xsl:when test="$DayInAWeek = 'Sat'">Sun</xsl:when>
</xsl:choose>
</xsl:template>*
* <xsl:template name="DoAddOneMonth">
<xsl:param name="DoMonth"/>
<xsl:variable name="MonthInAYear" select="$DoMonth"/>
<xsl:choose>
<xsl:when test="$MonthInAYear = 'Jan'">Feb</xsl:when>
<xsl:when test="$MonthInAYear = 'Feb'">Mar</xsl:when>
<xsl:when test="$MonthInAYear = 'Mar'">Apr</xsl:when>
<xsl:when test="$MonthInAYear = 'Apr'">May</xsl:when>
<xsl:when test="$MonthInAYear = 'May'">Jun</xsl:when>
<xsl:when test="$MonthInAYear = 'Jun'">Jul</xsl:when>
<xsl:when test="$MonthInAYear = 'Jul'">Aug</xsl:when>
<xsl:when test="$MonthInAYear = 'Aug'">Sep</xsl:when>
<xsl:when test="$MonthInAYear = 'Sep'">Oct</xsl:when>
<xsl:when test="$MonthInAYear = 'Oct'">Nov</xsl:when>
<xsl:when test="$MonthInAYear = 'Nov'">Dec</xsl:when>
<xsl:when test="$MonthInAYear = 'Dec'">Jan</xsl:when>
</xsl:choose>
</xsl:template>*


*This was not the best solution for my problem , but i had to resort to a
workaround because of the limitation of the system i was trying to add
content to. :0*
*I know this was a bit different bbut i hope i help you with an idea,..
keep me posted. ^_^*





On 10/13/08, stylus-studio-xslt Listmanager <
stylus-studio-xslt.listmanager@stylusstudio.com> wrote:
>
> From: tyler horath
>
> anyway that will work is fine by me. I just want the date to start at the
> current time on the first node, then to keep adding an hour to each node.
>
> <example>
> <item>
> <pubdate>10-13-2008 8:00</pubdate>
> </item>
> <item>
> <pubdate>10-13-2008 9:00</pubdate>
> </item>
> <item>
> <pubdate>10-13-2008 10:00</pubdate>
> </item>
> <item>
> <pubdate>10-13-2008 11:00</pubdate>
> </item>
> <item>
> <pubdate>10-13-2008 12:00</pubdate>
> </item>
> <item>
> <pubdate>10-14-2008 1:00</pubdate>
> </item>
> </example>
>
> and so on...
>
> And in doing this hopefully the days will change as the hours pass 24 or
> whatever.
>
>
> --
> To reply:stylus-studio-xslt.25319@stylusstudio.com
> To start a new topic:stylus-studio-xslt@stylusstudio.com
> To login:http://www.stylusstudio.com/SSDN/
> To (un)subscribe:stylus-studio-xslt.list-request@stylusstudio.com
>



--
"We can observe and theorize. But we can never know how. Reality is
something we can only approach"-albert enstein's pen

Postnext
tyler horathSubject: Re: xsl date time adding...
Author: tyler horath
Date: 14 Oct 2008 12:40 PM
so I would just call those templates where i wanted to put the date time?

Postnext
(Deleted User) Subject: Re: xsl date time adding...
Author: (Deleted User)
Date: 14 Oct 2008 05:55 PM
yes. If this is how you would like to achieve your goal.

On Wed, Oct 15, 2008 at 12:42 AM, stylus-studio-xslt Listmanager <
stylus-studio-xslt.listmanager@stylusstudio.com> wrote:

> From: tyler horath
>
> so I would just call those templates where i wanted to put the date time?
>
>
> --
> To reply:stylus-studio-xslt.25326@stylusstudio.com
>
> To start a new topic:stylus-studio-xslt@stylusstudio.com
> To login:http://www.stylusstudio.com/SSDN/
> To (un)subscribe:stylus-studio-xslt.list-request@stylusstudio.com
>



--
"We can observe and theorize. But we can never know how. Reality is
something we can only approach"-albert enstein

Postnext
tyler horathSubject: Re: xsl date time adding...
Author: tyler horath
Date: 14 Oct 2008 07:51 PM
Originally Posted: 14 Oct 2008 07:15 PM
Isnt there just a way to use add:date to some sort of loop?

Postnext
(Deleted User) Subject: Re: xsl date time adding...
Author: (Deleted User)
Date: 15 Oct 2008 05:38 AM
i think there is . try to research about EXSLT extensions.
http://www.exslt.org/func/ Then when you already know how you can integrate
datetime functions, you can just use it while looping through the nodes
that you need to add 24 hours to.

On 10/15/08, stylus-studio-xslt Listmanager <
stylus-studio-xslt.listmanager@stylusstudio.com> wrote:
>
> From: tyler horath
>
> Isnt there just a way to use add:date to some sort of loop?
>
>
>
> --
> To reply:stylus-studio-xslt.25329@stylusstudio.com
> To start a new topic:stylus-studio-xslt@stylusstudio.com
> To login:http://www.stylusstudio.com/SSDN/
> To (un)subscribe:stylus-studio-xslt.list-request@stylusstudio.com
>



--
"We can observe and theorize. But we can never know how. Reality is
something we can only approach"-albert enstein's Pen

Postnext
tyler horathSubject: Re: xsl date time adding...
Author: tyler horath
Date: 17 Oct 2008 04:54 PM
tried this with no luck...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:a="http://webservices.amazon.com/AWSECommerceService/2005-10-05"
xmlns:b="http://webservices.amazon.com/AWSECommerceService/2008-08-19"
xmlns:dp="http://www.dpawson.co.uk"
xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes"

>
<xsl:import href="date.add.template.xsl" />
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

<xsl:template match="/">
<xsl:call-template name="for.loop">
<xsl:with-param name="i"><xsl:value-of select="xs:dateTime('2008-10-17T12:00:00')"/></xsl:with-param>
<xsl:with-param name="count"><xsl:value-of select="xs:dateTime('2010-10-17T12:00:00')"/></xsl:with-param>
</xsl:call-template>
</xsl:template>


<!-- Rename "old name" elements to "new name" -->
<xsl:template name="for.loop">
<xsl:param name="i"/>
<xsl:param name="count"/>
<xsl:if test="$i &lt;= $count">
<!-- body of the loop goes here -->
</xsl:if>
<xsl:if test="$i &lt;= $count">
<xsl:call-template name="for.loop">

<xsl:with-param name="i">
<!-- Increment index-->
<xsl:value-of select="xs:dateTime('2008-10-17T12:00:00') +
xs:dayTimeDuration('PTD')"/>
</xsl:with-param>
<xsl:with-param name="count">
<xsl:value-of select="$count"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>



</xsl:stylesheet>

Posttop
(Deleted User) Subject: Re: xsl date time adding...
Author: (Deleted User)
Date: 18 Oct 2008 02:41 AM
ok. i guess i didn't help you. Can you give me the sample of your worlk?
just a sample of the node or xml file you are trying to convert..
your expected output? and your solution?
and is the structure of your xml file the same throughout? .. etc.
Let me try to solve it.. (just a try.)



On 10/17/08, stylus-studio-xslt Listmanager <
stylus-studio-xslt.listmanager@stylusstudio.com> wrote:
>
> From: tyler horath
>
> tried this with no luck...
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="2.0" xmlns:xsl="
> http://www.w3.org/1999/XSL/Transform"<">http://www.w3.org/1999/XSL/Transform>xmlns:xs="
> http://www.w3.org/2001/XMLSchema" <http://www.w3.org/2001/XMLSchema>
> xmlns:fn="http://www.w3.org/2005/xpath-functions"<http://www.w3.org/2005/xpath-functions>
> xmlns:a="http://webservices.amazon.com/AWSECommerceService/2005-10-05"<http://webservices.amazon.com/AWSECommerceService/2005-10-05>
> xmlns:b="http://webservices.amazon.com/AWSECommerceService/2008-08-19"<http://webservices.amazon.com/AWSECommerceService/2008-08-19>
> xmlns:dp="http://www.dpawson.co.uk" <http://www.dpawson.co.uk/>
> xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes"<http://www.w3.org/2005/02/xpath-datatypes>
>
> >
> <xsl:import href="date.add.template.xsl" />
> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
>
> <xsl:template match="/">
> <xsl:call-template name="for.loop">
> <xsl:with-param name="i"><xsl:value-of
> select="xs:dateTime('2008-10-17T12:00:00')"/></xsl:with-param>
> <xsl:with-param name="count"><xsl:value-of
> select="xs:dateTime('2010-10-17T12:00:00')"/></xsl:with-param>
> </xsl:call-template>
> </xsl:template>
>
>
> <!-- Rename "old name" elements to "new name" -->
> <xsl:template name="for.loop">
> <xsl:param name="i"/>
> <xsl:param name="count"/>
> <xsl:if test="$i &lt;= $count">
> <!-- body of the loop goes here -->
> </xsl:if>
> <xsl:if test="$i &lt;= $count">
> <xsl:call-template name="for.loop">
>
> <xsl:with-param name="i">
> <!-- Increment index-->
> <xsl:value-of select="xs:dateTime('2008-10-17T12:00:00') +
> xs:dayTimeDuration('PTD')"/>
> </xsl:with-param>
> <xsl:with-param name="count">
> <xsl:value-of select="$count"/>
> </xsl:with-param>
> </xsl:call-template>
> </xsl:if>
> </xsl:template>
>
>
>
> </xsl:stylesheet>
>
>
>
> --
> To reply:stylus-studio-xslt.25340@stylusstudio.com
> To start a new topic:stylus-studio-xslt@stylusstudio.com
> To login:http://www.stylusstudio.com/SSDN/
> To (un)subscribe:stylus-studio-xslt.list-request@stylusstudio.com
>



--
"We can observe and theorize. But we can never know how. Reality is
something we can only approach"-albert enstein's Pen

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.