[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Type of a variable containing values of mixed type

Subject: Re: Type of a variable containing values of mixed types
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 13 Apr 2015 11:59:11 -0000
Re:  Type of a variable containing values of mixed type
The XQuery/XSLT type system treats sequences as homogenous, so you can only
constrain the item type and the cardinality (except where you're dealing with
elements validated against a schema, in which case the item type of the parent
can constrain the sequence of children according to the content model of an
XSD complex type).

In XQuery 3.0/XSLT 3.0 you can make greater use of union types:

<xsl:import-schema>
 <xs:schema>
  <xs:simpleType name="integer-or-date">
    <xs:union memberTypes="xs:integer xs:date"/>
  </xs:simpleType>
 </xs:schema>
</xsl:import-schema>

<xsl:variable name="var" as="int-or-date*" select="...."/>

but in 2.0 you have to declare such a sequence with as="xs:anyAtomicType*"/>

Michael Kay
Saxonica
mike@xxxxxxxxxxxx
+44 (0) 118 946 5893




On 13 Apr 2015, at 11:39, Jorge . chocolate.camera@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hi,
>
> I only seldom write XSLT (and specifically only 2.0) so there are many
> aspects of it that I am still not familiar with. After reading
> <http://www.ibm.com/developerworks/library/x-schemaawarexslt/index.html>
> I am forcing myself to declare the type of variables, parameters and,
> sometimes, templates. I have immediately seen the benefit of it as
> transformations I thought were simple and bug-free fail all over the
> place revealing cases I did not account for.
>
> How can I enforce that a variable contains a particular bunch of mixed
> types? Say:
>
>    <xsl:variable name="MY_VAR" as="">
>        <xsl:value-of select="42"/>
>        <xsl:value-of select="13"/>
>        <xsl:value-of select="hello"/>
>    </xsl:variable>
>
> Is there a way to enforce, with the attribute `as`, that the variable
> contains a series of integers and a string (or, even, particularly 2
> integers and 1 string) or else have the transformation fail?
>
> I am using Saxon-HE 9.2.1.2J.
>
> 
> Jorge

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.