By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,677 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,677 IT Pros & Developers. It's quick & easy.

XSL prob.

P: n/a
Hi

I have an XSL stylesheet:

<xsl:for-each select="TRACKS/TRACK">
<tr class="TDL">
<td width="90%"><xsl:number value="position()" format="1" /> -
<xsl:value-of select="TRACKTITLE"/></td>
<td width="10%" align="center"><a href="{TRACKURL}"
target="_blank">More info!</a></td>
</tr>
</xsl:for-each>
I wan't to make every second <tr class> aligned to TDU, which I have in the
CSS. How is this possible?

Regards,
Kenneth
Jul 20 '05 #1
Share this Question
Share on Google+
29 Replies


P: n/a
Hi Kenneth,

Try one of the following (all do the same - in a slightly different way)...

<xsl:for-each select="TRACKS/TRACK">
<tr class="TDL">
<xsl:if test="position() mod 2 = 0">
<xsl:attribute name="class">TDU</xsl:attribute>
</xsl:if>
<td width="90%">
<xsl:number value="position()" format="1" /> -
<xsl:value-of select="TRACKTITLE"/>
</td>
<td width="10%" align="center">
<a href="{TRACKURL}" target="_blank">More info!</a>
</td>
</tr>
</xsl:for-each>

<xsl:for-each select="TRACKS/TRACK">
<tr>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="position() mod 2 = 1">
<xsl:text>TDL</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>TDU</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<td width="90%">
<xsl:number value="position()" format="1" /> -
<xsl:value-of select="TRACKTITLE"/>
</td>
<td width="10%" align="center">
<a href="{TRACKURL}" target="_blank">More info!</a>
</td>
</tr>
</xsl:for-each>

<xsl:for-each select="TRACKS/TRACK">
<tr class="{substring('TDUTDL',((position() mod 2) * 3) + 1,3)}">
<td width="90%">
<xsl:number value="position()" format="1" /> -
<xsl:value-of select="TRACKTITLE"/>
</td>
<td width="10%" align="center">
<a href="{TRACKURL}" target="_blank">More info!</a>
</td>
</tr>
</xsl:for-each>

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"Thomas" <ridder_dk@SLET_DETTEhotmail.com> wrote in message
news:Q_**********************@news010.worldonline. dk...
Hi

I have an XSL stylesheet:

<xsl:for-each select="TRACKS/TRACK">
<tr class="TDL">
<td width="90%"><xsl:number value="position()" format="1" /> -
<xsl:value-of select="TRACKTITLE"/></td>
<td width="10%" align="center"><a href="{TRACKURL}"
target="_blank">More info!</a></td>
</tr>
</xsl:for-each>
I wan't to make every second <tr class> aligned to TDU, which I have in the CSS. How is this possible?

Regards,
Kenneth

Jul 20 '05 #2

P: n/a
Hi Marrow.

Damn! You nailed it, thanks.

"Marrow" <marrow-NO-@-SPAM-marrowsoft.com> wrote in message
news:UF**************@newsfep1-gui.server.ntli.net...
Hi Kenneth,

Try one of the following (all do the same - in a slightly different way)...
<xsl:for-each select="TRACKS/TRACK">
<tr class="TDL">
<xsl:if test="position() mod 2 = 0">
<xsl:attribute name="class">TDU</xsl:attribute>
</xsl:if>
<td width="90%">
<xsl:number value="position()" format="1" /> -
<xsl:value-of select="TRACKTITLE"/>
</td>
<td width="10%" align="center">
<a href="{TRACKURL}" target="_blank">More info!</a>
</td>
</tr>
</xsl:for-each>

<xsl:for-each select="TRACKS/TRACK">
<tr>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="position() mod 2 = 1">
<xsl:text>TDL</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>TDU</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<td width="90%">
<xsl:number value="position()" format="1" /> -
<xsl:value-of select="TRACKTITLE"/>
</td>
<td width="10%" align="center">
<a href="{TRACKURL}" target="_blank">More info!</a>
</td>
</tr>
</xsl:for-each>

<xsl:for-each select="TRACKS/TRACK">
<tr class="{substring('TDUTDL',((position() mod 2) * 3) + 1,3)}">
<td width="90%">
<xsl:number value="position()" format="1" /> -
<xsl:value-of select="TRACKTITLE"/>
</td>
<td width="10%" align="center">
<a href="{TRACKURL}" target="_blank">More info!</a>
</td>
</tr>
</xsl:for-each>

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"Thomas" <ridder_dk@SLET_DETTEhotmail.com> wrote in message
news:Q_**********************@news010.worldonline. dk...
Hi

I have an XSL stylesheet:

<xsl:for-each select="TRACKS/TRACK">
<tr class="TDL">
<td width="90%"><xsl:number value="position()" format="1" /> -
<xsl:value-of select="TRACKTITLE"/></td>
<td width="10%" align="center"><a href="{TRACKURL}"
target="_blank">More info!</a></td>
</tr>
</xsl:for-each>
I wan't to make every second <tr class> aligned to TDU, which I have in

the
CSS. How is this possible?

Regards,
Kenneth


Jul 20 '05 #3

P: n/a
Hi

I have another prob. Is it possible to convert a unix timestamp to a
readable date with XSL?

Kenneth
Jul 20 '05 #4

P: n/a
Can you give an example of a "Unix timestamp" and a "readable date"?
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"Thomas" <ridder_dk@SLET_DETTEhotmail.com> wrote in message
news:vx**********************@news010.worldonline. dk...
Hi

I have another prob. Is it possible to convert a unix timestamp to a
readable date with XSL?

Kenneth

Jul 20 '05 #5

P: n/a
> Can you give an example of a "Unix timestamp" and a "readable date"?

Unix timestamp: 875996580
Readable converted date/time: 1997-10-04 22:23:00'

Kenneth
Jul 20 '05 #6

P: n/a
> > Can you give an example of a "Unix timestamp" and a "readable date"?

Unix timestamp: 875996580
Readable converted date/time: 1997-10-04 22:23:00'


And what's its meaning (e.g. number of seconds after some date)?
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #7

P: n/a
> And what's its meaning (e.g. number of seconds after some date)?

Source: http://www.mysql.com/doc/en/Date_and...functions.html

It would be a lot easier if they pull the data out of the database as a
readable date instead of unix timestamp, but they don't. :(

Regards,

Kenneth
Jul 20 '05 #8

P: n/a
"Thomas" <ridder_dk@SLET_DETTEhotmail.com> writes:
I have another prob. Is it possible to convert a unix timestamp to a
readable date with XSL?


Yes, because XSLT is Turing complete. However, you'll have to roll
your own conversion because there's neither an XSLT nor XPath function
that'll do the job for you.

Cheers

Jens
Jul 20 '05 #9

P: n/a
"Thomas" <ridder_dk@SLET_DETTEhotmail.com> wrote in message
news:7R**********************@news010.worldonline. dk
And what's its meaning (e.g. number of seconds after some date)?


Source: http://www.mysql.com/doc/en/Date_and...functions.html

It would be a lot easier if they pull the data out of the database as
a readable date instead of unix timestamp, but they don't. :(


Since a UNIX timestamp is the number of seconds since midnight, 1st
January 1970, it would be an "easy" addition of seconds to a date. But
XSL is not capable of that, AFAICS.

What you could do - write a web page accepting a timestamp as GET
parameter and let it return a small XML file to your XSL processor.

Given a return XML like:
<?xml version="1.0"?>
<formatted>1997-10-04 22:23:00</formatted>

then I would think of:
<xsl:value-of
select="document(concat('http://localhost/convert.php&amp;timestamp=',
$timestamp))/formatted" />

This would return the contents of the XML document's "formatted"
element, or what ever you'd like to call it.
PHP does contain date and time functions capable of converting
timestamps, so the implementation on the PHP side should be quite
straightforward.

You could even improve performance by handing all timestamps in your
document over to PHP simultaneously, as a seperated list of values
(build that by recursive call-template's). So you will need to use
document() only once per processed XML file.

just an idea,

Martin
Jul 20 '05 #10

P: n/a
"Jens M. Felderhoff" <j.************@gmx.net> wrote in message
news:bl************@ID-10019.news.uni-berlin.de
"Thomas" <ridder_dk@SLET_DETTEhotmail.com> writes:
I have another prob. Is it possible to convert a unix timestamp to a
readable date with XSL?


Yes, because XSLT is Turing complete. However, you'll have to roll
your own conversion [...]


Which would cause quite a headache and bury efficiency really big time.
XSLT is not the adequate instrument for such a task, except for academic
purposes maybe. But regarding the wording of the question you are
absolutely right. ;-)

