Edit online

Combining XML Document Content Using DTD Entities

There are two conditions for including a document fragment using DTD entities:

  • The main document should declare the DTD to be used, while the external entities should declare the XML fragments to be referenced.
  • The referenced documents that contain the fragments cannot also define the DTD because the main document will not be valid. If you want to validate the parts separately you have to use XInclude for assembling the parts together with the main file.
The main document looks like this:
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE book SYSTEM "../xml/docbookx.dtd" [ 
<!ENTITY testing SYSTEM "testing.xml" > ]
> 
<book> 
<chapter> ...

The referenced document (testing.xml) looks like this:

<section> ... here is the section content ... </section>
Note:

The indicated DTD and the element names (section, chapter) are used here only for illustrating the inclusion mechanism. You can use any DTD and element names you need.

The content from the referenced file (in the example above, it is a <section> in the test.xml file) can be inserted somewhere in the main document:
... &testing; ...

To obtain output in various formats (for example, PDF or HTML), you simply need to apply an XSLT stylesheet over the main document using a transformation scenario.

Viewing the Expanded Content in Oxygen XML Editor

When a transformation scenario is applied on the main file, an intermediary file combines all the referenced content and it will be expanded in the final output. If you want to see how the referenced content will be expanded before applying the transformation, you can do one of the following:
  • Simply switch to Author mode.
  • Create a minimal XSLT stylesheet that simply copies the XML content, then create a new XSLT transformation scenario that applies the stylesheet over the XML. The XSLT stylesheet would look like this:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:math="http://www.w3.org/2005/xpath-functions/math"
        exclude-result-prefixes="xs math"
        version="3.0">
        <xsl:template match="node() | @*">
            <xsl:copy>
                <xsl:apply-templates select="node() | @*"/>
            </xsl:copy>
        </xsl:template>
        
    </xsl:stylesheet>