Project

Profile

Help

Schematron Validation line and column error

Added by Sathya Selva about 4 years ago

Dear Team,

code:

                String xslFile = "xsl_File";
		try {
			StringWriter stringwriter = new StringWriter();
			processor.setConfigurationProperty(Feature.RECOVERY_POLICY, Configuration.RECOVER_SILENTLY);
			XsltCompiler compiler = processor.newXsltCompiler();
			XsltExecutable xslStylesheet = compiler.compile(new StreamSource(new File(xslFile)));
			Serializer out = processor.newSerializer();
			out.setOutputProperty(Serializer.Property.ENCODING, "UTF-8");
			out.setOutputProperty(Serializer.Property.METHOD, "xml");
			
		    out.setOutputWriter(stringwriter);
			XsltTransformer transformer = xslStylesheet.load();
			XdmNode source = processor.newDocumentBuilder().build(new File(System.getProperty("user.dir") + FS +"temp"+FS+"josl_12364.xml"));
			transformer.setInitialContextNode(source);
			transformer.setDestination(out);
			transformer.transform();
			System.out.println(stringwriter);


Output:

<svrl:successful-report test="contains($titleData1,$iTData1)"
                           id="SPS-000340b"
##                          **  line="-1"
##                            column="-1">**
      <svrl:text>[SPS-000340b] [Gl.:‘oh okay this one’] Partial italic not allowed inside title</svrl:text>
   </svrl:successful-report>


line and column number shows -1 please do the needful

Thanks in advance


Replies (5)

Please register to reply

RE: Schematron Validation line and column error - Added by Michael Kay about 4 years ago

After doing processor.newDocumentBuilder(), please call setLineNumbering(true) on the resulting document builder.

I don't guarantee this will work because I don't know the schematron processor, but it's the first step to ensuring that line and column information are retained during parsing.

The saxon:line-number() function is available only in Saxon-PE and higher, so that may affect things too.

RE: Schematron Validation line and column error - Added by Sathya Selva about 4 years ago

Dear Michael Kay, I tried your suggestion but it not work, please give some other suggestion my code

StringWriter stringwriter = new StringWriter();
			processor.setConfigurationProperty(Feature.RECOVERY_POLICY, Configuration.RECOVER_SILENTLY);
			XsltCompiler compiler = processor.newXsltCompiler();
			XsltExecutable compiledStylesheet = compiler.compile(new StreamSource(new File(xslFile)));
			Serializer out = processor.newSerializer();
			out.setOutputProperty(Serializer.Property.ENCODING, "UTF-8");
			out.setOutputProperty(Serializer.Property.METHOD, "xml");
			out.setOutputWriter(stringwriter);
			XsltTransformer transformer = compiledStylesheet.load();
			XdmNode source = processor.newDocumentBuilder().build(new StreamSource(new StringReader(data)));
			processor.newDocumentBuilder().setLineNumbering(true);
			transformer.setInitialContextNode(source);
			transformer.setDestination(out);
			transformer.transform();
			System.out.println(stringwriter);

RE: Schematron Validation line and column error - Added by Sathya Selva about 4 years ago

I'm using Saxon9EE Version with License

RE: Schematron Validation line and column error - Added by Michael Kay about 4 years ago

You are now calling newDocumentBuilder() twice, to create two document builders; you build the source document with one of them, and you set line numbering on the other. You need

DocumentBuilder builder = processor.newDocumentBuilder();
builder.setLineNumbering(true);
XdmNode source = builder.build(new StreamSource(new StringReader(data)));

RE: Schematron Validation line and column error - Added by Sathya Selva about 4 years ago

Dear Michael Kay,

DocumentBuilder builder = processor.newDocumentBuilder();
builder.setLineNumbering(true);
XdmNode source = builder.build(new StreamSource(new StringReader(data)));

Above the Code Working Perfectly, Thank you for your Knowledge sharing

    (1-5/5)

    Please register to reply