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

Re: Checking for instance of xs:integer

Subject: Re: Checking for instance of xs:integer
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 12 Oct 2004 16:44:19 +0100
xs integer
Hi Kenneth,

> ...where I'm trying to detect if a variable has an integer value. The
> output that I currently get is :
>
> bash-2.05b$ java net.sf.saxon.Transform intck.xsl intck.xsl 
>
>                                 no
>
> At first I thought that this is because the xsl:value-of that is
> used to assign the value of $var/a was producing either a string or
> an untypedAtomic value. However, changing the "xsl:when" to test for
> xs:string and xsd:untypedAtomic didnt work either. Is there any way
> to get this to work without using a schema aware processor?

The result of the expression "$var/a" is a sequence containing an <a>
element. A sequence of elements is not the same as a sequence of
atomic values. Tests such as:

  $var/a instance of element()
  $var/a instance of element(a)

will evaluate as true.

Note that when you do:

  <xsl:value-of select="xs:integer(2)" />

the value of the select attribute is the integer 2 (there's no
requirement for the explicit cast), in fact. The <xsl:value-of>
instruction creates a text node; text nodes don't have types, so
doing:

  <xsl:value-of select="xs:integer(2)" />

is actually just the same as doing:

  <xsl:text>2</xsl:text>

In:

  <xsl:element name="a">
    <xsl:value-of select="xs:integer(2)" />
  </xsl:element>

The generated <a> element doesn't have any type associated with it.
So, for example:

  $var/a instance of element(*, xs:integer)
  $var/a instance of element(a, xs:integer)
  data($var/a) instance of xs:integer

will be false. The first two test whether the <a> element is typed as
an xs:integer. The second tests whether the typed value of the <a>
element is an xs:integer.

If you want the <a> element to be typed as an integer, and therefore
its typed value to be an instance of xs:integer, you can do (for
example):

  <a xsl:type="xs:integer">2</a>

and then the above instance of tests will be true.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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.