Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file name using xsl

Tags:

xslt

xslt-1.0

How can I get the file name using xsl 1.0?

I tried

<xsl:value-of select="base-uri()" />

but got "Fatal Error! Could not find function: base-uri"

like image 743
joe Avatar asked Feb 24 '09 18:02

joe


2 Answers

base-uri() is a standard XPath 2.0 function, so when running XSLT 1.0 this function will be unavailable.

In XSLT 1.0 the filename (of what?) may be passed as a parameter for the transformation.

Do note that it isn't always possible to produce a filename for a stylesheet or for an XML document -- either or both may be residing in memory without an associated file.

It is not clear from the problem which filename must be produced.

Here is how to find filenames in XPath 2.0 / XSLT 2.0:

The filename of the current document:

 base-uri()

The filename of the current stylesheet module:

  base-uri(document(''))
like image 154
Dimitre Novatchev Avatar answered Sep 22 '22 19:09

Dimitre Novatchev


There is no such XPath function, or XSLT extension to XPath function to do this in XSLT v1/XPath v1.

It is quite possible for there to be no file, and even if there is no reason for the XSLT engine to have that file name (consider loading the file content into a buffer, parsing the buffer into a DOM and then passing the DOM to the XSLT processor).

You will need to pass the filename into the processor to be available as a parameter in the transform.

like image 35
Richard Avatar answered Sep 19 '22 19:09

Richard