xslt get the file current folder path

2019-02-06 04:29发布

Is there a way to get the current folder path from within a xslt file?

Need it to locate other xml and xslt files. We have different customer folders and will need to successfully find the correct files.

Cheers

标签: xslt
7条回答
可以哭但决不认输i
2楼-- · 2019-02-06 04:50

no...
but you could maybe workaround the problem by using relative URLs and/or passing parameters into the stylesheet.

查看更多
冷血范
3楼-- · 2019-02-06 04:54

In most XSLT processor, you can add custom functions as extensions. For example here is Saxon's documentation how to do that.

查看更多
时光不老,我们不散
4楼-- · 2019-02-06 04:55

Is there a way to get the current folder path from within a xslt file?

Need it to locate other xml and xslt files

No need for any extension functions or even parameters to do that!

Any relative URLs used in the href attribute of an <xsl:import> or <xsl:include> instruction are resolved based on the URL of the current XSLT stylesheet -- it only needs to have an URL, which is vlearly stated as true in the question above. This is very convenient in importing/including XSLT stylesheets.

The document() function also will resolve a relative URL in a similar way, thus making any additional XML document accessible using anrelative URL.

Lastly, here is an example how this facilities are massively used in a big library of XSLT functions and templates (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>
查看更多
神经病院院长
5楼-- · 2019-02-06 05:01

This may work for your setup:

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

For example,

<xsl:value-of select="document(concat(system-property('user.dir'),'/',filename,'.xml'))//title[1]"/>
查看更多
该账号已被封号
6楼-- · 2019-02-06 05:08

Not AFAIK (though you could always pass it as a param to the transform), but I'm not clear why relative paths won't work for you here.

查看更多
The star\"
7楼-- · 2019-02-06 05:12

You can send it into the style-sheet from outside using xsl:param. Then you need to determine what the current path is when invoking the from the outside ;)

查看更多
登录 后发表回答