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

Re: testing for string and number in XSLT 2.0 was Re:

Subject: Re: testing for string and number in XSLT 2.0 was Re: Test For Numeric Values?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sun, 10 Apr 2005 08:56:12 +1000
xdt untypedatomic
On Apr 10, 2005 3:59 AM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> > I repeated your experiment with Saxon 8.4, changing only the variable
> > definition of $y to:
> >
> >       <xsl:variable name="y" select="data(example/test/text())"/>
> >
> > and still got:
> >
> >        $y variable value: 132131
> >        Test as string:false
> >        Test as integer:false
> >
> > It seems to me that the test as xs:string should be positive, because
> > the typed value of a text node must be by definition xs:string.
> >
> 
> No, the typed value of a text node is by definition untypedAtomic - see
> 
> http://www.w3.org/TR/xpath20/#id-typed-value
> 
> untypedAtomic is a chameleon type that is automatically cast to the type
> required by the context where it is used.


Yes, I saw this in the spec, too.

I have two questions:

  1. What was the reason for the decision that the typed value of a
text node must be of type xdt:untypedAtomic ? If the node is a *text*
node, then its value must be *text* -- that is *string*.


  2. I didn't find in the F & O spec any explanation why a value
comparison (such as lt) of two xdt:untypedAtomic values treats them as
strings. Why not as integers? Why/how this happens? Is there something
like a "preferred/default datatype" for the value-comparison
operators? Isn't it more practical to have xs:string as the chameleon
datatype?

For example, I have this source xml document:

<t>
 <num>1</num>
 <num>02</num>
</t>


and this transformation:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes" 
 exclude-result-prefixes="xs xdt"
 >
  
 <xsl:template match="/">
  <xsl:variable name="v1" select="data(/*/*[1])"/>
  <xsl:variable name="v2" select="data(/*/*[2])"/>
  
  $v1: '<xsl:value-of select="$v1"/>' 
  $v2: '<xsl:value-of select="$v2"/>' 
  
  $v1 instance of xdt:untypedAtomic: <xsl:value-of select="$v1
instance of xdt:untypedAtomic"/>
  $v2 instance of xdt:untypedAtomic: <xsl:value-of select="$v2
instance of xdt:untypedAtomic"/>
  
  $v1 lt $v2: <xsl:value-of select="$v1 lt $v2"/>
  $v1 gt $v2: <xsl:value-of select="$v1 gt $v2"/>
 </xsl:template>
</xsl:stylesheet>

produces this result:

  $v1: '1' 
  $v2: '02' 
  
  $v1 instance of xdt:untypedAtomic: true
  $v2 instance of xdt:untypedAtomic: true
  
  $v1 lt $v2: false
  $v1 gt $v2: true

So we see that the two values of type xdt:untypedAtomic are treated as
xs:string by the value-comparison operators.


Cheers,
Dimitre Novatchev

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.