Using Saxon9he, I would like to pass the directory of the input file to my XSLT style sheet. I have defined the parameter in my style sheet:
<xsl:param name="publishing.folder" />
and on the command line:
+publishing.folder="%~dp1\"
With the +
the parameter is empty.
Without the +
,
publishing.folder="%~dp1\"
I get: Error in xsl:result-document/@href Resolved URL is malformed: unknown protocol: d
The d
could be the drive letter, that's where the input file is.
Here is the code with the @href
causing the error:
<xsl:template match="/">
<xsl:call-template name="write-dataset-file">
<xsl:with-param name="filename" select="concat($publishing.folder,'-dataset.xml')"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="write-dataset-file">
<xsl:param name="filename"/>
<xsl:result-document href="{$filename}" omit-xml-declaration="false" method="xml" indent="yes">
<Dataset>
</Dataset>
</xsl:result-document>
</xsl:template>
xalan accepts the command-line parameter -PARAM publishing.folder "%~dp1\"
, but I'd rather not go back to XSLT 1.0
The href attribute of xsl:result-document must be a URI, but you are constructing a filename. Although many XML-related software packages accept filenames where the standards require a URI, Saxon tends to be more strict. The simplest way to fix this is to add "file:///" at the start of the filename, though this might not be adequate if the filename contains special characters such as "#".