Re: [xsl] Testing if a string begins with numeric in XSL 1.0

Subject: Re: [xsl] Testing if a string begins with numeric in XSL 1.0
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Tue, 20 Oct 2009 06:24:02 -0700
In addition to the good advice already received, if wewant to get the
starting number (not only the starting digit) within a string $s, one
way to express this with a single XPath expression is:


substring-before(translate(concat($s,'X'), translate($s, '0123456789',
''), 'X'), 'X')



--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
I enjoy the massacre of ads. This sentence will slaughter ads without
a messy bloodbath.

On Tue, Oct 20, 2009 at 1:28 AM, Adrian Stringer
<adrian.stringer@xxxxxxxxxxxx> wrote:
> Hi,
>
> Is this the correct/best way to test whether a string begins with a digit in
XSL 1.0?
>
> B  B <xsl:when test="string(number(substring($input-name, 1, 1))) !=
'NaN'">
>
> I guess using a regular expression in XSL 2.0 would be the best approach,
but unfortunately I'm constrained to using MSXSL and hence XSL 1.0 at the
moment.
>
> Thanks,
>
> Ade
>
> --
> Adrian Stringer
> Software Developer
> Direct Dial: 0845 265 6029
> Mobile:
>
> Motors.co.uk Ltd is registered in England and Wales with Company No.
5975777. B VAT registration GB 243 5711 74
> Registered address: Northcliffe House, 2 Derry Street, London W8 5TT.
B Motors.co.uk Ltd is a Daily Mail and General Trust plc company.
>
> This message and any attachments are intended for the named addressee only.
It contains information which may be confidential, legally privileged or
otherwise protected by law. B If you are not the intended recipient, please
telephone or email the sender and delete this message and any attachments from
your system. B If you are not the intended recipient you must not copy this
message or attachments or disclose the contents to any other person. Emails
are not secure and may contain viruses. Motors.co.uk reserves the right to
monitor all e-mail communications.

Current Thread