Subject: Re: [xsl] testing for string and number in XSLT 2.0 was Re: [xsl] Test For Numeric Values? From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Sat, 9 Apr 2005 20:27:13 +1000 |
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.fuller@xxxxxxxxxxxxxx> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] testing for string and nu, James Fuller | Thread | RE: [xsl] testing for string and nu, Michael Kay |
Re: [xsl] testing for string and nu, James Fuller | Date | Re: [xsl] Compatibility question, António Mota |
Month |