2
votes

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?

1
I took your schematron file, changed <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 prefix m in the appropriate place. Perhaps a bug? You can fix it by adding the m namespace to the root of the resulting XSLT by hand (use a post-process XSLT with this XSLT as input to add it).Abel
Abel - thanks for the feedback. I think there's a bug in the ph-sch2xslt-maven-plugin as it ignores the namespace prefix element.Barry S
Well, since it is open source, have you tried checking the rules on it processing ns nodes? Or report it as a bug, or if you can fix it, suggest a fix?Abel
The problem is that you are using the wrong class. SchematronResourceXSLT is only to be used, if you have the pre-converted file. If you have the Schematron XML use SchematronResourceSCH instead. I just check with the current 4.0.1-SNAPSHOT and the Schematron is valid!Philip Helger

1 Answers

1
votes

This is a issue with ph-schematron and has been fixed in 4.0.1, released on 05-Jul-2016.