I am using ph-sch2xslt-maven-plugin 3.0.0 to compile the following simple schematron to xslt:
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<ns prefix="m" uri="http://www.ociweb.com/movies"/>
<pattern name="all">
<rule context="m:actor">
<report test="@role=preceding-sibling::m:actor/@role"
diagnostics="duplicateActorRole">
Duplicate role!
</report>
</rule>
</pattern>
<diagnostics>
<diagnostic id="duplicateActorRole">
More than one actor plays the role<value-of select="@role"/>.
A duplicate is named<value-of select="@name"/>.
</diagnostic>
</diagnostics>
</schema>
The plugin compiles the schematron into an xslt file. However, attempting to use the compiled xslt file results in an "Undeclared namespace prefix" error.
Using ph-schematron 3.0.0, the following snippet:
final ISchematronResource isr = schematronResourceXSLT.fromFile(aSchematronFile);
if (!isr.isValidSchematron ())
throw new IllegalArgumentException ("Invalid Schematron!");
Produces this:
[main] INFO com.helger.schematron.xslt.SchematronResourceXSLTCache - Compiling XSLT instance [file=/opt/temp/phschematron/schematron-model/src/main/resources/xslt/movies.xslt]
[main] ERROR com.helger.commons.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Undeclared namespace prefix {m})
[main] ERROR com.helger.commons.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Undeclared namespace prefix {m})
[main] ERROR com.helger.schematron.xslt.SchematronProviderXSLTPrebuild - XSLT read/compilation error for [file=/opt/temp/phschematron/schematron-model/src/main/resources/xslt/movies.xslt]
When using the schematron directly, it works and the isValidSchematron()
returns true:
final ISchematronResource aResPure = SchematronResourcePure.fromFile(aSchematronFile);
if (!aResPure.isValidSchematron ())
throw new IllegalArgumentException ("Invalid Schematron!");
Can someone please explain what is causing the namespace error?
<pattern name="all" >
to<pattern id="all" >
(as the name attribute is not allowed) and used oXygen (sorry, no Maven handy) to generate the XSLT 1.0 and 2.0, both worked. It added the namespace prefixm
in the appropriate place. Perhaps a bug? You can fix it by adding them
namespace to the root of the resulting XSLT by hand (use a post-process XSLT with this XSLT as input to add it). – Abelns
nodes? Or report it as a bug, or if you can fix it, suggest a fix? – AbelSchematronResourceXSLT
is only to be used, if you have the pre-converted file. If you have the Schematron XML useSchematronResourceSCH
instead. I just check with the current 4.0.1-SNAPSHOT and the Schematron is valid! – Philip Helger