Martin
Jul 20 '05 #11

P: n/a

"Martin Boehm" <ng********@arcor.de> wrote in message
news:3f***********************@newsread2.arcor-online.net...
"Jens M. Felderhoff" <j.************@gmx.net> wrote in message
news:bl************@ID-10019.news.uni-berlin.de
"Thomas" <ridder_dk@SLET_DETTEhotmail.com> writes:
I have another prob. Is it possible to convert a unix timestamp to a
readable date with XSL?


Yes, because XSLT is Turing complete. However, you'll have to roll
your own conversion [...]


Which would cause quite a headache and bury efficiency really big time.
XSLT is not the adequate instrument for such a task, except for academic
purposes maybe. But regarding the wording of the question you are
absolutely right. ;-)


This is not true!

Using the datetime_lib.xsl stylesheet, which comes with the XSelerator (one
can obtain it free with the trial download), the code to convert a Unix
timestamp to a formatted date is just a few lines (11 lines for the called
template):

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="E:\Program
Files\Marrowsoft\Xselerator25\Samples\Libraries\da tetime_lib.xsl"/>

<xsl:output method="text"/>

<xsl:variable name="vDaySecs" select="86400"/>

<xsl:template match="/">
<xsl:call-template name="unix-timestamp-to-datetime">
<xsl:with-param name="pTimeStamp" select="875996580"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="unix-timestamp-to-datetime">
<xsl:param name="pTimeStamp" select="0"/>

<xsl:variable name="vBase">
<xsl:call-template name="date-to-julian-day">
<xsl:with-param name="date" select="'1970-01-01'"/>
</xsl:call-template>
</xsl:variable>

<xsl:call-template name="float-to-date-time">
<xsl:with-param name="value" select="$vBase + $pTimeStamp div
$vDaySecs"/>
</xsl:call-template>
</xsl:template>

</xsl:stylesheet>

When this transformation is applied on any source.xml (not used), the wanted
result is produced:

1997-10-04T20:23:00
To see the real power of this pure XSLT 1.0 library, do have a look at the
Calendar Application I wrote two years ago:

http://www.topxml.com/code/default.a...20020711152545

FYI, it is really efficient -- on my PC the transformation time is just 93
milliseconds.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

Jul 20 '05 #12

P: n/a
> To see the real power of this pure XSLT 1.0 library, do have a look at the
Calendar Application I wrote two years ago:

http://www.topxml.com/code/default.a...20020711152545

FYI, it is really efficient -- on my PC the transformation time is just 93
milliseconds.
I mean the complete Calendar application, which performs complex
calculations for 365 days, 52 weeks and days-in-week, 12 months and 4
quarters.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

Jul 20 '05 #13

P: n/a
"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bl************@ID-152440.news.uni-berlin.de
I have another prob. Is it possible to convert a unix timestamp to
a readable date with XSL?

Yes, because XSLT is Turing complete. However, you'll have to roll
your own conversion [...]
Which would cause quite a headache and bury efficiency really big
time. XSLT is not the adequate instrument for such a task, except
for academic purposes maybe. But regarding the wording of the
question you are absolutely right. ;-)


This is not true!

[example snipped]


I admit, I was not aware of that.
[...]

FYI, it is really efficient -- on my PC the transformation time is
just 93 milliseconds.


Whatever "my PC" means. SCNR ;-) Besides that you forgot to compare it
to the time maybe PHP would need to do it. The word "efficient" is quite
meaningless if you give only one number.

BTW I am not sure if one can call doing about 10 conversions per second
"efficient" in context of the simplicity of this task, given the
hardware that you use.

What I thought of was putting the algorithms together myself, and my
subjective impression was that the outcome would not be optimal under
the best of circumstances, and that it would not approximate solutions
more adequate for the problem.

Martin
Jul 20 '05 #14

P: n/a
> > FYI, it is really efficient -- on my PC the transformation time is
just 93 milliseconds.
Whatever "my PC" means. SCNR ;-)


My PC is 2 years old 1.7GHz Pentium with 256MB RAM running W2K
Besides that you forgot to compare it
to the time maybe PHP would need to do it. The word "efficient" is quite
meaningless if you give only one number.
By efficient I mean that it is not obviously a bottleneck. In this case one
would use an existing solution, which BTW is 100% portable.

