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

Subject: Re: [xsl] Constructor functions & `cast as` -- why both?
From: Frans Englich <frans.englich@xxxxxxxxx>
Date: Tue, 5 Jul 2005 13:56:19 +0000
On Monday 04 July 2005 19:38, Dimitre Novatchev wrote:
> On 7/5/05, Frans Englich <frans.englich@xxxxxxxxx> wrote:
> > Hi,
> >
> > According to the XPath specifications are constructor functions and the
> > cast expression defined to be semantically equivalent. I wonder, why then
> > provide both?
> >
> > Here my speculation:
> >
> > * The two uses different default namespaces. Hence, it can be practical
> > on the stylesheet-writing level. But this aspect is not more than
> > convenience, right?
> >
> > * A usability aspect of the language. One might argue that multiple ways
> > of expressing the same thing allows users to choose their way which fits
> > them the best(a psychological aspect). _For example_, the `cast as`
> > expression can be percepted as changing the type of an existing value,
> > while a constructor function can be percepted as creating a new value.
> >
> > What was the reasoning for creating the two?
>
> A "cast as" expression is a synonym for using a constructor function,
> except in two cases, where a constructor function cannot be used:
>
>   - If the "?" must be used after the atomic type name to express that
> an empty sequence is allowed.
>
>   - If there is no target namespace for the schema defining the type
> (the type is in no namespace) -- in this case a constructor function
> with no namespace prefix will bind to the default namespace of the
> core functions (F & O).

Dimitre, Michael, thanks for the explanations.


> BTW, this is the second question you ask, the perfect answer to which
> can be easily found in Mike Kay's book "XPath 2.0 Programmer's
> Reference" -- ISBN: 0-764-56910-4

Yes, I've heard only good about them. I'll definitely get a copy when I have 
the money.


Cheers,

		Frans

Current Thread