|
Subject: Re: [xsl] testing for string and number in XSLT 2.0 was Re: [xsl] Test For Numeric Values? From: James Fuller <jim.fuller@xxxxxxxxxxxxxx> Date: Sat, 09 Apr 2005 11:27:15 +0200 |
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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] testing for string and nu, David Carlisle | Thread | Re: [xsl] testing for string and nu, Dimitre Novatchev |
| Re: [xsl] Compatibility question, Camaleón | Date | Re: [xsl] testing for string and nu, Dimitre Novatchev |
| Month |