XSL 导入:如何克服(文档或其他)样式文件的位置差异
来自 Linux 发行版并从网上复制/粘贴了许多示例,我正在执行以下操作以在我的 XSL 文件中包含 DocBook 样式(使用 xsltproc 处理):
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="/usr/share/xml/docbook/stylesheet/nwalsh/html/docbook.xsl"/>
...
只要“docbook.xsl”是在指定地点。当然,情况并非总是如此。例如,在带有 MacPorts 的 Mac OSX 上,它需要:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="/opt/local/share/xsl/docbook-xsl/html/docbook.xsl"/>
...
一条完全不同的路径。我浏览过网络,看看 XSL 是否存在“文件存在”功能(显然还没有),或者条件包含是否可能(显然不可能)。
因此,除了必须根据“docbook.xsl”的实际位置动态创建 XSL(我可能会通过 Makefile 来做到这一点)之外,是否还有其他可能性可以从正确的位置导入文件而无需太多麻烦?
编辑/回答: Dimitre 指出了正确的方法,在阅读了一些内容以及我系统上的通用目录文件后,对特定问题的简短回答是使用:
<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"/>
案例已结,问题已解决。编写自己的目录被推迟到另一个时间:-)
Coming from a Linux distribution and having copy/pasted from a number of examples across the net, I am doing the following to include DocBook style in my XSL files (processed with xsltproc):
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="/usr/share/xml/docbook/stylesheet/nwalsh/html/docbook.xsl"/>
...
This works great as long as "docbook.xsl" is at the specified place. Of course, it is not always. E.g., on Mac OSX with MacPorts, it needs to be:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="/opt/local/share/xsl/docbook-xsl/html/docbook.xsl"/>
...
A totally different path. I've looked through the net to see whether a "file exists" functionality exists for XSL (apparently not yet) or whether conditional includes are possible (apparently not).
So, short of having to dynamically create the XSL depending on where the "docbook.xsl" really is (I would probably do that via a Makefile), are there any other possibilities to have the file imported from the correct location without too much hassle?
Edit / Answer:
Dimitre pointed the right way, and after reading a bit there and in the general catalog files on my systems, the short answer to the specific problem is to use:
<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"/>
Case closed, problem solved. And writing own catalogs is postponed to another time :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XML 目录旨在解决这个问题(以及其他问题)。
了解更多信息此处。
XML catalogs are intended to solve this problem (among others).
Read more here.