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: Mon, 13 Oct 2003 11:26:56 +0100
Hi Dave,

>> The 'as' attribute indicates the data type of the variable. Its
>> syntax is known as a SequenceType -- it describes a sequence of
>> items. The items are described by an item type, which can be item()
>> (any item), a node test or the name of an atomic type. The usual
>> occurrence indicators (?, +, *) mean the usual things (0-or-1,
>> 1-or-more, 0-or-more).
>> So in this case the items in the sequence are elements (indicated
>> by the node test "element()")
> ?? Which may be tested for using .... Jeni?

I don't understand what you're asking?

>   Its the 'as' attribute on Mikes xsl:variable that determines it to be
> an 'element' in this case?

Yes, or at least partly. If you have an 'as' attribute on
<xsl:variable> then it indicates the static type of the variable, but
the variable itself can be of a more specific type.

The "static type" is the type that the XSLT processor knows about when
it first goes through the styelsheet, or an XSLT editor might be able
to use: even without having an XML document to work on, the 'as'
attribute tells you what type of value the variable must hold. For
example, if I have:

  <xsl:variable name="foo" as="item()*">...</xsl:variable>

then the static type, indicated by the 'as' attribute, is any number
of any kind of item -- in other words, the variable could hold
anything at all.

If I have:

  <xsl:variable name="foo" as="xs:decimal" select="..." />

then the static type, indicated by the 'as' attribute, is a decimal

Contrast this with the "dynamic type", which is the type of the actual
value of the variable when you actually do the transformation on a
particular XML document. For example, if you have:

  <xsl:variable name="foo" as="item()*">
    <a /><b /><c />

then the static type is any number of any item but the value of the
variable is a sequence of three elements.

Similarly, if you have:

  <xsl:variable name="foo" as="xs:decimal" select="2" />

then the static type is a xs:decimal but the type of the variable's
value is a xs:integer.

As long as the dynamic type (the type of the value that the variable
gets set to) is a subset of the static type (the type of the variable
as declared by the 'as' attribute), you're OK.

> Ok. So (and I think I've asked this before and Mike quoted ?I think?
> xsd rec) where is the full list of ' data types' in the current raft
> of specs?
> lists the ones I guessed at.
> I couldn't find one, so I guess as with Dimitres 'misnaming',
> I (we?) will be fumbling with data types until we've guessed them all?

The SequenceType syntax is specified in the XPath 2.0 spec at:

It's impossible to give a complete list of sequence types because
user-defined data types can be imported into a stylesheet from a
schema, and of course there are infinite numbers of element and
attribute names. However, to summarize, a SequenceType can be:

  - "empty()"
  - an item type with an occurrence indicator; item types are:
    - "item()"
    - a node kind test, which are:
      - "node()"
      - a document node test, which can be:
        - "document()"
        - "document(element())"
        - "document(element(Name))"
        - "document(element(Name, *))"
        - "document(element(Name, Type))"
        - "document(element(*, Type))"
        - "document(element(SchemaPath))"
      - an element node test, which can be:
        - "element()"
        - "element(Name)"
        - "element(Name, *)"
        - "element(Name, Type)"
        - "element(*, Type)"
        - "element(SchemaPath)"
      - an attribute node test, which can be:
        - "attribute()"
        - "attribute(Name)"
        - "attribute(Name, *)"
        - "attribute(Name, Type)"
        - "attribute(*, Type)"
        - "attribute(SchemaPath)"
      - a processing instruction node test, which can be:
        - "processing-instruction()"
        - "processing-instruction(Name)"
      - "comment()"
      - "text()"
    - an atomic type, which can be any QName; common ones are:
      - "xdt:anyAtomicType"
      - "xs:string"
      - "xs:decimal"
      - "xs:double"
      - "xs:integer"
      - "xs:boolean"
      - "xs:date"
      - "xs:time"
      - "xs:dateTime"
      - "xdt:dayTimeDuration"
      - "xdt:yearMonthDuration"

For a full list of the built-in atomic data types, look in the F&O
spec at:

As I said, these atomic data types can be augmented with ones that you
define yourself, within a schema, so it's not possible to generate an
exhaustive list.

> Yes, you're probably right Jeni... but I'm not surprised,
> its got to be closer to xsl-fo complexity than xslt 1?

There's certainly more to learn in XSLT 2.0 than there was in XSLT
1.0, which isn't surprising considering that it can do that much more.



Jeni Tennison

 XSL-List info and archive:

Current Thread