BTW I am not sure if one can call doing about 10 conversions per second
"efficient" in context of the simplicity of this task, given the
hardware that you use.


You misunderstood me -- the reported time was for the complete Calendar
Application, which does many hundreds of times more...

The time for a single conversion using MSXML4 on my PC is 0.3 milliseconds.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #15

P: n/a
> The time for a single conversion using MSXML4 on my PC is 0.3
milliseconds.

Some more accurate timing:

The time for 104 conversions is ~ 7.5 milliseconds.

This makes 0.073 milliseconds for a single conversion or ~ 13700 conversions
per second.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #16

P: n/a
"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bl************@ID-152440.news.uni-berlin.de
The time for 104 conversions is ~ 7.5 milliseconds.

This makes 0.073 milliseconds for a single conversion or ~ 13700
conversions per second.


Just estimated the PHP solution:
(I hold the difference between the power of your CPU and that of mine
for quite negligible, and the amount RAM does not matter here. I used a
for loop containing a call to the PGP date() function.)

My 1.8 GHz P4 with 512 MB of RAM (Win2k, too) did 1.000.000 conversions
in a 10 reiterations average of 7.57 seconds, this breaks down to about
132100 per second. For a single conversion that would be (quite exactly)
7,56998 * 10^-6 seconds, or ~0.076 milliseconds.

I am amazed. :-)

surrendering,

Martin

P.S.: Would you mind do post or mail the code you used so I can make a
direct comparison on that? Thanks!
Jul 20 '05 #17

P: n/a
Hi Kenneth,

Using some functions from our datetime_lib.xsl (www.marrowsoft.com -
libraries included in the trial installer) you could do...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="unix_timestamp" select="875996580"/>
<xsl:variable name="jd19700101" select="2440588"/>
<xsl:call-template name="float-to-date-time">
<xsl:with-param name="value" select="$jd19700101 + ($unix_timestamp div
(24 * 60 * 60))"/>
</xsl:call-template>
</xsl:template>

<!--
================================================== ========================
Template: float-to-date-time
Description: Convert a floating point value representing a date/time to
a date/time string.
Parameters:-
<value> the value to be converted
<round-seconds> if true then the seconds are not quoted on the output
and, if the seconds are 59 then hour/minute is rounded
(this is useful because some processors have limited
floating point precision to cope with the seconds)
================================================== ======================== -
->
<xsl:template name="float-to-date-time">
<xsl:param name="value" select="number(0)"/>
<xsl:param name="round-seconds" select="false()"/>
<xsl:variable name="date">
<xsl:call-template name="julian-day-to-date">
<xsl:with-param name="julian-day" select="floor($value)"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="t1" select="$value - floor($value)"/>
<xsl:variable name="h" select="floor($t1 div (1 div 24))"/>
<xsl:variable name="t2" select="$t1 - ($h * (1 div 24))"/>
<xsl:variable name="m" select="floor($t2 div (1 div 1440))"/>
<xsl:variable name="t3" select="$t2 - ($m * (1 div 1440))"/>
<xsl:choose>
<xsl:when test="$round-seconds">
<xsl:variable name="s" select="$t3 div (1 div 86400)"/>
<xsl:variable name="h2">
<xsl:choose>
<xsl:when test="($s &gt;= 59) and ($m = 59)"><xsl:value-of select="$h +
1"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$h"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="m2">
<xsl:choose>
<xsl:when test="($s &gt;= 59) and ($m = 59)">0</xsl:when>
<xsl:when test="($s &gt;= 59)"><xsl:value-of select="$m +
1"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$m"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- pad final time result -->
<xsl:variable name="hh" select="concat(substring('00',1,2 -
string-length(string($h2))),string($h2))"/>
<xsl:variable name="mm" select="concat(substring('00',1,2 -
string-length(string($m2))),string($m2))"/>
<!-- final output resultant -->
<xsl:value-of select="concat($date,'T',$hh,':',$mm)"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="s" select="floor($t3 div (1 div 86400))"/>
<!-- pad final time result -->
<xsl:variable name="hh" select="concat(substring('00',1,2 -
string-length(string($h))),string($h))"/>
<xsl:variable name="mm" select="concat(substring('00',1,2 -
string-length(string($m))),string($m))"/>
<xsl:variable name="ss" select="concat(substring('00',1,2 -
string-length(string($s))),string($s))"/>
<!-- final output resultant -->
<xsl:value-of select="concat($date,'T',$hh,':',$mm,':',$ss)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!--
================================================== ========================
Template: julian-day-to-date
Description: Convert a julian day to date
Parameters:-
<julian-day>
================================================== ======================== -
->
<xsl:template name="julian-day-to-date">
<xsl:param name="julian-day" select="number(0)"/>
<!-- pre-calcs -->
<xsl:variable name="la" select="$julian-day + 68569"/>
<xsl:variable name="n" select="floor((4 * $la) div 146097)"/>
<xsl:variable name="lb" select="$la - floor((146097 * $n + 3) div 4)"/>
<xsl:variable name="i" select="floor((4000 * ($lb + 1)) div 1461001)"/>
<xsl:variable name="lc" select="$lb - floor((1461 * $i) div 4) + 31"/>
<xsl:variable name="j" select="floor((80 * $lc) div 2447)"/>
<xsl:variable name="day" select="$lc - floor((2447 * $j) div 80)"/>
<xsl:variable name="ld" select="floor($j div 11)"/>
<xsl:variable name="month" select="$j + 2 - (12 * $ld)"/>
<xsl:variable name="year" select="100 * ($n - 49) + $i + $ld"/>
<!-- whole days -->
<xsl:variable name="iday" select="floor($day)"/>
<!-- pad final result -->
<xsl:variable name="sday" select="concat(substring('00',1,2 -
string-length(string($iday))),string($iday))"/>
<xsl:variable name="smonth" select="concat(substring('00',1,2 -
string-length(string($month))),string($month))"/>
<xsl:variable name="syear" select="concat(substring('00',1,4 -
string-length(string($year))),string($year))"/>
<!-- final output -->
<xsl:value-of select="concat($syear,'-',$smonth,'-',$sday)"/>
</xsl:template>

