xsl-list
[Top] [All Lists]

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

2005-04-08 04:32:51

The xsl:analyze-string construct could be written more simply as

<xsl:value-of select="matches($select, '[\d]+')"/>
 

i like the matches() function...neat

this is fine and dandy in a basic XSLT 2.0 processor, and potentiall
could be extended, though I find it uncomfortable that xsl:function
automatically casts my params as xs:string when there is no 
declaration,
   


It doesn't. If you don't declare the types of your parameters then they
actual values supplied in the function call are passed through unchanged.

 

ok understand, btw I assume that tunnel params are not in affect within
params in xsl:functions....

so doing something like the following (in an XSLT 2.0 
processor that is
schema aware).


       Test X (xs:integer) matching string
       using istype:<xsl:value-of select="type:istype($x,'number')"/>
       using isnumber:<xsl:value-of select="type:isnumber($x)"/>
       using isstring:<xsl:value-of select="type:isstring($x)"/>
   


This doesn't require a schema-aware processor, you aren't doing anything
here that's not available in a basic processor
 

ok..yes David just corrected me


will through out an error, I guess I could employ the 
use-when attribute
to check for schema conformance (does this exist as a system 
property?).
   


Yes it does but you don't need it here
 

btw, does anyone else find it weird that xsl:function doesnt have the
ability to prescribe a return type ?...I wanted to return a boolean
type...
   


Then (a) declare the type

<xsl:function name="x" as="xs:boolean">
 


yes just discovered this as well...feels right, though once again not
the use of XML Schema datatypes....or the option not to use them.

and (b) return a value of that type

<xsl:sequence select="matches($arg, '\d+')"/>

In fact, I think the function you want is:

<xsl:function name="type:is-number" as="xs:boolean">
 <xsl:param name="arg" as="xs:string"/>
 <xsl:sequence select="matches($arg, '\d+')"/>
</xsl:function>

 

so explain to me the scenario

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

<xsl:function name="type:is-number" as="xs:boolean">
  <xsl:param name="arg" as="xs:string"/>
  <xsl:sequence select="matches($arg, '\d+')"/>
</xsl:function>

hehe, no pls dont answer that! really I understand now; 

the fact that BASIC conformance meant XML Schema datatypes are still being used 
completely went under my radar...so I now understand that value for BASIC 
conformance is directed towards implementators...

many thx for taking the time to answer my lame questions.

jim






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