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 03:27:13
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.

I would appreciate Mike's comments on this.


Cheers,
Dimitre Novatchev



On Apr 9, 2005 7:27 PM, James Fuller 
<jim(_dot_)fuller(_at_)ruminate(_dot_)co(_dot_)uk> wrote:
Michael Kay wrote:

take for example xsl:sort

<xsl:sort select="." data-type="number"/>

what does 'number' mean here?



It's retained for backwards compatibility with XSLT 1.0; the "native" way of
doing this in 2.0 would be

<xsl:sort select="xs:double(.)"/>

if they are doubles, or more likely

<xsl:sort select="xs:integer(.)"/>

if they are integers.



thx for clarification and generally letting me indulge...its much easier
to fire off questions whilst reading the specs..

and if we are comfortable with this type of ambiguity of identifying
something purely as a 'number'....then why not have some fairly useful
functions such as is-number() and is-string() that exist in
this no mans land.



You're welcome to write your own function is-string($x) that has the same
effect as the expression ($x instance of xs:string), but the WG wants to
avoid bloating the language with redundant ways of doing the same thing.


agree with avoiding bloat, esp if we are duplicating
functionality....just a final point....

using Saxon 8.1b

EX. XML
<?xml version="1.0" encoding="UTF-8"?>
<example>
   <test>132131</test>
</example>

EX. XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   version="2.0"
   xmlns:xs="http://www.w3.org/2001/XMLSchema";>

   <xsl:output method="xml" indent="yes"/>

   <xsl:variable name="x" select="example/test" as="xs:integer"/>
   <xsl:variable name="y" select="example/test"/>

   <xsl:template match="example">

       $y variable value: <xsl:value-of select="$y"/>
       Test as string:<xsl:value-of select="$y instance of xs:string"/>
       Test as integer:<xsl:value-of select="$y instance of xs:integer"/>

       I would expect this to be true as I have explicitly cast x as an
integer
       $x variable value: <xsl:value-of select="$y"/>
       Test as an integer: <xsl:value-of select="$x instance of
xs:integer"/>

   </xsl:template>

</xsl:stylesheet>

I get the following result;

       y variable value(so we know we are selecting it): 132131
       Test y as string:false
       Test y as integer:false

       I would expect this to be true as I have explicitly cast x as an
integer
       x variable value:132131
       test x as integer: true

not sure if this is what I would expect normally, the issue is related
to an element if if has no explicitly declared data-type..

the above behavior works the same way if I just reference the element
(example/test) and dont use a variable...though I wanted to highlight
that there are a few steps where an XSLT Processor may have to *decide*
what datatype it is.

it doesnt make much sense to me to *have* to declare something as an
integer datatype to test if its a value is a number...whats the point?

I know this is quite a speculative thread and apologies to list for
going on...

cheers, Jim Fuller


--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>