phax / ph-schematron

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

HTML tags not working #160

Closed pradyumanaggarwal closed 6 months ago

pradyumanaggarwal commented 9 months ago

I am trying to use HTML tags in Schematron File and validating it against XML doc. I have used SchematronResourceSCH class implementation.

Schematron file :

<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns="http://purl.oclc.org/dsdl/schematron" xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns:sqf="urn:anything"
  queryBinding="xslt2" schemaVersion="ISO19757-3">  
  <ns prefix="html" uri="http://www.w3.org/1999/xhtml" />
  <sch:title>Schematron 1</sch:title>
  <sch:pattern>
    <sch:rule context="title"> 
            <sch:assert role = "error" test = "matches(.,'^Legal.*')"><html:b>Title should start with Legal</html:b></sch:assert>
    </sch:rule>
    <sch:rule context="shortdesc">
        <sch:let name="characters" value="string-length(.)"/>
        <sch:assert role="info" test="$characters &lt; 100"> 
        You have <sch:value-of select="$characters"/> characters. Short Description characters should be less than 100.       
        </sch:assert>  
    </sch:rule>
  </sch:pattern>
</sch:schema>

It's returning text error using rule of short description and it is a valid schematron file. But not returning anything for rule on title even when it should.

@phax

pradyumanaggarwal commented 9 months ago

By any chance @phax you get to find solution for this one ?

phax commented 6 months ago

Yes I did :) The error is, that the namespace prefix was missing in the context elements. So instead of

<sch:rule context="title"> 

it should be

<sch:rule context="html:title"> 

(and the same for shortdesc)