how to pass either relative or absolute windows path+filename as command line parameter
Added by Mark Hutchinson about 3 years ago
I have cd'ed to a folder that contains my xslt file with source files in folders below that.
e.g.
c:\users\mark\xsltdocs
myxslt.xsl
datafile1.xml
\source
mySourceFile.xml
\config
datafile2.xml
In myxslt.xsl, I have: ... <xsl:param name="sd"/> <xsl;param name="if"/> <xsl:variable name="sdconfig" select="document($sd)/"/> <xsl:variable name="ifconfig" select="document($if)/"/>
I have tried as many combinations of sd=, +sd=, followed by the full path/file name, relative path/filename, ./filename ./relative path/filename, ...
I've copied all the sub-folder files to the same folder as the xslt. Nothing seems to work. I get various errors for any/all combinations.
Yet with another xslt (built-in Altova XMLSpy) I can use: <xsl:param name=sd" select=" 'file:datafile1.xml' "/> <xsl:param name="if" select=" 'file:config\datafile2.xml' "/>
and it works perfectly without error and no warnings/errors.
What is the 'trick' to doing the same in Saxon XSLT / saxon-he-10.5.jar?
Replies (2)
RE: how to pass either relative or absolute windows path+filename as command line parameter - Added by Martin Honnen about 3 years ago
Passing parameters should be easy, expecting Saxon to deal with Windows file names or even file paths is a different issue. A simple file name, as in <xsl:param name="sd" select="'datafile.xml'"/>
plus then using doc($sd)
should work fine. For paths, either relative or absolute, use URLs paths e.g. <xsl:param name="if" select="'config/datafile2.xml'"/>
, then using e.g. doc($if)
) should work.
Passing those values in on the command line might require escaping, but how exactly depends the command shell, e.g. command prompt or Powershell.
RE: how to pass either relative or absolute windows path+filename as command line parameter - Added by Michael Kay about 3 years ago
It's always a bit difficult to respond to an email that says "I tried everything and nothing worked". It's always easier if you give exact details of one thing you tried and exact details of how it failed.
I would always recommend declaring the type of a parameter, for example <xsl:param name="sd" as="xs:string"/>
. That's mainly for improved diagnostics; if you supply an inappropriate value, you'll get a clearer error message.
Supplying a string value for a parameter on the command line is straightforward, for example sd=my.xml
. The rules of the document() function are that if this is a relative URI, it will be resolved relative to the location of the stylesheet (not the current directory).
There's another option which is to supply a (parsed) document rather than a string. In that case you would declare <xsl:param name="sd" as="document-node()"/>
, you then don't need to call the document() function, and you can supply the parameter on the command line using +sd=my.xml
. In this case, the relative filename is interpreted relative to the current directory.
Please register to reply