user1613270
user1613270

Reputation: 533

Get current working directory for XSLT v1.0?

How can I retrieve the current working directory with XSLT version 1.0? I have already looked at these posts here: XSL, get current working directory How to get current document uri in XSLT?

But it requires version 2.0 and I am not sure if I have that as when I tried switching to 2.0 I get an error. Here are the XSL snippets I tried:

<xsl:variable name="myURI" select="resolve-uri('my.xsl')"/>

or

<xsl:variable name="myURI" select="document-uri(document(''))" />

and in both cases I get errors:

Error! Error checking type of the expression 'funcall(resolve-uri, [literal-expr(junit-frames.xsl)])'.
Fatal Error! Could not compile stylesheet

Error! Error checking type of the expression 'funcall(document-uri, [funcall(document, [literal-expr()])])'.
Fatal Error! Could not compile stylesheet

Then I also saw this post here: xslt get the file current folder path

But as I am an XSLT newbie I don't understand the answer or how to implement it. Can anybody provide an example snippet? Thanks!

Upvotes: 0

Views: 2682

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122364

You say in a comment that you're using the processor "which comes with Ant 1.8.2". In that case the simplest answer may be to pass in the current directory as a parameter

<xslt style="stylesheet.xsl" in="in.xml" out="out.xml">
  <param name="basedir" expression="${basedir}" />
</xslt>

and in your stylesheet add a top-level

<xsl:param name="basedir" />

Now you have access to the current directory path as $basedir.

If you need the path as a URI rather than a native file path you can use makeurl:

<makeurl file="${basedir}" property="basedir.url" />
<xslt style="stylesheet.xsl" in="in.xml" out="out.xml">
  <param name="basedir" expression="${basedir.url}" />
</xslt>

Upvotes: 1

Related Questions