[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XSLT function optimization - datetime comparisons?

Subject: RE: XSLT function optimization - datetime comparisons?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 22 Sep 2005 12:39:37 +0100
xslt datetime
The reason it doesn't work in Xalan is that xsl:function is an XSLT 2.0
construct, and Xalan doesn't support XSLT 2.0.

It's probably marginally faster to use Saxon's native dateTime support, but
I doubt it makes a very big difference:

<xsl:function name="my:compDate" as="xs:boolean">
  <xsl:param name="dt_a" as="xs:string" />
  <xsl:param name="dt_b" as="xs:string" />
  <xsl:sequence select="xs:dateTime(dt_a) gt xs:dateTime(dt_b)"/>
</xsl:function>

This isn't 100% identical, for example Saxon will throw a wobbly if the date
is 2005-02-29.

Note that you could use the <xsl:sequence select="(boolean expression)"/> in
your version as well.

Also, you could get rid of all three punctuation characters in a single call
on translate.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Jeffrey Schrab [mailto:jschrab@xxxxxxxxxxxx] 
> Sent: 21 September 2005 20:53
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  XSLT function optimization - datetime comparisons?
> 
> I don't profess to be well seasoned in XSLT.  Simply put I 
> have a function that I call an awful lot in stylesheet.  I'm 
> wondering if I'm being very inefficient about how it's coded. 
>  Does anyone have any comments how best to do the comparison 
> that I'm doing below for datetimes of the form YYYY-MM-DDTHH:MM:SS ?
> 
> I'm using Saxon - I found that Xalan (2.7) just couldn't do 
> this sort of thing for reasons I don't understand to this day.
> 
> 
> <xsl:function name="my:compDate" as="xs:boolean">
> 	<xsl:param name="dt_a" as="xs:string" />
> 	<xsl:param name="dt_b" as="xs:string" />
> 	<xsl:choose>
> 		<xsl:when test="
> xs:integer(translate(translate(translate($dt_a,'-',''),'T','')
> ,':','')) gt 
> xs:integer(translate(translate(translate($dt_b,'-',''),'T','')
> ,':',''))">
> 			<xsl:copy-of select="true()"/>
> 		</xsl:when>
> 		<xsl:otherwise>
> 			<xsl:copy-of select="false()"/>
> 		</xsl:otherwise>
> 	</xsl:choose>
> </xsl:function>
> 
> -- 
> Jeffrey Schrab
> Internet Application Developer
> 
> GS Design
> 6665 N. Sidney Place
> Milwaukee, WI 53209
> 
> P: 414.228.9666
> F: 414.228.9652
> E: jschrab@xxxxxxxxxxxx http://www.gsdesign.com

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.