schxslt / schxslt-java

Java classes for Schematron validation with SchXslt
MIT License
7 stars 4 forks source link

Unterschied zwischen 1.2 und 2.0 #5

Closed tvelkoff closed 4 years ago

tvelkoff commented 4 years ago

Lieber Herr Maus, Ich denke, es war mein Schicksal, Schxslt zu entdecken! :)

I have recently been working on a plugin for measuring XSLT code quality with SonarQube. During my research I found https://github.com/sonar-xsl and https://github.com/mricaud/xslt-quality. From the latter project, I have successfully applied xsl-common.sch against a body of code for my work. My Sonar plugin uses schxslt-java to apply this schematron file to my set of XSLT files.

Initially I prototyped this by downloading the schxslt and schxslt-java projects from GitHub and building them locally. Now I have gone back to the POM for my Sonar plugin and changed the versions to those found in the mvnrepository. But when I replace this code using 2.0-SNAPSHOT

Schematron schematron = Schematron.newInstance(StreamSource(new FileInputStream(schematronFile), schematronFile.getAbsolutePath()))

with this code using 1.2

new Schematron(getSchematronFile())

I get an error at runtime (when running mvn sonar:sonar on my files) while processing the schematron that looks like this:

ERROR:  'jar:file:/C:/Users/tvelkoff/.sonar/cache/080dd17f320251f9df79f17d74785977/sonar-xslt-plugin.jar_unzip/META-INF/lib/schxslt-1.3.1.jar!/xslt/2.0/include.xsl: line 46: An attribute whose value
 must be a QName or whitespace-separated list of QNames had the value '#current''
FATAL ERROR:  'jar:file:/C:/Users/tvelkoff/.sonar/cache/080dd17f320251f9df79f17d74785977/sonar-xslt-plugin.jar_unzip/META-INF/lib/schxslt-1.3.1.jar!/xslt/2.0/include.xsl: line 70: Required attribute
 'select' is missing.'

In 2.0, a Source is passed to the newInstance factory method, whereas, in 1.2, the DOMSource is built by the constructor, which calls loadDocument. It seems that either I am misusing the 1.2 API or I should continue depending on my local build of 2.0 until it is published to Maven Central. Do you perhaps have any advice on this?

Vielen Dank fuer ihre Arbeit an Schxslt!

tvelkoff commented 4 years ago

Now I know precisely what the issue is. In 1.2, the default TransformerFactory (Xalan) is selected, and it does not support XSLT 2.0. In 2.0-SNAPSHOT, the API supports injection of the TransformerFactory like this:

Schematron schematron = Schematron.newInstance(createSchematronSource(getSchematronFile()))
    .withTransformerFactory(TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl", SchematronReader.class.getClassLoader()));

And of course, Saxon handles XSLT 2.0 without problems.

I don't see how the TransformerFactory can be injected in 1.2. So the best solution for me is to build 2.0-SNAPSHOT locally for now, and pull it from the Maven Repository when 2.0 is published.

dmj commented 4 years ago

Lieber Herr Volkoff,

Vielen Dank für das detailliert Feedback!

Version 1.x of schxslt-java worked with the assumption, that the user sets the respective java property javax.xml.transform.TransformerFactory. I found this to be problematic and was also unsatisfied with the structure of the 1.x classes.

I hope to be able to release 2.0 at the end of December.

With best regards, -- David Maus

tvelkoff commented 4 years ago
    Schön!

— Ted Velkoff

dmj commented 4 years ago

Lieber Herr Volkoff,

Version 2.0 ist auf Maven Central verfügbar.

With best regards, -- David

tvelkoff commented 4 years ago
    Lieber Herr Maus,

Ausgezeichnet! Vielen Dank, Ted

    Get Outlook for iOS

On Tue, Jan 14, 2020 at 2:47 PM -0500, "David Maus" notifications@github.com wrote:

Lieber Herr Volkoff,

Version 2.0 ist auf Maven Central verfügbar.

With best regards,

-- David

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe.