variable doesn't contain a number

Hi,

I would like to do a check to see if a ID contains a number - this can feature anywhere in the ID...
<xsl:when test="not(contains($ID, '1234567890'))">

This doesn't seem to be working.

Also, I may want to add a second condition like

<xsl:when test="$productName='test' and not(contains($ID, '1234567890'))">

Can anyone assist?

Thanks
Al4ddin2Asked:
Who is Participating?
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
Here is how translate works

translate($ID, '1234567890', '')

replaces every occurence of a character in the second argument as found in the first argument with the character found in the same location in the third argument

translate($ID, 'ab', 'AB')
replaces every 'a' in $ID with a 'A' and every 'b' in $ID with a 'B'

if there is nothing in the third argument, the character will be dropped

translate($ID, 'ab', 'A')
replaces every 'a' in $ID with 'A' and drops every 'b'

translate($ID, '1234567890', '')
drops every number in $ID
if this returns something that is still the same as the original $ID, you know there weren't any numbers

if you add more characters, the test will be stricter

translate($ID, '1234567890&amp;()', '')
is what you need
(note that the parser will make the &amp; an &
0
 
Geert BormansInformation ArchitectCommented:
contains() works on a string, not per character
you can translate the numbers away and see if it still equal

test="translate($ID, '1234567890', '') = $ID"

this test will be true when there are no numbers in $ID
0
 
Geert BormansInformation ArchitectCommented:
your compound test would be

<xsl:when test="$productName='test' and translate($ID, '1234567890', '') = $ID">
0
 
Al4ddin2Author Commented:
Thanks Gertone,

What about if it contains special characters i.e. &() etc.

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.