Project

Profile

Help

How to specify the xsd schema used to validate with saxon:validate in XSLT

Added by Alex Muir over 10 years ago

Hi,

I'm reading the documentation here

http://www.saxonica.com/documentation/functions/saxon/validate.html but I'm not clear on how to specify which schema file is being used to validate.

Would be helpful to see an xslt example of how to saxon:validate.

Thanks Alex


Replies (8)

Please register to reply

RE: How to specify the xsd schema used to validate with saxon:validate in XSLT - Added by Michael Kay over 10 years ago

The validation will be done using the schema components present in the configuration, plus any additional schema components loaded using an xsi:schemaLocation attribute in the instance document.

The schema comonents present in the configuration include:

  • any that were loaded using xsl:import-schema in the stylesheet

  • any that were loaded to validate other input documents

  • any that were loaded frome the command line using the -xsd option

It would be useful to know more about your use case, that would make it easier to help you, and easier to improve the documentation.

RE: How to specify the xsd schema used to validate with saxon:validate in XSLT - Added by Alex Muir over 10 years ago

Thanks very much,

The use case is when a user uploads a xml and a xsd file to a website and I need to validate them prior to continuing processing within xproc.

Those instructions though are what I needed.

On Mon, Mar 17, 2014 at 1:12 PM, Saxonica Developer Community < > wrote:

RE: How to specify the xsd schema used to validate with saxon:validate in XSLT - Added by Alex Muir over 10 years ago

Hi, I've just found some time to look at this validation aspect again. The problem I'm having is the 'valid' result in the map is always true regardless of the xml file being invalid

I'm running the following cmd with an xml file that simply changes the name of one element. The file is detected as invalid and so to run I added the outval parameter

#!/bin/bash

xml_file="/var/www/ elt.kode1100.com/public_html/wiki/automation/TestData/validate/elt.test.datatypes.xml " xsd_file="/var/www/ elt.kode1100.com/public_html/wiki/automation/TestData/validate/elt.test.datatypes.xsd " validationReportHREF="/var/www/ elt.kode1100.com/public_html/wiki/automation/TestData/validate/validationResult.xml "

java -jar ../../../../lib/saxon9ee.jar -outval:recover -val:strict -s:${xml_file} -xsd:${xsd_file} -xsl:../../scripts/xsl/validate.xsl -o:${validationReportHREF}

with the following template in a xslt 3.0 file

Any thoughts on what I'm doing wrong Thanks

On Tue, Mar 18, 2014 at 9:29 AM, Saxonica Developer Community < > wrote:

RE: How to specify the xsd schema used to validate with saxon:validate in XSLT - Added by Michael Kay over 10 years ago

Is there some code missing after "the following template"?

I think it would be useful to submit a repro: a complete working example that we can run here to reproduce what is going on. I don't currently have enough information to respond.

RE: How to specify the xsd schema used to validate with saxon:validate in XSLT - Added by Michael Kay over 10 years ago

OK, when I run:

java com.saxonica.Validate -t -xsd:elt.test.datatypes.xsd -s:elt.test.datatypes.xml

I get

Validation error on line 15 column 22 of elt.test.datatypes.xml: XSD99999: In content of element <test.datatypes>: The content model does not allow element <Period.of.xxx.year> to appear immediately after element <Recurring.period.of.time.yearl...>. Expected <Period.of.one.year>. Validating /test.datatypes[1]/Period.of.xxx.year[1] Validation error on line 100 column 18 of elt.test.datatypes.xml: XSD99999: One or more validation errors were reported

which is presumably what's expected.

When I run

java net.sf.saxon.Transform -t -xsl:validate.xsl -s:elt.test.datatypes.xml -xsd:elt.test.datatypes.xsd

I get

false

which is presumably also what's expected.

If I add -val:strict I get

Validation error on line 15 column 22 of elt.test.datatypes.xml: XTTE1510: In content of element <test.datatypes>: The content model does not allow element <Period.of.xxx.year> to appear immediately after element <Recurring.period.of.time.yearl...>. Expected <Period.of.one.year>. Validating /test.datatypes[1]/Period.of.xxx.year[1] Validation error on line 100 column 18 of elt.test.datatypes.xml: XTTE1510: One or more validation errors were reported Transformation failed: Run-time errors were reported

because the validation is now happening during the initial reading of the source document, not under the control of saxon:validate().

Adding -outval:recover now outputs validation errors to the console, and then gives

true

which is the first result that surprises me, given that -outval is specified as only affecting the validation of result documents, and you aren't validating the result document. I suspect that what is happening is that -outval is affecting both the validation done using -val:strict and the validation done using saxon:valdidate, so that all validation errors are treated as non-fatal and the validation is treated as if it succeeded. So there are really two issues here: should -outval affect validation of anything other than the result document? And if it should affect saxon:validate(), it should not cause the document to be reported as valid just because validation is considered to have succeeded.

RE: How to specify the xsd schema used to validate with saxon:validate in XSLT - Added by Alex Muir over 10 years ago

Is there a way to get false from the validation when running the -jar style of invocation?

java -jar ../../../../lib/saxon9ee.jar -outval:recover -val:strict -s:${xml_file} -xsd:${xsd_file} -xsl:../../scripts/xsl/validate.xsl -o:${validationReportHREF}

or is

java net.sf.saxon.Transform -t -xsl:validate.xsl -s:elt.test.datatypes.xml -xsd:elt.test.datatypes.xsd

the only way to achieve it?

"-outval:(recover|fatal)

Normally, if validation of result documents is requested, a validation error is fatal. Setting the option -outval:recover causes such validation failures to be treated as warnings. The validation message is written both to the standard error stream, and (where possible) as a comment in the result document itself." Some part of me feels it makes sense as written so either it should be rewritten or perhaps it requires a third parameter for this case like bypass or uservalidate

along with some logic adjustment.

Thanks

On Fri, Apr 4, 2014 at 4:25 PM, Saxonica Developer Community < > wrote:

RE: How to specify the xsd schema used to validate with saxon:validate in XSLT - Added by Michael Kay over 10 years ago

I tend not to use the -jar invocation because you can't specify additional things to go on the classpath (such as the license file), but it invokes exactly the same code as specifying net.sf.saxon.Transform as the entry point.

    (1-8/8)

    Please register to reply