RE: [xsl] Constructor functions & `cast as` -- why both?

Subject: RE: [xsl] Constructor functions & `cast as` -- why both?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 5 Jul 2005 09:43:28 +0100
> According to the XPath specifications are constructor 
> functions and the cast 
> expression defined to be semantically equivalent. I wonder, 
> why then provide 
> both?

There were two reasons for retaining the "cast as" syntax after constructor
functions were introduced:

(a) "cast as" gives you the choice of whether to allow an empty sequence as
the operand (returning an empty sequence as the answer) or not.

(b) constructor functions aren't available for types whose names are in no
namespace, unless you want to namespace-qualify all system functions with
fn: (e.g. fn:count()). Since many people use no-namespace schemas, and
they're quite likely to include types with names that clash with system
functions, no-one could come up with a way of handling these other than
retaining the "cast" syntax.

Remember that committees find it much easier to add something to a language
than to take something out.

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

Current Thread