In an XSL file, the code :
<xsl:variable name="xyz" select="/this/is/a/path" />
refers to the path "/this/is/a/path". How do I find the location of this path ?
If this path exists in another file, how do I find out which file that is ?
Thanks
In an XSL file, the code :
<xsl:variable name="xyz" select="/this/is/a/path" />
refers to the path "/this/is/a/path". How do I find the location of this path ?
If this path exists in another file, how do I find out which file that is ?
Thanks
EDIT (added some context)
If this the content of the xml:
<?xml version='1.0' encoding='UTF-8'?>
<!-- A comment -->
<?some-pi ?>
<this>
<is>
<a>
<path/>
</a>
</is>
</this>
This xsl:variable:
<xsl:variable name="xyz" select="/this/is/a/path" />
with has this XPath : /this/is/a/path
which selects a set of XML-elements. In this case a pointer to the only path
-element which is empty.
You could use that variable like this
<xsl:copy-of select="$xyz/ancestor::is"/>
Which will give this result:
<is>
<a>
<path/>
</a>
</is>
If you want to get everything from the xml-root, you could use:
<xsl:copy-of select="/"/>
Which wil give this result:
<!-- A comment -->
<?some-pi ?>
<this>
<is>
<a>
<path/>
</a>
</is>
</this>
So to answer your question in your comment:
"If the XPath starts from the root, where exactly is this root ?"
That is at the point after this xml-declaration:
<?xml version='1.0' encoding='UTF-8'?>
which is optional
For a small intro on XPath see here
So the XPath in your question has nothing to do with files. It is meant to select an element in a xml-file.
How to find the XML file which is being referred to by the current XSL file?
If this path exists in another file, how do I find out which file that is ?
Every XSL transformation has a source XML document. This document is specified by the application that initiates the transformation, not by the stylesheet.
All XPath expressions in the stylesheet are relative to the source XML document, unless the context has been changed by using the document()
function.
If (as it seems*) you are using an XSLT 1.0 processor, you have no way of returning the file path to the source XML. However, you can use the calling application to pass the file path as a parameter to the stylesheet. In XSLT 2.0 and higher you can use the base-uri()
and/or the document-uri()
functions.
--
(*) If you are "not sure about the version of XSLT", see here how to find out: https://stackoverflow.com/a/25245033/3016153