Search code examples
xmldocbookxslt

parameterized doctype in xsl:stylesheet


How could I inject a --stringparam (xsltproc) into the DOCTYPE of a XSL stylesheet? The --stringparam is specified from the command line.

I have several books in docbook5 format I want to process with the same customization layer, each book having an unique identifier, here "demo", so I'm running something like

xsltproc --stringparam course.name demo ...

for each book.

Obviously the parameter is not recognized as such, but as verbatim text, giving the error:

warning: failed to load external entity "http://edu.yet-another-project.com/course/$(course.name)/entities.ent"

Here it is how I've tried, which won't work:

<?xml version='1.0'?>
<!DOCTYPE stylesheet [
<!ENTITY % myent SYSTEM "http://edu.yet-another-project.com/course/$(course.name)/entities.ent">
%myent;
]>
<xsl:stylesheet  
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">

<!-- the docbook template used -->
<xsl:import href="http://docbook.org/ns/docbook/xhtml/chunk.xsl"/>

<!-- processor parameters -->
<xsl:param name="html.stylesheet">default.css</xsl:param>
<xsl:param name="use.id.as.filename">1</xsl:param>
<xsl:param name="chunker.output.encoding">UTF-8</xsl:param>
<xsl:param name="chunker.output.indent">yes</xsl:param>
<xsl:param name="navig.graphics">1</xsl:param>
<xsl:param name="generate.revhistory.link">1</xsl:param>
<xsl:param name="admon.graphics">1</xsl:param>

<!-- here more stuff -->
</xsl:stylesheet>

Ideas?


Solution

  • From http://www.w3.org/TR/xslt#output

    <xsl:output
      method = "xml" | "html" | "text" | qname-but-not-ncname 
      version = nmtoken 
      encoding = string 
      omit-xml-declaration = "yes" | "no"
      standalone = "yes" | "no"
      doctype-public = string 
      doctype-system = string 
      cdata-section-elements = qnames 
      indent = "yes" | "no"
      media-type = string />
    

    So, when using XSLT 1.0 you can't parameterize public nor system DOCTYPE strings.

    From http://www.w3.org/TR/xslt20/#element-result-document

    <xsl:result-document
      format? = { qname }
      href? = { uri-reference }
      validation? = "strict" | "lax" | "preserve" | "strip"
      type? = qname
      method? = { "xml" | "html" | "xhtml" | "text" |
      qname-but-not-ncname }
      byte-order-mark? = { "yes" | "no" }
      cdata-section-elements? = { qnames }
      doctype-public? = { string }
      doctype-system? = { string }
      encoding? = { string }
      escape-uri-attributes? = { "yes" | "no" }
      include-content-type? = { "yes" | "no" }
      indent? = { "yes" | "no" }
      media-type? = { string }
      normalization-form? = { "NFC" | "NFD" | "NFKC" | "NFKD" |
      "fully-normalized" | "none" | nmtoken }
      omit-xml-declaration? = { "yes" | "no" }
      standalone? = { "yes" | "no" | "omit" }
      undeclare-prefixes? = { "yes" | "no" }
      use-character-maps? = qnames
      output-version? = { nmtoken }>
      <!-- Content: sequence-constructor -->
    </xsl:result-document>
    

    In XSLT 2.0 you can use xsl:result-document instruction for that task.