Re: [xsl] Re: XSLT 2.0: On xsl:sequence and xsl:copy-of

Subject: Re: [xsl] Re: XSLT 2.0: On xsl:sequence and xsl:copy-of
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 14 Oct 2003 12:20:26 +0100
Hi Dave,

>> So, you *can* use the 'as' attribute to do implicit casting.
> But only between a subtype and super of that subtype?

No. There is never a need to cast a value from a subtype to a
supertype, because a value of the subtype is *by*definition* a value
of the supertype already. For example, the xs:integer 2 is a
xs:decimal value.

The implicit casting is mainly used when casting from an untyped value
(of a node) to a particular type. For example, casting the value of
the 'dob' attribute to a xs:date. In this case, the type of the value
of the node (xdt:untypedAtomic) is not a subtype of the type to which
it's being cast (xs:date).

(The other time it's used is when promoting values from xs:decimal to
xs:float or xs:double, and from xs:float to xs:double.)

>> >  I was checking my understanding of the nesting?
>> >   Is it the 'subtype' mentioned above?
>> >     E.g. you had 
>> >              "a node()
>> >                 "element()
>> >                    "element(Name, Type)
>> >
>> > Can I read that as element is a subtype of node,
>> No, you can't read the list like that. But it is true that an element
>> node would match a SequenceType of "node()".
> I think this is just down to being exact in terms of terminology?

Possibly, but just because document-node() comes earlier in the list
that I gave than element() doesn't mean that you can provide an
element where a document-node() is expected.

>> >     the last line I'm less sure of.
> I meant the line "                   "element(Name, Type)    "

Ah. Basically, "element(Name, Type)" only matches elements that are
called "Name" and have a type "Type". For example, "element(Start,
xs:dateTime)" will match elements called <Start> with a type of
xs:dateTime. (It's a bit more complicated than that, because of
element substitution groups, but I won't go into that because you've
said you don't care about schema-aware processing.) The type is
assigned when the element is validated against a schema (which it
might be when it's generated using XSLT).

In basic XSLT, all elements have the type xdt:untypedAny (xs:anyType
in the current specs, but I think that's going to change), so if
you're using basic XSLT then you don't have to worry about this kind
of test. The only element node tests you will be interested in are:

  - element()
  - element(Name, *)

which match all elements, and all elements with a particular name,

> Which raises another question.
>   I can see how the simpler ones from your list might be used
> as a value for the as attribute,
> <xsl:variable name="fred" as="xs:integer">
> but how might element(elementName, xs:integer)  be used?

If you wanted to say that the variable holds an element called
"elementName" whose type is xs:integer. For example, when setting the
variable with:

  <xsl:variable name="fred" as="element(elementName, xs:integer)">
    <elementName xsl:type="xs:integer">4</elementName>

Note that SequenceTypes are used in other places as well as in the
'as' attribute on variable-binding elements. For example, you might
want to say that a function returns a sequence of <value> elements of
type xs:integer:

<xsl:function name="my:get-values" as="element(value, xs:integer)">

And note that this currently only applies in schema-aware XSLT
processors. If you try to use a SequenceType like this in a basic XSLT
processor, you will get an error.



Jeni Tennison

 XSL-List info and archive:

Current Thread