xslt获取文件当前文件夹路径

时间:2009-02-13 14:36:15

标签: xslt

有没有办法从xslt文件中获取当前文件夹路径?

需要它找到其他xml和xslt文件。我们有不同的客户文件夹,需要成功找到正确的文件。

干杯

7 个答案:

答案 0 :(得分:6)

您可以使用xsl:param从外部将其发送到样式表。然后,您需要确定从外部调用时当前路径是什么;)

答案 1 :(得分:5)

在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>

其他XSL处理器支持类似的方法来使用外部资源(脚本语言,函数库等),所以这只是一个例子。

答案 2 :(得分:5)

  

有没有办法获得最新信息   xslt文件中的文件夹路径?

     

需要它找到其他xml和xslt   文件

无需任何扩展功能甚至参数!

<xsl:import><xsl:include>href属性中使用的任何 相对 网址  基于当前XSLT样式表的URL解析指令 - 它只需要一个URL,在上面的问题中这个URL被清楚地说明为true。这在导入/包含XSLT样式表时非常方便。

document() 函数也会以类似的方式解析相对网址,从而可以使用相关网址访问任何其他XML文档。

最后, an example 如何在大型库的XSLT函数和模板(FXSL 2.x)中大量使用这些工具:< / p>

<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>

答案 3 :(得分:4)

这可能适用于您的设置:

<xsl:value-of select="system-property('user.dir')"/>

例如,

<xsl:value-of select="document(concat(system-property('user.dir'),'/',filename,'.xml'))//title[1]"/>

答案 4 :(得分:3)

...没有
但您可以通过使用相对URL和/或将参数传递到样式表来解决问题。

答案 5 :(得分:2)

在大多数XSLT处理器中,您可以添加自定义函数作为扩展。例如,Saxon's documentation如何做到这一点。

答案 6 :(得分:1)

不是AFAIK(虽然你总是可以把它作为变换的参数传递),但是我不清楚为什么相对路径在这里不适合你。

相关问题