</xsl:stylesheet>

Cheers
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Thomas" <ridder_dk@SLET_DETTEhotmail.com> wrote in message
news:7R**********************@news010.worldonline. dk...
And what's its meaning (e.g. number of seconds after some date)?


Source: http://www.mysql.com/doc/en/Date_and...functions.html

It would be a lot easier if they pull the data out of the database as a
readable date instead of unix timestamp, but they don't. :(

Regards,

Kenneth

Jul 20 '05 #18

P: n/a
"Martin Boehm" <ng********@arcor.de> wrote in message
news:3f***********************@newsread2.arcor-online.net...
"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bl************@ID-152440.news.uni-berlin.de
The time for 104 conversions is ~ 7.5 milliseconds.

This makes 0.073 milliseconds for a single conversion or ~ 13700
conversions per second.
Just estimated the PHP solution:
(I hold the difference between the power of your CPU and that of mine
for quite negligible, and the amount RAM does not matter here. I used a
for loop containing a call to the PGP date() function.)

My 1.8 GHz P4 with 512 MB of RAM (Win2k, too) did 1.000.000 conversions
in a 10 reiterations average of 7.57 seconds, this breaks down to about
132100 per second. For a single conversion that would be (quite exactly)
7,56998 * 10^-6 seconds, or ~0.076 milliseconds.

I am amazed. :-)


I am, too. You did 1 million in 7.6 seconds and Dimitre did 104 thousand in
7.5 seconds, yet his is slightly faster per conversion! That is truly
amazing. But I believe 7.6 * 10^-6 seconds is 7.6 microseconds, which is
0.0076 milliseconds.

Bob Foster
surrendering,

Martin

P.S.: Would you mind do post or mail the code you used so I can make a
direct comparison on that? Thanks!

Jul 20 '05 #19

P: n/a
> Just estimated the PHP solution:
(I hold the difference between the power of your CPU and that of mine
for quite negligible, and the amount RAM does not matter here. I used a
for loop containing a call to the PGP date() function.)

My 1.8 GHz P4 with 512 MB of RAM (Win2k, too) did 1.000.000 conversions
in a 10 reiterations average of 7.57 seconds, this breaks down to about
132100 per second. For a single conversion that would be (quite exactly)
7,56998 * 10^-6 seconds, or ~0.076 milliseconds.

I am amazed. :-)

surrendering,

Martin

P.S.: Would you mind do post or mail the code you used so I can make a
direct comparison on that? Thanks!


