0

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

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

xsltproc --stringparam course.name 演示 ...

对于每本书。

显然,参数不是这样识别的,而是作为逐字文本,给出错误:

警告:未能加载外部实体“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>

想法?

4

2 回答 2

0

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

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

于 2010-12-25T20:43:48.597 回答
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指令来完成该任务。

于 2010-12-26T16:58:11.150 回答