I am a trying to pass the value of a shell variable to an xsltproc instance. The file text.xsl contains:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="file:/Users/robertramey/WorkingProjects/modular-boost/tools/boostbook/xsl/docbook.xsl"/>
<xsl:import href="file:$BOOST_ROOT/tools/boostbook/xsl/docbook.xsl"/>
</xsl:stylesheet>
#functions as expected
$echo $BOOST_ROOT
/Users/robertramey/WorkingProjects/modular-boost
#passes on first import as expected.
#but fails on the second as expect as BOOST_ROOT is not set
$xsltproc --maxdepth 6000 --xinclude --nonet test.xsl
warning: failed to load external entity
"file:$BOOST_ROOT/tools/boostbook/xsl/docbook.xsl"
#passes on the first import as expected
#fails on the second - NOT expected
$xsltproc --maxdepth 6000 --stringparam BOOST_ROOT "/Users/robertramey/WorkingProjects/modular-boost" --xinclude --nonet test.xsl
warning: failed to load external entity
"file:$BOOST_ROOT/tools/boostbook/xsl/docbook.xsl"
compilation error: file test.xsl line 4 element import
xsl:import : unable to load file:$BOOST_ROOT/tools/boostbook/xsl/docbook.xsl
Why is this? What do I have to do to make this work?
$cat bb2db.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href="https://www.boost.org/tools/boostbook/xsl/docbook.xsl"/> </xsl:stylesheet>
which works. But it relies on a global URL to find the file to import. This makes my script dependent on having an internet connection which I'd prefer to avoid. I'd like to refer to a local directory:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href=file:"$BOOST_ROOT/tools/boostbook/xsl/docbook.xsl"/> </xsl:stylesheet>
Since the shell variable holds the base path of the desired xml stylysheet I want to import.
xsl:importis possible with XSLT 1. With XSLT 3 (like SaxonC 12 HE) you might be able to use a static parameter (<xsl:param name="BOOST_ROOT" static="yes" as="xs:string" select="'/Users/robertramey/WorkingProjects/modular-boost'"/>) and a shadow attribute (<xsl:import _href="file:{$BOOST_ROOT}/tools/boostbook/xsl/docbook.xsl"/>).xsl:import? What is the reason why you don't just import the file directly?xsl:import. Since the answer to #2 is that you can't (because thehrefattribute ofxsl:importis not an attribute value template) the first part becomes moot.https://www.boost.org/tools/boostbook/xsl/docbook.xslto your local file URL. Or of course consider moving to XSLT 3, both SaxonC 12 for C/C++ saxonica.com/saxon-c/index.xml or the Node.js SaxonJS/xslt3 command line tool npmjs.com/package/xslt3 should support the approach with a static parameter and a shadow attribute.