Schematron schema-aware attribute expansion

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
dnl
Posts: 9
Joined: Tue Aug 28, 2018 3:51 pm

Schematron schema-aware attribute expansion

Post by dnl » Tue Jun 16, 2020 7:23 pm

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

tavy
Posts: 224
Joined: Thu Jul 01, 2004 12:29 pm

Re: Schematron schema-aware attribute expansion

Post by tavy » Wed Jun 17, 2020 9:54 am

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
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com

dnl
Posts: 9
Joined: Tue Aug 28, 2018 3:51 pm

Re: Schematron schema-aware attribute expansion

Post by dnl » Wed Jun 17, 2020 10:38 am

Thank you Octavian for the explanation

Post Reply