How does a DOCTYPE declared as a DTD affect the XSLT transformation?

I am converting a TEI (TEI - Text Encoding Initiative, a standard in text document encoding) text document using XSLT 1 and 2 and various processors.

I have a very difficult problem. Depending on which DTD I put in the header of the XML file, I get different results. Sample input file:   

<!DOCTYPE TEI SYSTEM "tei_lite.dtd">
<TEI>
  <teiHeader>  
    <fileDesc>
      <titleStmt>
        <title>Przyjaciel szczery</title>
        <author>Jan Daniecki</author>
        <respStmt>
          <resp>wyd.</resp> 
          <name>Maciej Eder</name>
        </respStmt>
      </titleStmt>
    </fileDesc>
   </teiHeader>
</TEI>

      

The following xslt should DELETE the author's node:

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="author"/>
  <xsl:template match="*">
    <xsl:copy>
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

      

However, the stylesheet ONLY removes the node if I replace dtd (which is too long to post here) with an empty one.

I figured out why: it's because using a DTD represents a namespace. For the stylesheet to work, it turns out I need to declare a namespace - then everything works, see

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:tei="http://www.tei-c.org/ns/1.0" version="2.0">
  <xsl:template match="tei:author"/>
  <xsl:template match="*">
    <xsl:copy>
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

      

I thought that only the definition of attributes based on DTD attributes is defined when the XSLT is transformed. Can anyone generalize how and when a DTD adds namespaces to be considered?

Thank!

+3


source to share


1 answer


I thought that only the definition of the default attributes depends on the definition of the DTD during the XSLT transformation.

Well it might affect entities as well, but default attribute nodes are exactly what happens here.

Can anyone generalize how and when a DTD adds namespaces to be considered?

Assuming the DTD you are using is this , then note:

<!ATTLIST TEI xmlns CDATA "http://www.tei-c.org/ns/1.0">

      

So the DTD says the element <TEI>

has a default attribute value for xmlns

of http://www.tei-c.org/ns/1.0

. If an element does not have an explicit attribute xmlns

in the source, it should be treated as if it had xlmns="http://www.tei-c.org/ns/1.0"

on it.



Now, while there is a difference between a namespace declaration and an attribute for a namespace-aware XML process, such as XSLT transformations, with a non-namespace-aware XML process, such as DTD validation, namespace declarations are similar to other attributes. (Thus, namespaces could be added to XML in a backward-compatible manner.)

In fact, most (all?) Elements are defined this way, so after checking the DTD, your document is:

<TEI>
  <teiHeader>  
    <fileDesc>
      <titleStmt>
        <title>Przyjaciel szczery</title>
        <author>Jan Daniecki</author>
        <respStmt>
          <resp>wyd.</resp> 
          <name>Maciej Eder</name>
        </respStmt>
      </titleStmt>
    </fileDesc>
   </teiHeader>
</TEI>

      

becomes:

<TEI xmlns="http://www.tei-c.org/ns/1.0">
  <teiHeader xmlns="http://www.tei-c.org/ns/1.0">
    <fileDesc xmlns="http://www.tei-c.org/ns/1.0">
      <titleStmt xmlns="http://www.tei-c.org/ns/1.0">
        <title xmlns="http://www.tei-c.org/ns/1.0">Przyjaciel szczery</title>
        <author xmlns="http://www.tei-c.org/ns/1.0">Jan Daniecki</author>
        <respStmt xmlns="http://www.tei-c.org/ns/1.0">
          <resp xmlns="http://www.tei-c.org/ns/1.0">wyd.</resp> 
          <name xmlns="http://www.tei-c.org/ns/1.0">Maciej Eder</name>
        </respStmt>
      </titleStmt>
    </fileDesc>
   </teiHeader>
</TEI>

      

Then the XSLT transformation is then transformed.

+3


source







All Articles