Get file name using xsl

2019-03-25 00:17发布

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"

标签: xslt xslt-1.0
2条回答
姐就是有狂的资本
2楼-- · 2019-03-25 01:01

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.

查看更多
Juvenile、少年°
3楼-- · 2019-03-25 01:15

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(''))
查看更多
登录 后发表回答