OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   XSLT Question: Inserting a DOCTYPE decl

[ Lists Home | Date Index | Thread Index ]
  • From: "Roger L. Costello" <costello@mitre.org>
  • To: xml-dev@ic.ac.uk, "Garriss Jr.,James P." <jgarriss@mitre.org>, "Costello,Roger L." <costello@mitre.org>
  • Date: Thu, 09 Dec 1999 16:00:51 -0500

Hi Folks,

I have a situation where I have many XML documents that do not contain a
DOCTYPE declaration, and would like to write a stylesheet that inserts a
declaration within the documents.  The interesting aspect of this
problem is that each XML document contains within it an element which
gives the name of the DTD file.  So, the declaration should use the
value of that element as the name for the DTD file.

For example, here's a sample XML document into which I need to insert a
DOCTYPE declaration:

<?xml version="1.0"?>
<Numbers>
        <DoctypeFile>Number.dtd</DoctypeFile>
        <Number>27</Number>
        <Number>34</Number>
        <Number>18</Number>
        <Number>67</Number>
        <Number>99</Number>
        <Number>16</Number>
</Numbers>

Note the DoctypeFile element, which indicates the name of the DTD file.

The stylesheet should insert the declaration, thus resulting in an XML
document as such:

<?xml version="1.0"?>
<!DOCTYPE Numbers SYSTEM "Number.dtd">
<Numbers>
        <DoctypeFile>Number.dtd</DoctypeFile>
        <Number>27</Number>
        <Number>34</Number>
        <Number>18</Number>
        <Number>67</Number>
        <Number>99</Number>
        <Number>16</Number>
</Numbers>

Here's the stylesheet that I wrote to do this task:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">
 
    <xsl:variable name="doctype">
        <xsl:value-of select="//DoctypeFile"/>
    </xsl:variable>

    <xsl:output method="xml" doctype-system="string($doctype)"/>

    <xsl:template match="*|@*|comment()|
                         processing-instruction()|text()">
        <xsl:copy>
            <xsl:apply-templates select="*|@*|comment()|
                                     processing-instruction()|text()"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet> 

A pretty simple stylesheet - create a variable which gets the value of
the DoctyleFile element, and instruct the xsl:output element to output a
DOCTYPE declaration, using the value of the variable as the name of the
DTD file, and then do a copy operation on the input XML document.

Here is the XML file that I get when this example is run through XT
(Lotus XSL gives the same results):

<?xml version="1.0"?>
<!DOCTYPE Numbers SYSTEM "string($doctype)">
<Numbers>
        <DoctypeFile>Number.dtd</DoctypeFile>
        <Number>27</Number>
        <Number>34</Number>
        <Number>18</Number>
        <Number>67</Number>
        <Number>99</Number>
        <Number>16</Number>
</Numbers>

Note that the XSL processor did not evaluate the expression that I used
in the xsl:output's doctype-system attribute.  Instead, it used the
expression literally.

Thus, here are my questions:

(1)  Is this a bug in XT and Lotus XSL?
(2)  I suspect it isn't a bug, in which case can someone think of
another way to solve this problem?

/Roger


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo@ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS