Re: [xsl] XSLT 1.1 comments -Examples please

Subject: Re: [xsl] XSLT 1.1 comments -Examples please
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 15 Feb 2001 13:01:41 GMT

> 1. A usage illustrating portability. Say get and re-format the date
>    in ecmascript, which could also use a java extension, as per DC comment.
>   - Regularly asked for? Reasonably 'safe'.

I just posted this off list to someone, may as well repost here (the
actual method and class names  don't work, but the basic
principle I hope is clear)


If you have a web form on which you get a date in the local language
settings and want to know if it is within a month of today, are you
really going to write a recursive xslt extension function to do that
or use a couple of lines to an extension language with built in locale
aware date handling? More than anyone I've argued for the benefits of
the functional approach, but I know which I would do. (Until XSLT n+1
when the feature gets added to XSLT)

Using xsl:script you can implement a date:number-of-days-between(a,b)
function that works for any XSLT 1.1 implementation that supports
javascript or vbscript or java. I don't think you can do that
in xslt 1.0 in any reasonable way.

in xslt 1.1 you make date: point of at any unique URI and then give 
multiple xsl:script to bind that URI to date related methods in whatever
target languages you are using.

in XSLT 1.0 you have to make date: point to a URI that is an xsl engine
specific prefix followed by a URI using the java class name, so it only
works on one engine, not even all the java ones.

(if had a method of that name, which it probably doesn't) 

This is what xsl:script is trying to avoid.

It means I can use

<xsl:value-of select="date:number-of-days-between($a,$b)"/>

rather than the XSL 1.0 equivalent

  <xsl:when test="function-exists('xt:number-of-days-between')">
    <xsl:value-of select="xt:number-of-days-between($a,$b)"/>
  <xsl:when test="function-exists('saxon:number-of-days-between')">
    <xsl:value-of select="saxon:number-of-days-between($a,$b)"/>
  <xsl:when test="function-exists('xalan:number-of-days-between')">
    <xsl:value-of select="xalan:number-of-days-between($a,$b)"/>
  <xsl:when test="function-exists('msxsl:number-of-days-between')">
    <xsl:value-of select="msxsl:number-of-days-between($a,$b)"/>

which is crazy, especialy given that the first three areeven using the
same class, thus the same code, just specified differently.

This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit

 XSL-List info and archive:

Current Thread