phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
116 stars 36 forks source link

Cannot find a 0-argument function named Q{http://www.w3.org/2005/xpath-functions}current() #156

Closed KonradEichstaedt closed 1 year ago

KonradEichstaedt commented 1 year ago

I tried to using an schematron isosch file for xml validation. I decided to take the pure implementation for this.

`

com.helger.schematron
    <artifactId>ph-schematron-pure</artifactId>
    <version>6.3.4</version>
</dependency>`

I using this following code

'XPathFactory factory = XPathHelper.createXPathFactorySaxonFirst();

  factory.setFeature(FeatureKeys.ALLOW_EXTERNAL_FUNCTIONS, true);
  factory.setFeature(FeatureKeys.TRACE_EXTERNAL_FUNCTIONS, true);
  factory.setFeature(FeatureKeys.ALLOW_SYNTAX_EXTENSIONS, true);
  XPathConfig config = new XPathConfig(factory,null,null);

  final SchematronResourcePure aResSCH = SchematronResourcePure.fromInputStream(null,schemaFileResource);
  aResSCH.setXPathConfig(config);

  final ByteArrayInputStream teiInputStream = new ByteArrayInputStream(
      xml.getBytes(StandardCharsets.UTF_8));
  final StringBuilder message = new StringBuilder();

  try {
    SchematronOutputType outputType = aResSCH.applySchematronValidationToSVRL(TransformSourceFactory.create(teiInputStream));
    SVRLHelper.getAllFailedAssertions(outputType).forEach(assertion -> {
      message.append(assertion.getText());
    });
  }catch (Exception error) {
    log.error("Error during generate SVRL Report", error);
  }'

The execution failed always with this error:

ooking for function Q{http://www.w3.org/2005/xpath-functions}name#1 Trying net.sf.saxon.functions.registry.XPath31FunctionSet 2023-07-12 09:28:20.594 ERROR 607562 --- [ main] c.h.s.p.e.LoggingPSErrorHandler : [error] [PSAssertReport] Failed to compile XPath expression in : 'ancestor::tei:l[not(.//tei:note//tei:l[. = current()])]' with the following variables: {} (javax.xml.xpath.XPathExpressionException: net.sf.saxon.trans.XPathException: Cannot find a 0-argument function named Q{http://www.w3.org/2005/xpath-functions}current())

javax.xml.xpath.XPathExpressionException: net.sf.saxon.trans.XPathException: Cannot find a 0-argument function named Q{http://www.w3.org/2005/xpath-functions}current() at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:212) ~[Saxon-HE-12.3.jar:na] at com.helger.schematron.pure.bound.xpath.PSXPathBoundSchema._compileXPath(PSXPathBoundSchema.java:109) ~[ph-schematron-pure-6.3.4.jar:6.3.4]

Can you please help to fix this issue, Many Thanks

phax commented 1 year ago

Well, current() is an XSLT function, and not an XPath function. Therefore it cannot be used with the pure implementation, as the pure implementation is limited to XPath only.

So if you change from SchematronResourcePure to SchematronResourceXSLT and use the Dependency ph-schematron-xslt instead of ph-schematron-pure, you should be good to go.

hth Philip

KonradEichstaedt commented 1 year ago

Many Thanks for your help but if I using the XSLT Implementation your library doesn't accept the isosch file

2023-07-12 10:21:10.594 ERROR 613701 --- [ main] c.h.s.x.SchematronProviderXSLTPrebuild : XSLT read/compilation error for [[ReadableResourceInputStream@0x6c5c6d88: ResourceID=input-stream]; InputStream=java.io.BufferedInputStream@3e6e7e06] javax.xml.transform.TransformerConfigurationException: net.sf.saxon.s9api.SaxonApiException: The supplied file does not appear to be a stylesheet

phax commented 1 year ago

Sorry, my bad. Please use SchematronResourceSCH if your source file is a .sch file. The SchematronResourceXSLT can be used, if you precompile your Schematron to XSLT with the Maven Plugin aforehand.

KonradEichstaedt commented 1 year ago

I refactored my code and technically it works but the isosch doesn't find any error within given xml file.

try (InputStream schemaFileResource = createStreamSource(ID_ISOSCH_TEI_HSP).getInputStream()) {

  final SchematronResourceSCH schematron = SchematronResourceSCH.fromInputStream(null,schemaFileResource);

  final StringBuilder message = new StringBuilder();
  final boolean validation = schematron.getSchematronValidity(TransformSourceFactory.create(xml)).isValid();

  SchematronOutputType outputType = schematron.applySchematronValidationToSVRL(TransformSourceFactory.create(xml));
  SVRLHelper.getAllFailedAssertions(outputType).forEach(assertion -> {
    message.append(assertion.getText());
  });

Do you have any idea what the root cause could be?

phax commented 1 year ago

Well, therefore I need the SCH and the XML. The root cause is most likely a bug in the Schematron :)

KonradEichstaedt commented 1 year ago

Enclosed the xml and isosch file, could you please check this, Many Thanks for your support

phax commented 1 year ago

I don't see the attachment here. Eventually you need to ZIP it to make it work. Accepted extensions are: .gif,.jpeg,.jpg,.mov,.mp4,.png,.svg,.webm,.csv,.docx,.fodg,.fodp,.fods,.fodt,.gz,.log,.md,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.pptx,.tgz,.txt,.xls,.xlsx,.zip

KonradEichstaedt commented 1 year ago

schematronhsp.zip Sorry for this

KonradEichstaedt commented 1 year ago

Do you have any news for me regarding the isosch validation?

phax commented 1 year ago

Nope. Didn't have sufficient time to dig into the problem. Stay tuned :)

phax commented 1 year ago

Can you please let me know, what kind of error you'd expect? This is the SVRL:

<?xml version="1.0" encoding="UTF-8"?>
<svrl:schematron-output xmlns:svrl="http://purl.oclc.org/dsdl/svrl" title="ISO Schematron rules" schemaVersion="">
  <svrl:ns-prefix-in-attribute-values prefix="tei" uri="http://www.tei-c.org/ns/1.0" />
  <svrl:ns-prefix-in-attribute-values prefix="xs" uri="http://www.w3.org/2001/XMLSchema" />
  <svrl:ns-prefix-in-attribute-values prefix="rng" uri="http://relaxng.org/ns/structure/1.0" />
  <svrl:ns-prefix-in-attribute-values prefix="dcr" uri="http://www.isocat.org/ns/dcr" />
  <svrl:ns-prefix-in-attribute-values prefix="xi" uri="http://www.w3.org/2001/XInclude" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-att.datable.w3c-att-datable-w3c-when-1" name="schematron-constraint-hsp_cataloguing-att.datable.w3c-att-datable-w3c-when-1" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:*[@when]" />
  <svrl:fired-rule context="tei:*[@when]" />
  <svrl:fired-rule context="tei:*[@when]" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-att.datable.w3c-att-datable-w3c-from-2" name="schematron-constraint-hsp_cataloguing-att.datable.w3c-att-datable-w3c-from-2" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-att.datable.w3c-att-datable-w3c-to-3" name="schematron-constraint-hsp_cataloguing-att.datable.w3c-att-datable-w3c-to-3" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-att.datable-calendar-calendar-4" name="schematron-constraint-hsp_cataloguing-att.datable-calendar-calendar-4" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-att.measurement-att-measurement-unitRef-5" name="schematron-constraint-hsp_cataloguing-att.measurement-att-measurement-unitRef-5" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-att.typed-subtypeTyped-6" name="schematron-constraint-hsp_cataloguing-att.typed-subtypeTyped-6" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:*[@subtype]" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-att.pointing-targetLang-targetLang-7" name="schematron-constraint-hsp_cataloguing-att.pointing-targetLang-targetLang-7" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-att.spanning-spanTo-spanTo-2-8" name="schematron-constraint-hsp_cataloguing-att.spanning-spanTo-spanTo-2-8" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-att.styleDef-schemeVersion-schemeVersionRequiresScheme-9" name="schematron-constraint-hsp_cataloguing-att.styleDef-schemeVersion-schemeVersionRequiresScheme-9" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-p-abstractModel-structure-p-10" name="schematron-constraint-hsp_cataloguing-p-abstractModel-structure-p-10" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:p" />
  <svrl:fired-rule context="tei:p" />
  <svrl:fired-rule context="tei:p" />
  <svrl:fired-rule context="tei:p" />
  <svrl:fired-rule context="tei:p" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-p-abstractModel-structure-l-11" name="schematron-constraint-hsp_cataloguing-p-abstractModel-structure-l-11" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:p" />
  <svrl:fired-rule context="tei:p" />
  <svrl:fired-rule context="tei:p" />
  <svrl:fired-rule context="tei:p" />
  <svrl:fired-rule context="tei:p" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-desc-deprecationInfo-only-in-deprecated-12" name="schematron-constraint-hsp_cataloguing-desc-deprecationInfo-only-in-deprecated-12" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="isoNormDate" name="isoNormDate" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-ptr-ptrAtts-14" name="schematron-constraint-hsp_cataloguing-ptr-ptrAtts-14" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="typeAndTarget" name="typeAndTarget" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:ref" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-ref-refAtts-17" name="schematron-constraint-hsp_cataloguing-ref-refAtts-17" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:ref" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-list-gloss-list-must-have-labels-18" name="schematron-constraint-hsp_cataloguing-list-gloss-list-must-have-labels-18" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="indexTermHead" name="indexTermHead" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msDesc/tei:head/tei:index/tei:term[@type eq 'material_type']" />
  <svrl:fired-rule context="tei:index/tei:term[@type eq 'measure_noOfLeaves']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='height']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='width']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='depth']" />
  <svrl:fired-rule context="tei:term[@type='dimensions_typeOfInformation']" />
  <svrl:fired-rule context="tei:term[@type='format']" />
  <svrl:fired-rule context="tei:term[@type='format_typeOfInformation']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='origDate_notBefore']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='origDate_notAfter']" />
  <svrl:fired-rule context="tei:term[@type='origDate_type']" />
  <svrl:fired-rule context="tei:msDesc/tei:head/tei:index/tei:term[@type eq 'form']" />
  <svrl:fired-rule context="tei:index/tei:term[@type eq 'status']" />
  <svrl:fired-rule context="tei:term[@type='decoration']" />
  <svrl:fired-rule context="tei:term[@type='musicNotation']" />
  <svrl:fired-rule context="tei:index/tei:term[@type eq 'measure_noOfLeaves']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='height']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='width']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='depth']" />
  <svrl:fired-rule context="tei:term[@type='dimensions_typeOfInformation']" />
  <svrl:fired-rule context="tei:term[@type='format']" />
  <svrl:fired-rule context="tei:term[@type='format_typeOfInformation']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='origDate_notBefore']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='origDate_notAfter']" />
  <svrl:fired-rule context="tei:term[@type='origDate_type']" />
  <svrl:fired-rule context="tei:index/tei:term[@type eq 'status']" />
  <svrl:fired-rule context="tei:term[@type='decoration']" />
  <svrl:fired-rule context="tei:term[@type='musicNotation']" />
  <svrl:fired-rule context="tei:index/tei:term[@type eq 'measure_noOfLeaves']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='height']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='width']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='depth']" />
  <svrl:fired-rule context="tei:term[@type='dimensions_typeOfInformation']" />
  <svrl:fired-rule context="tei:term[@type='format']" />
  <svrl:fired-rule context="tei:term[@type='format_typeOfInformation']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='origDate_notBefore']" />
  <svrl:fired-rule context="tei:index/tei:term[@type='origDate_notAfter']" />
  <svrl:fired-rule context="tei:term[@type='origDate_type']" />
  <svrl:fired-rule context="tei:index/tei:term[@type eq 'status']" />
  <svrl:fired-rule context="tei:term[@type='decoration']" />
  <svrl:fired-rule context="tei:term[@type='musicNotation']" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-relatedItem-targetorcontent1-20" name="schematron-constraint-hsp_cataloguing-relatedItem-targetorcontent1-20" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-l-abstractModel-structure-l-21" name="schematron-constraint-hsp_cataloguing-l-abstractModel-structure-l-21" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-lg-atleast1oflggapl-22" name="schematron-constraint-hsp_cataloguing-lg-atleast1oflggapl-22" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-lg-abstractModel-structure-l-23" name="schematron-constraint-hsp_cataloguing-lg-abstractModel-structure-l-23" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-textLang-textLang.check-24" name="schematron-constraint-hsp_cataloguing-textLang-textLang.check-24" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="//tei:textLang/@mainLang | //tei:textLang/@otherLangs | //@xml:lang" />
  <svrl:fired-rule context="//tei:textLang/@mainLang | //tei:textLang/@otherLangs | //@xml:lang" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-div-abstractModel-structure-l-27" name="schematron-constraint-hsp_cataloguing-div-abstractModel-structure-l-27" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-div-abstractModel-structure-p-28" name="schematron-constraint-hsp_cataloguing-div-abstractModel-structure-p-28" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="msPart_fragment" name="msPart_fragment" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msPart[@type eq 'fragment']" />
  <svrl:active-pattern id="msPart_booklet" name="msPart_booklet" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="msPart_accMat" name="msPart_accMat" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="msPart_other" name="msPart_other" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msPart[@type eq 'other']" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-catchwords-catchword_in_msDesc-30" name="schematron-constraint-hsp_cataloguing-catchwords-catchword_in_msDesc-30" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-dimensions-duplicateDim-31" name="schematron-constraint-hsp_cataloguing-dimensions-duplicateDim-31" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-secFol-secFol_in_msDesc-32" name="schematron-constraint-hsp_cataloguing-secFol-secFol_in_msDesc-32" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-signatures-signatures_in_msDesc-33" name="schematron-constraint-hsp_cataloguing-signatures-signatures_in_msDesc-33" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-msIdentifier-msId_minimal-34" name="schematron-constraint-hsp_cataloguing-msIdentifier-msId_minimal-34" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msIdentifier" />
  <svrl:fired-rule context="tei:msIdentifier" />
  <svrl:fired-rule context="tei:msIdentifier" />
  <svrl:fired-rule context="tei:msIdentifier" />
  <svrl:active-pattern id="ÄußeresKunst" name="ÄußeresKunst" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="booklet" name="booklet" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="binding" name="binding" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msPart[@type eq 'binding']/tei:head/tei:index/tei:term[@type eq 'material_type']" />
  <svrl:fired-rule context="tei:msPart[@type eq 'binding']/tei:head/tei:index/tei:term[@type eq 'form']" />
  <svrl:active-pattern id="accMat" name="accMat" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="fragment" name="fragment" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msPart[@type eq 'fragment']/tei:head/tei:index/tei:term[@type eq 'material_type']" />
  <svrl:fired-rule context="tei:msPart[@type eq 'fragment']/tei:head/tei:index/tei:term[@type eq 'form']" />
  <svrl:active-pattern id="msPartInmsPartStandard" name="msPartInmsPartStandard" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msPart[@type eq 'binding' or @type eq 'fragment' or @type eq 'accMat']/tei:msPart" />
  <svrl:active-pattern id="msPartInmsPartBooklet" name="msPartInmsPartBooklet" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="msPartInmsPartStandardForm" name="msPartInmsPartStandardForm" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msPart/tei:msPart[@type eq 'fragment']/tei:head/tei:index/tei:term[@type eq 'form']" />
  <svrl:active-pattern id="idnoKomponenteSonstiges" name="idnoKomponenteSonstiges" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msPart[@type eq 'other']/tei:msIdentifier/tei:idno" />
  <svrl:active-pattern id="childKomponenteSonstiges" name="childKomponenteSonstiges" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msPart[@type eq 'other']" />
  <svrl:active-pattern id="msPartoneP" name="msPartoneP" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msPart[@type eq 'booklet' or @type eq 'fragment' or @type eq 'binding' or @type eq 'accMat']" />
  <svrl:fired-rule context="tei:msPart[@type eq 'booklet' or @type eq 'fragment' or @type eq 'binding' or @type eq 'accMat']" />
  <svrl:active-pattern id="msPartnoP" name="msPartnoP" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:fired-rule context="tei:msPart[@type eq 'booklet' or @type eq 'fragment' or @type eq 'binding' or @type eq 'accMat']" />
  <svrl:fired-rule context="tei:msPart[@type eq 'booklet' or @type eq 'fragment' or @type eq 'binding' or @type eq 'accMat']" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-relation-reforkeyorname-37" name="schematron-constraint-hsp_cataloguing-relation-reforkeyorname-37" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-relation-activemutual-38" name="schematron-constraint-hsp_cataloguing-relation-activemutual-38" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-relation-activepassive-39" name="schematron-constraint-hsp_cataloguing-relation-activepassive-39" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern id="schematron-constraint-hsp_cataloguing-objectIdentifier-objectIdentifier_minimal-40" name="schematron-constraint-hsp_cataloguing-objectIdentifier-objectIdentifier_minimal-40" document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
  <svrl:active-pattern document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\external\issues\github156\test.xml" />
</svrl:schematron-output>
KonradEichstaedt commented 1 year ago

I expect an error regarding an empty ref attribute for this element:

<persName role="Autor" ref="">SThomas Bricot</persName>

phax commented 1 year ago

Well, the only rule regarding the @ref attribute I find is

   <pattern id="schematron-constraint-hsp_cataloguing-relation-reforkeyorname-37">
      <rule context="tei:relation">
         <assert test="@ref or @key or @name">One of the attributes  'name', 'ref' or 'key' must be supplied</assert>
      </rule>
   </pattern>

There is also no rule on persName

KonradEichstaedt commented 1 year ago

What is with the when rule? This attribute should throw an error or isn't it?

<date when="dsfsdfs" type="primary">2012</date>

phax commented 1 year ago

The check for date element is only for a specific one:

      <rule context="tei:surrogates/tei:bibl/tei:date">
         <assert test="@when[matches(.,'^[1,2]\d{3}-[0,1]\d{1}-\d{2}$')]"> @when
                      requires a date in the standard form: yyyy-mm-dd. </assert>
      </rule>

Yours is in teiHeader/fileDesc/publicationStmt/date

Please make sure you understand XPath and how it is applied before diving too deep into Schematron :)

ingofrank commented 1 year ago

It is my fault: I forgot to provide the appropriate Schematron schema for testing purposes to my colleague Konrad.

Please find enclosed the ZIP file containing the schema which has the needed rules:

hsp_test.zip

Sorry for the confusion.

The small Schematron schema in the ZIP file includes also some diagnostic elements for more human-readable validation messages, which the Schematron schema generated from the TEI ODD does not (yet) include.

Here for example is the rule to test the @ref attribute of person entries:

   <pattern id="persNameRef">
      <rule role="error" context="tei:persName/@ref">
         <assert test="matches(., '^https?://d-nb.info/gnd/')" diagnostics="d_ref_en d_ref_de">@ref requires a GND URI. '<value-of select="."/>' is not a valid GND URI.</assert>
      </rule>
   </pattern>
phax commented 1 year ago

Okay, if I use this Schematron on the test file, I get 2 failed assertions: 1.

  <svrl:failed-assert location="Autor" test=". = ('commissionedBy', 'author', 'bookbinder', 'mentionedIn', 'scribe', 'previousOwner', 'translator', 'illuminator', 'conservator', 'other', 'complementedBy', 'editedBy')">
    <svrl:text>@role requires a label from the controlled vocabulary for person roles. 'Autor' is not an entry from the controlled vocabulary.</svrl:text>
    <svrl:diagnostic-reference diagnostic="d_role_en" xml:lang="en">
If given the role of a person must be an entry from the controlled vocabulary providing the possible roles of persons! -- The role attribute 'Autor' in element persName is not an entry from the controlled vocabulary.</svrl:diagnostic-reference>
    <svrl:diagnostic-reference diagnostic="d_role_de" xml:lang="de">
Wenn angegeben, braucht das role-Attribut einer Person einen Eintrag aus dem kontrollierten Vokabular für die möglichen Rollen von Personen! -- Das role-Attribut im Element persName ist mit 'Autor' kein Eintrag aus dem kontrollierten Vokabular.</svrl:diagnostic-reference>
  </svrl:failed-assert>

and 2.

  <svrl:failed-assert location="" test="matches(., '^https?://d-nb.info/gnd/')">
    <svrl:text>@ref requires a GND URI. '' is not a valid GND URI.</svrl:text>
    <svrl:diagnostic-reference diagnostic="d_ref_en" xml:lang="en">
A person's ref attribute must link to a GND URI! -- The entry '' of the ref attribute of the persName element is not a valid GND URI.</svrl:diagnostic-reference>
    <svrl:diagnostic-reference diagnostic="d_ref_de" xml:lang="de">
Das ref-Attribut einer Person muss eine GND-URI enthalten! -- Im ref-Attribut des Elements persName ist mit '' keine gültige GND-URI eingetragen.</svrl:diagnostic-reference>
  </svrl:failed-assert>
KonradEichstaedt commented 1 year ago

@phax Many thanks for your great and fast support. The implementation above shows with the proper schematron file to expected errors. Because of this I would say again many thanks and close the issue.

phax commented 1 year ago

@KonradEichstaedt thanks for the update and greetings from Vienna :)