?
Solved

variable doesn't contain a number

Posted on 2012-08-30
4
Medium Priority
?
260 Views
Last Modified: 2012-09-25
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
0
Comment
Question by:Al4ddin2
  • 3
4 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 38349484
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 38349490
your compound test would be

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

Author Comment

by:Al4ddin2
ID: 38349579
Thanks Gertone,

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

Thanks
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 38349623
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question