[xsl] Fixed attribute problems on change from DTD to schema

Subject: [xsl] Fixed attribute problems on change from DTD to schema
From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Sep 2009 03:44:36 +1300
Hi

As previously described I have switched from DTD modelling to XSD for my
application's XML files. Today I have encountered a problem with
default/fixed attribute values: the fixed attribute value appears to be
forced into the parsed XML file when using the DTD (as wanted) but
apparently not found when using the schema.

Document 1:
----
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document system "hcdocs.dtd">
<document>
<title>Software development</title>
<section>
<title id="Head">Q.A. Cycle</title>
<steps>
<step>Test application</step>
<step>Isolate problem</step>
<step>Submit bug report</step>
<step>Wait a while</step>
<step>When anything happens, go back to step 1</step>
</steps>
</section>
</document>
----

and Document 2:
----
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:noNamespaceSchemaLocation="hcdocs.xsd">
<title>Software development</title>
<section>
<title id="Head">Q.A. Cycle</title>
<steps>
<step>Test application</step>
<step>Isolate problem</step>
<step>Submit bug report</step>
<step>Wait a while</step>
<step>When anything happens, go back to step 1</step>
</steps>
</section>
</document>
----

In the DTD, the section element is defined like so:
----
<!ELEMENT section (title, (section|para|steps)*)>
<!ATTLIST section
    mark CDATA "Y"
    break (Y|N) #IMPLIED
>
----

and in the schema, like so:
----
<xs:complexType name="sectionaltype">
  <xs:sequence>
    <xs:element ref="title"/>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="section"/>
      <xs:element ref="para"/>
      <xs:element ref="steps"/>
    </xs:choice>
  </xs:sequence>
</xs:complexType>

<xs:element name="section">
  <xs:complexType>
    <xs:complexContent>
      <xs:extension base="sectionaltype">
        <xs:attribute name="break">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="Y"/>
              <xs:enumeration value="N"/>
            </xs:restriction>
          </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="mark" fixed="Y"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:element>
----


The documents are passed into a stylesheet which includes these two
templates:
----
<xsl:template match="*[@mark='Y']" priority="2">
...
</xsl:template>
<xs:template match="*">
...
</xsl:temnplate>
----

Unlike my earlier problems, I am not compelled to use Xalan for this
transformation, and it is (mis)behaving as described when the processor is
Saxon:

 * the section in document 1 is matched by the first template;
 * the section in document 2 is matched by the second template.

I would expect both documents to give the same result (and use template 1
for sections).

Can somebody please explain why this is happening? The commandline is
identical for the two cases, no options are being supplied either to
suppress or to force attribute value inheritance from the DTD/schema.

Thanks
Trevor

Current Thread