这可能适用于您的设置:
<xsl:value-of select="system-property('user.dir')"/>
Run Code Online (Sandbox Code Playgroud)
例如,
<xsl:value-of select="document(concat(system-property('user.dir'),'/',filename,'.xml'))//title[1]"/>
Run Code Online (Sandbox Code Playgroud)
在Windows上的MSXSL中,可以使用如下脚本扩展名:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://tempuri.org/msxsl"
>
<msxsl:script language="JScript" implements-prefix="user">
<![CDATA[
var fso = new ActiveXObject("Scripting.FileSystemObject");
function getCurrentPath(){
return fso.GetFolder(".").Path
}
]]>
</msxsl:script>
<xsl:template match="/">
<xsl:value-of select="user:getCurrentPath()"/>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
其他XSL处理器支持类似的方法来使用外部资源(脚本语言,函数库等),因此这只是一个示例。
有没有办法从xslt文件中获取当前文件夹路径?
需要它来找到其他xml和xslt文件
不需要任何扩展功能甚至参数来做到这一点!
在一个或多个
指令的属性中使用的任何相对 URL 都是根据当前XSLT样式表的URL来解析的 - 它只需要一个URL,在上面的问题中这个URL被清楚地表示为true.这在导入/包含XSLT样式表时非常方便.href
<xsl:import>
<xsl:include>
该 函数还将以类似的方式解析相对URL,从而使用相对URL访问任何其他XML文档.document()
最后,这里有 一个例子, 说明如何在 XSLT函数和模板(FXSL 2.x)的大型库中大量使用这些工具:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:f="http://fxsl.sf.net/"
exclude-result-prefixes="xs xdt f"
>
<!--
This module contains the FXSL versions of the "standard" XPath functions
These are intended as convenience functions, so that they can be passed
as parameters to other functions (e.g. to f:zipWith())
or curried and passed as parameters (e.g. to f:map())
-->
<xsl:import href="func-curry.xsl"/>
<xsl:import href="func-compose-flist.xsl"/>
<xsl:import href="func-standardArithmeticXpathFunctions.xsl"/>
<xsl:import href="func-standardBooleanXpathFunctions.xsl"/>
<xsl:import href="func-standardStringXpathFunctions.xsl"/>
<xsl:import href="func-standardNodesXpathFunctions.xsl"/>
<xsl:import href="func-standardSequencesXpathFunctions.xsl"/>
<xsl:import href="func-standardAggregateXpathFunctions.xsl"/>
<xsl:import href="func-standardDateTimeXpathFunctions.xsl"/>
<xsl:import href="func-standardXSLTXpathFunctions.xsl"/>
<xsl:import href="func-standardAxisXpathFunctions.xsl"/>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20790 次 |
最近记录: |