xsl-list
[Top] [All Lists]

Re: testing for string and number in XSLT 2.0 was Re: [xsl] Test For Numeric Values?

2005-04-09 15:56:12
On Apr 10, 2005 3:59 AM, Michael Kay <mike(_at_)saxonica(_dot_)com> 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>