xml - XSL,获取当前工作目录

标签 xml xslt directory

我正在寻找将当前工作目录存储到变量中的 XSL 样式表的具体示例。

我需要这个,因为在我的情况下,我需要使用相对路径导入某些库样式表。知道我的处理器选择的路径作为当前目录就足够了。

编辑

请不要提供特定于供应商的信息。

最佳答案

在 XSLT 2.0 中,可以使用标准的 XPath 2.0 函数 resolve-uri() .

请注意,包含/导入的样式表模块的相对 URI 是相对于包含/导入样式表模块的基本 URI 的 - 而不是来自“工作目录”!

以下是 W3 F&O 规范中对此函数的部分描述:

8.1 fn:resolve-uri

fn:resolve-uri($relative as xs:string?) as xs:anyURI?

fn:resolve-uri($relative as xs:string?, $base as xs:string) as xs:anyURI?

Summary: The purpose of this function is to enable a relative URI to be resolved against an absolute URI.

The first form of this function resolves $relative against the value of the base-uri property from the static context. If the base-uri property is not initialized in the static context an error is raised [err:FONS0005].

这是一个非常简单的例子:

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:template match="/">
  <xsl:sequence select=
   "resolve-uri('resolve-uri-example2.xsl')"/>
 </xsl:template>
</xsl:stylesheet>

当此转换应用于任何 xml 文档(未使用)时,结果是:

file:///c:/tests/resolve-uri-example2.xsl

这是正确的结果,因为我们的主要样式表模块保存为:

c:/tests/resolve-uri-example2.xsl

关于xml - XSL,获取当前工作目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3910389/

相关文章:

xml - 为什么xsl :value-of not working here (XML namespaces)?

android - 如何在可绘制 View 中设置背景 xml 文件?

xml - 用于清理数据的 XSLT

xslt - 如何动态设置 XSLT 转换输出 XML 的默认命名空间声明?

html - 如何使用 XSL 从 html 中提取标题和描述等元数据

oracle - 如何检索 Oracle 目录路径?

xml - 如何在 shell 脚本中解析 rss-feeds/xml

Java 和 XML : How to get list of included files

ruby - ruby 模块是否有可能获取定义包含该模块的类的文件的目录?

Python - os.listdir 的顺序