How do I get the current folder path within an XSLT file?

In MSXSL on Windows, you can use a script extension like this:

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

Other XSL processors support similar methods to use external resources (scripting languages, function libraries etc.), so this is just an example.


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

Tags:

Xslt