Here it is -- just check (as I did) that the value of count($vNodes) is 104:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="E:\Program
Files\Marrowsoft\Xselerator25\Samples\Libraries\da tetime_lib.xsl"/>

<xsl:output method="text"/>

<xsl:variable name="vDaySecs" select="86400"/>

<xsl:template match="/">
<xsl:variable name="vNodes"
select="document('')//node() | document('')//@* |
document('')//namespace::*"/>

<xsl:variable name="vResult">
<xsl:for-each select="$vNodes">
<xsl:call-template name="unix-timestamp-to-datetime">
<xsl:with-param name="pTimeStamp" select="875996580"/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<!-- <xsl:value-of select="count($vNodes)"/>-->
</xsl:template>

<xsl:template name="unix-timestamp-to-datetime">
<xsl:param name="pTimeStamp" select="0"/>

<xsl:variable name="vBase">
<xsl:call-template name="date-to-julian-day">
<xsl:with-param name="date" select="'1970-01-01'"/>
</xsl:call-template>
</xsl:variable>

<xsl:call-template name="float-to-date-time">
<xsl:with-param name="value" select="$vBase + $pTimeStamp div
$vDaySecs"/>
</xsl:call-template>
</xsl:template>

</xsl:stylesheet>
P.S.
1. This solution can be optimized still more by having a constant for vBase
(2440588) and not calculating it every time. Then the result for 92
conversions is 3.776 milliseconds, which makes:

0.041 milliseconds for one conversion
24390 conversions per second.
2. This is not the first example of an efficient XSLT application. See my
article in xml.com "EXSLT for MSXML" at the end of which there is a
comparison table showing the timings of XSLT processors that implement the
Sets module of EXSLT.

The EXSLT implementation for MSXML4 was faster than 5 of them -- JD (Java),
4XSLT (Python), .Net xsltTransform (C#), xsltProc (C) and Xalan J 2.4.1
(Java).

For those, who don't know -- the (Sets module of) EXSLT support for MSXML4
is implemented in XSLT.

So, in this case the XSLT implementation outperforms implementations written
in such languages as C, C#, Java and Python.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #20

P: n/a
> > I am amazed. :-)

I am, too. You did 1 million in 7.6 seconds and Dimitre did 104 thousand in 7.5 seconds, yet his is slightly faster per conversion! That is truly
amazing. But I believe 7.6 * 10^-6 seconds is 7.6 microseconds, which is
0.0076 milliseconds.

Bob Foster


OK Guys,

I was also amazed.

Anyway, if something takes 0.073 milliseconds and is not the most frequently
performed operation, shall we agree that this will not be a cause for a
bottleneck in an application? Or even that an end user will not be able to
perceive the difference between this operation and one that takes 7.6
microseconds?

This was just my point.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #21

P: n/a
"Bob Foster" <bo********@comcast.net> wrote in message
news:Yz8eb.636183$Ho3.130300@sccrnsc03
You did 1 million in 7.6 seconds and Dimitre did 104
thousand in 7.5 seconds, yet his is slightly faster per conversion!
That is truly amazing.
Owned.
But I believe 7.6 * 10^-6 seconds is 7.6 microseconds, which is
0.0076 milliseconds.


Oops, stupid of me. I am one order of magnitude less amazed. ;-)

Martin
Jul 20 '05 #22

P: n/a
"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bl************@ID-152440.news.uni-berlin.de
I was also amazed.

Anyway, if something takes 0.073 milliseconds and is not the most
frequently performed operation, shall we agree that this will not be
a cause for a bottleneck in an application?
As this evolved to be an academic kind of discussion - no. ;-)
But in terms of portability, homogeneity of implemetation and common
sense - yes.
Or even that an end user will not be able to perceive the difference
between this operation and one that takes 7.6 microseconds?


Agreed.

Martin
Jul 20 '05 #23

P: n/a
"Martin Boehm" <ng********@arcor.de> wrote in message
news:3f***********************@newsread2.arcor-online.net...
Oops, stupid of me. I am one order of magnitude less amazed. ;-)


Easy mistake to make. So your original point was that you thought PHP would
be faster and it was 10 times faster. Point made.

Dimitre responds that if not done very often the difference between 73
microseconds and 7.6 microseconds is insignificant. Point made.

It's good to see some actual numbers in performance discussions! Hats off to
both of you.

