xsl:stylesheet 中的参数化文档类型

发布于 2024-10-08 20:16:24 字数 1415 浏览 1 评论 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>

有想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦 2024-10-15 20:16:24

来自 http://www.w3.org/TR/xslt#output

<前><代码>>

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

来自 http://www.w3.org/TR/xslt20/#element-结果文档


  

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

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.

最偏执的依靠 2024-10-15 20:16:24

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

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

The course.name parameter is given to the XSLT processor. But it is the XML parser that sees the entity declaration containing $(course.name), and the parser won't know what to do with that. The entity cannot be expanded.

You need to declare course.name as a parameter in the stylesheet and then reference it somewhere in a custom template.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文