Volker
Volker

Reputation: 33

Name of the XSLT-File (not the input XML)

These are the first two lines im my XSLT:

<xsl:variable name="BaseUri" select="fn:base-uri()"/>
<xsl:variable name="DocumentURI" select="fn:document-uri(.)"/>

Both variables contain the same content, the URI of the processed XML file.

How do I get the URI of the XSLT File?

Upvotes: 3

Views: 67

Answers (3)

Volker
Volker

Reputation: 33

Thank you both very much for of your very quick answers. Both approaches worked in my XSLT.

These are the results:

<xsl:variable name="StyleSheet1" select="fn:document-uri(fn:document(''))"/>
<xsl:variable name="StyleSheet2" select="fn:static-base-uri()"/>

StyleSheet1: file:///D:/Tools/QS DF/QS-DF_0_76.xsl

StyleSheet2: file:/D:/Tools/QS%20DF/QS-DF_0_76.xsl

Unfortunately it seems I can not mark both answers as being helpful or solving the problem.

Upvotes: 0

Michael Kay
Michael Kay

Reputation: 163262

The information is not available in XSLT 1.0 except (a) by using vendor extensions, or (b) by passing the information to the stylesheet as a parameter.

In XSLT 2.0 you can use the static-base-uri() function.

There are some complications if you use a processor like Saxon-EE that allows you to deploy a compiled stylesheet; in that situation the spec doesn't define clearly whether static-base-uri() gives you the location of the source code or the location of the compiled code. Moreover, it's possible that neither is actually available, perhaps for security reasons. So this is all a little bit system-dependent.

Note also that the static-base-uri() will change depending which stylesheet module you are in, and the rules if you use xml:base or XInclude or external entities get even more complicated...

Upvotes: 2

Trevor Lawrence
Trevor Lawrence

Reputation: 190

Try this:

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

It's an odd feature of the XSLT-only document function, described in a note here:

https://www.w3.org/TR/xslt20/#function-document

Upvotes: 3

Related Questions