[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: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 13 Apr 2015 10:53:00 -0000
Re:  Type of a variable containing values of mixed type
Jorge . chocolate.camera@xxxxxxxxx wrote:


How can I enforce that a variable contains a particular bunch of mixed
types? Say:

     <xsl:variable name="MY_VAR" as="b&">
         <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?

Inside your variable with xsl:value-of you construct text nodes, not numbers or strings. If you want to output an integer then use e.g.


<xsl:sequence select="42"/>


to construct a string literal use e.g.


<xsl:sequence select="'hello'"/>

As for the "as" attribute, you can use

as="item()*"

to make sure you get a sequence of values and not a temporary tree.

I am not sure a union type would help to allow only integers and strings, but I am sure you can't specify that a sequence is made up of two integers followed by one string. You would need to define a complex type with a sequence of two elements of type xs:integer and a third element of type xs:string and then would need a schema-aware processor which Saxon HE not is. And it would no longer be a sequence of atomic types but rather a sequence of elements.

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.