Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

X-Path Validation

Status
Not open for further replies.

noslenwerd

Programmer
May 2, 2005
59
US
Basically what I need to do is set up an X-Path Expression on an input field that will only allowed the following...

- One will only allow dates in the following format mm/dd/yyyy BUT will also accept 'NA'

- Also need another field that will only accept 'NA', any number, a comma, and a decimal.

I know how to set the two up using xsd, but the program we have has limitation and I must use x-path to validate these.

This is the NA/FormattedDate type in the xsd

<xs:pattern value="((0[1-9]|1[012])[/.](0[1-9]|[12][0-9]|3[01])[/.](19|20)\d\d)|NA|N[/.]A"/>

This is the na/comma/decimal type in the xsd

<xs:pattern value="([1-9]{1}[0-9]{0,2}(,[0-9]{3})*(\.[0-9]{0,2})|NA|N[/.]A)"/>

Any help on this? Or any good online resources on how to get started with this? I never had to write an expression like this in x-path so any help would be great.
 
XPath is not a validation language. XPath is a means to address different parts of an XML document.

I think that we can be more helpful if you give us an idea of the problem you need to solve, rather than some particular (in this case, nonexistant) solution to the problem.

the program we have
And that program is...?

has limitation
What limitation?

I must use x-path to validate these
What led you to this conclusion?

Tom Morrison
 
- The program we are using is Altova StyleVision.
- The limitation is the message returned to users, when data they input into an input field is invalid according to the schema,... the message returned to the user is cryptic and not helpful at all. The only way to modify the message a user sees is to set up x-path. For instance I tested it out making the user input a number between 1 and 100, and the error message would be "Please input a number between 1-100" if the user entered an invalid value.

- I was led to this conclusion through a help call i had opened with altova. They insist that there is no way to modify the message returned to the user when it is validated against the schema. Our project manager insists that we must have a more user friendly message returned to them and the only way to do this is setting up an x-path expression.
 
XPath and XML Schema are two different things.

Altova StyleVision is used to create XSLT stylesheets. A quick check of the Altova web site does not show a schema validation feature within StyleVision.

If you are getting a forum or email response from Altova, perhaps you can share it here.

So, we still have not identified exactly what program is returning this message to users. Your users are not using StyleVision...

Tom Morrison
 
Okay, found that StyleVision claims that it does XML Schema validation. HAve fun talking to Altova about this...

Tom Morrison
 
I understand that the schema and x-path are two different things.

Altova does infact validate against the schema, the problem is you CANNOT change the error message the user reads. For instance, see the below screen shot. This is what appears when a user enters incorrect information and it checks against the schema


Above is just a for instance... we have a Money type set up for this element and therefor will not accept letters. This error will confuse your everyday user.

The screen shot below is where I can enter in specific x-path expressions and a correlating custom error message


This is basically my only option in letting the user know what they entered is incorrect, and this is why I must use x-path expressions to set something like this up.

The program sending the litle yellow box you see above, is actually the SPS file (altova StyleVision specific) live on our test site.

Thank you very much for taking the time to help.
 
Haha it has been very "fun" talking to Altova about this. Their help call system is horrible, no phone support, and it takes 3 days to get any kind of email response from them. Also the info they supply is usually very vague and unhelpful.
 
With those clues, I have a slightly better understanding of the issue.

It appears that you are being asked to construct the test attribute for an <xsl:if> or <xsl:when> XSLT processing instruction. These indeed are XPath expressions that are testing a condition in the context of a node or nodeset.

So, you should be able to find the corresponding place in the stylesheet (XSL) that is created and see the effect of your input.

Now for the bad news: XPath does not have regular expressions, so you will have to generate a rather complicated expression from the available functions and boolean operators. This is certainly possible, but it might not be as pretty as a regular expression.

My guess is that the SPS file is something that is feeding JavaScript in your browser. Check the page source for clues.

Tom Morrison
 
Great thanks for all your help... turns out something like this works...

matches( . , '^([0-9]*|[1-9]{1}[0-9]{0,2}(,[0-9]{3})*|NA|N/A|N\.A\.)$' )

This accepts a valid number with a comma in the correct place, N/A, NA etc.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top