Bob Foster
Jul 20 '05 #24

P: n/a

"Bob Foster" <bo********@comcast.net> wrote in message
news:fjKeb.651568$Ho3.135258@sccrnsc03...
"Martin Boehm" <ng********@arcor.de> wrote in message
news:3f***********************@newsread2.arcor-online.net...
Oops, stupid of me. I am one order of magnitude less amazed. ;-)
Easy mistake to make. So your original point was that you thought PHP

would be faster and it was 10 times faster. Point made.


Actually with the optimization I reported -- pre-calculating 1970-01-01 as a
Julian day number, the XSLT solution becomes twice faster.

Therefore the PHP to XSLT performance ratio in this case is 4-5 times
faster.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #25

P: n/a
"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bl************@ID-152440.news.uni-berlin.de
P.S.: Would you mind do post or mail the code you used so I can make
a direct comparison on that? Thanks!
Here it is -- just check (as I did) that the value of count($vNodes)
is 104:

[...code sample...]


For the sake of completeness, I ran the code on my machine, too.

I wrapped the transformation into VB (transformNode method), as it is a
little easier to access the complete time date (e.g. with milliseconds)
from there. I called the Win32 API function GetSystemTime for that
purpose.
1. This solution can be optimized still more by having a constant
for vBase (2440588) and not calculating it every time.
Done.

My input XML had 10.000 <timestamp> elements, and the XSL loop took 407
ms.
That breaks down to 0.0407 milliseconds per conversion.
0.041 milliseconds for one conversion
That is, 24570 converstions per second.
24390 conversions per second.


So, the 100 MHz my machine is faster make for an actual performance
increase of merely 0.74 percent. Or zero, in case you rounded the single
conversion time.

q.e.d.

Martin
Jul 20 '05 #26

P: n/a
Thanks. This matches exactly my timings.

Should I say that I enjoyed this dialog :o)
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Martin Boehm" <ng********@arcor.de> wrote in message
news:3f**********************@newsread4.arcor-online.net...
"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bl************@ID-152440.news.uni-berlin.de
P.S.: Would you mind do post or mail the code you used so I can make
a direct comparison on that? Thanks!


Here it is -- just check (as I did) that the value of count($vNodes)
is 104:

[...code sample...]


For the sake of completeness, I ran the code on my machine, too.

I wrapped the transformation into VB (transformNode method), as it is a
little easier to access the complete time date (e.g. with milliseconds)
from there. I called the Win32 API function GetSystemTime for that
purpose.
1. This solution can be optimized still more by having a constant
for vBase (2440588) and not calculating it every time.


Done.

My input XML had 10.000 <timestamp> elements, and the XSL loop took 407
ms.
That breaks down to 0.0407 milliseconds per conversion.
0.041 milliseconds for one conversion


That is, 24570 converstions per second.
24390 conversions per second.


So, the 100 MHz my machine is faster make for an actual performance
increase of merely 0.74 percent. Or zero, in case you rounded the single
conversion time.

q.e.d.

Martin

Jul 20 '05 #27

P: n/a
"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bl************@ID-152440.news.uni-berlin.de
Should I say that I enjoyed this dialog :o)


Me, too. And I learned a lot.

Thanks,

Martin
Jul 20 '05 #28

P: n/a
"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bl************@ID-152440.news.uni-berlin.de...
"Bob Foster" <bo********@comcast.net> wrote in message
news:fjKeb.651568$Ho3.135258@sccrnsc03...
"Martin Boehm" <ng********@arcor.de> wrote in message
news:3f***********************@newsread2.arcor-online.net...
Oops, stupid of me. I am one order of magnitude less amazed. ;-)
Easy mistake to make. So your original point was that you thought PHP

would
be faster and it was 10 times faster. Point made.


Actually with the optimization I reported -- pre-calculating 1970-01-01 as

a Julian day number, the XSLT solution becomes twice faster.

Therefore the PHP to XSLT performance ratio in this case is 4-5 times
faster.


My hat is always off to you. I'm continually amazed at what you can squeeze
out of XSLT.

Bob Foster
Jul 20 '05 #29

P: n/a
My hat is always off to you. I'm continually amazed at what you can squeeze out of XSLT.

Bob Foster


In this case our hats should be off to

Marrow,

who is the author of datetime_lib.xsl.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #30

This discussion thread is closed

Replies have been disabled for this discussion.