[xsl] xsl:include and validation

Subject: [xsl] xsl:include and validation
From: JBryant@xxxxxxxxx
Date: Fri, 14 Oct 2005 16:20:06 -0500
Hi, all,

I'm trying to validate my source documents against a DTD, and I am getting 
an error that I cannot figure out how to fix.

I have a stylesheet that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:fo="http://www.w3.org/1999/XSL/Format";
  xmlns:fox="http://xml.apache.org/fop/extensions";
  xmlns:saxon="http://saxon.sf.net/";
  exclude-result-prefixes="fo">

  <xsl:output method="xml" version="1.0"
    omit-xml-declaration="no" indent="yes"/>

  <xsl:include href="newbook_formats.xsl"/>

  <!-- keys and templates go here -->

</xsl:stylesheet>

The included stylesheet looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<!-- Format Definitions -->
  <xsl:attribute-set name="body">
    <xsl:attribute name="font-size">11pt</xsl:attribute>
    <xsl:attribute name="font-family">serif</xsl:attribute>
    <xsl:attribute name="line-height">15pt</xsl:attribute>
    <xsl:attribute name="space-before.optimum">3pt</xsl:attribute>
    <xsl:attribute name="space-after.optimum">3pt</xsl:attribute>
  </xsl:attribute-set>

  <!-- and so on for all the styles I use -->

</xsl:styelsheet>

I have a source document and a DTD, and the source document conforms. 
That's not the problem.

The problem is that Saxon (8.5) tries to validate the included stylesheet, 
which produces this message:

Recoverable error on line 2 column 16 of file:/c:/jay/newbook_formats.xsl:
  SXXP0003: Error reported by XML parser: Document is invalid: no grammar 
found.

Recoverable error on line 2 column 16 of file:/c:/jay/newbook_formats.xsl:
  SXXP0003: Error reported by XML parser: Document root element 
"xsl:stylesheet"
, must match
  DOCTYPE root "null".

They are recoverable errors, so it doesn't actually stop me, but I'm a 
purist, and I don't want any error or warning to be produced by my tools. 
I did some searching (FAQ and general Googling) and found that XSLT 
doesn't have a DTD (which is what I thought), and I have no particular 
interest in trying to write a DTD for it. Also, isn't the XSLT processor 
supposed to create a single stylesheet from all the included stylesheets 
(that is, resolve all the references) and then process the source 
documents? So, when instructed to validate, shouldn't it resolve 
xsl:include and then parse (and validate) the source document and then 
start transforming the source document's content? Or have I misunderstood 
something?

Anyway, I guess I don't see an included stylesheet as being a source 
document. In my view of things, it's part of the stylesheet that will 
control the transformation. It just happens to be stored in a separate 
file until transformation time. To me, the source is the content that gets 
transformed, not the stylesheet that does the transforming (regardless of 
how many files it occupies).

Enough grumbling. Other than moving the style information into the main 
XSL file, how do I correct the situation so that the error goes away?

Thanks.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)

Current Thread