Skip to content

Schematron support appears to not work #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tgraham-antenna opened this issue May 7, 2025 · 10 comments
Open

Schematron support appears to not work #150

tgraham-antenna opened this issue May 7, 2025 · 10 comments

Comments

@tgraham-antenna
Copy link
Contributor

I have renamed elements and attributes in test.sch from the Git repository to make them invalid, and VS Code does not complain.

How is the Schematron support supposed to work?

@pgfearo
Copy link
Member

pgfearo commented May 7, 2025

Current Status of Schematron Validation

If I recall correctly, the Schematron validation was disabled some time ago in the absence of any user feedback.

If you open a Schematron file, you will find that the only Schematron specific support is syntax-highlighting of XPath in attributes like context. The is not validation of the XML or XPath.

The documentation for the extension does not I believe claim Schematron support.

There is admittedly code in place for Schematron but it is incomplete. I believe I paused work on this because at DeltaXignia we require many XSLT 3.0 features and therefore use non-standard extensions to Schematron which caused spurious errors (for us) in the Schematron files.

Schematron Version?

If I do re-implement Schematron validation, do you have a version that you would prefer?

I see that SchXSLT extends the ISO Schematron standard (which is not publicly available).

An XML Schema for Schematron would be most helpful to bring the validation up to date, but not essential.

The schSchema.ts TypeScript file was auto-generated from an old Schematron XML Schema but I don't recall where I sourced this from, it was quite possibly an indirect source. Do you know where I can locate an authoritative version of the XML Schema?

@tgraham-antenna
Copy link
Contributor Author

There's an unofficial schema copy at https://github.com/Schematron/schema

The authoritative source is, of course, the ISO standard (plus errata). Happily, the schema in the standard says that you can copy, and even modify, it.

I found the Schematron mentions in the code, so had assumed that it would work.

@pgfearo
Copy link
Member

pgfearo commented May 7, 2025

Thanks for that Schematron Schema link, it will prove useful to verify the data I have.

I still have long-term ambitions to support validating the Schematron standard, hence I didn't remove the code I had already written. I had to cut short this work though when I switched to another feature and then haven't got around to returning to this.

I'm coding daily in XSLT 3.0 or 4.0, so this is where the focus for this project tends to lie. On the other hand, it is a relatively quick win to exploit the existing code for other standards that include XSLT/XPath features like Schematron.

@tgraham-antenna
Copy link
Contributor Author

Sorry to be a distraction, but can you say what would be needed to re-enable the Schematron support?

@pgfearo
Copy link
Member

pgfearo commented May 8, 2025

That's fine, I'm very happy to get feedback and questions.

I'll check the code history to see where/when I disabled Schematron validation support. If memory serves, it was still very much a work in progress.

@pgfearo
Copy link
Member

pgfearo commented May 8, 2025

I've found where Schematron validation is disabled:

In xsltSymbolProvider.ts there's the following code, starting on line 205:

if (this.collection && this.docType !== DocumentTypes.SCH) {
	let importDiagnostics: vscode.Diagnostic[] = [];
	importErrors.forEach((importError) => {
		importDiagnostics.push(XsltTokenDiagnostics.createImportDiagnostic(importError));
	});
	let allDiagnostics = importDiagnostics.concat(diagnostics);
	if (allDiagnostics.length > 0) {
		this.collection.set(document.uri, allDiagnostics);
	} else {
		this.collection.clear();
	};
}

For a Schematron file, the condition on line 205 evaluates to false because of the expression:

this.docType !== DocumentTypes.SCH

Removing this expression give us just:

if (this.collection) {
...
}

Running the extension with this modified code results in me getting lots of validation errors within our non-standard schematron. XPath expressions in the Schematron file reference variables and functions that are within XSLT files included using <xsl:include> instruction elements that are children of the <schema> element.

So, with the code changed, there's some validation, but the implementation seems to be at quite an early stage.

@pgfearo
Copy link
Member

pgfearo commented May 8, 2025

Image

Here's a screenshot from some sample Schematron - with the code change I mention in my previous comment.

@tgraham-antenna
Copy link
Contributor Author

Thanks. Can you make a branch for this and then we'll see if I or anyone else can do anything with it?

@tgraham-antenna
Copy link
Contributor Author

Thanks for the branch.

@pgfearo
Copy link
Member

pgfearo commented May 8, 2025

I'm currently working on the 'issue-144' branch, unfortunately the xsltTokenDiagnostics.ts class has many changes already on this branch (relative to 'master') - so there wold be quite a lot of conflicts to manage.

It anyone else works on Schematron validation, it may be better to merge the 'issue-144' branch onto the schematron branch first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants