XSL,获取当前工作目录 [英] XSL, get current working directory

查看:261
本文介绍了XSL,获取当前工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm looking for a concrete example of an XSL stylesheet storing the current working directory into a variable.

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

I need this because in my situation, I need to import certain library stylesheets using a relative path. Knowing the path my processor is choosing as the current directory would be sufficient.

编辑

没有特定的供应商。

推荐答案

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

In XSLT 2.0 one can use the standard XPath 2.0 function resolve-uri().

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

Do note, that the relative URIs of the included/imported stylesheet modules are relative to the base URI of the including/importing stylesheet module -- not from the "working directory"!

以下是W3 F& O规范对此功能的描述的一部分:

Here is part of the description of this function from the W3 F&O specification:


8.1 fn:resolve-uri

8.1 fn:resolve-uri

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

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

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

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

摘要:此函数
的目的是使相对URI解析为
对于一个绝对的URI。

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

此函数
的第一种形式从$ b解析了基础uri属性的
的$ relative $ b静态上下文。如果在
静态上下文中没有初始化base-uri
属性,则会出现错误
[err:FONS0005]。

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

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

This is the correct result, because our main stylesheet module is saved as:

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

这篇关于XSL,获取当前工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