1

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

  • Is that variable declaration a top level one, i.e. the child of the `xsl:stylesheet` or `xsl:transform` root element? Or is it used inside of a template? – Martin Honnen May 18 '21 at 13:57
  • And is the question about understanding the shown code snippet or about writing XSLT or XPath code to show the document URI? Which version of XSLT do you use? – Martin Honnen May 18 '21 at 13:58
  • @MartinHonnen Variable declaration is inside a particular ``, which is inside `` root element. Question is about understanding the code snippet i.e., what exactly the 'select' is selecting. Not sure about the version of XSLT – Pradyumna Kp May 18 '21 at 14:18
  • 1
    Can you post a minimal but complete sample to demonstrate the issue? A particular `` inside of the `xsl:stylesheet` sounds odd, unless it is an `xsl:template`. – Martin Honnen May 18 '21 at 15:29
  • ` ` In this code, how do I find out where exactly `/EXTR/OUT/MESG/SNDR` is ? – Pradyumna Kp May 19 '21 at 04:59

2 Answers2

0

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.

Siebe Jongebloed
  • 3,906
  • 2
  • 14
  • 19
0

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

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51