xsl:stylesheet中的参数化doctype

时间:2010-12-25 17:02:28

标签: xml docbook xslt

如何将--stringparam(xsltproc)注入XSL样式表的DOCTYPE? --stringparam是从命令行指定的。

我有几本docbook5格式的图书我想用同一个自定义图层处理,每本书都有一个唯一的标识符,这里是“demo”,所以我正在运行类似

  

xsltproc --stringparam course.name demo ...

每本书。

显然,参数不会被识别,但作为逐字文本,给出错误:

  

警告:无法加载外部实体“http://edu.yet-another-project.com/course/$(course.name)/entities.ent”

这就是我尝试过的方法,但这不起作用:

<?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>

想法?

2 个答案:

答案 0 :(得分:0)

course.name参数提供给 XSLT处理器。但是 XML解析器会看到包含$(course.name)的实体声明,并且解析器将不知道如何处理它。该实体无法扩展。

您需要在样式表中将course.name声明为参数,然后在自定义模板中的某处引用它。

答案 1 :(得分:0)

来自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 />

因此,在使用XSLT 1.0时,您无法参数化公共或系统DOCTYPE字符串。

来自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>

在XSLT 2.0中,您可以对该任务使用xsl:result-document指令。