Page 1 of 1

Schematron schema-aware attribute expansion

Posted: Tue Jun 16, 2020 7:23 pm
by dnl
Hi,

I fail to understand how the attribute expansion works in Oxygen. The XPath "element[@attribute]" in sch:rule/@context is always reporting even if the attribute is optional in the XSD and missing in the XML.
Shouldn't the schematron fail to report since it is an optional attribute and the XPath in sch:rule/@context says "the attribute must be there" in the predicate?

XML:

Code: Select all

<xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
  <element>text</element>
</xml>
XSD:

Code: Select all

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="xml">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="element"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="element">
    <xs:complexType mixed="true">
      <xs:attribute name="attribute" default="false"/>
    </xs:complexType>
  </xs:element>
</xs:schema>
Schematron:

Code: Select all

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
  xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
  
  <sch:pattern>
    <sch:rule context="element[@attribute]">
      <sch:report test="text()">has-text</sch:report>
    </sch:rule>
  </sch:pattern>
  
</sch:schema>
Oxygen setting in the Schematron menu: expand attribute values schema-aware checked.

Is this a bug, or am I getting the Schematron XPath handling wrong?
Thanks, Daniel

Re: Schematron schema-aware attribute expansion

Posted: Wed Jun 17, 2020 9:54 am
by tavy
Hello Daniel ,

If you define an xs:attribute with default="false", it means that the attribute will have a default value equal to false. Because you are using schema aware validation even if the attribute is not present in XML it is present in the model with the default value set to false.
Maybe you can change the context in Schematron and set it to element[@attribute != 'false'].

Best Regards,
Octavian

Re: Schematron schema-aware attribute expansion

Posted: Wed Jun 17, 2020 10:38 am
by dnl
Thank you Octavian for the explanation