How can I make a reference to an external CSS or JS file that is
relative to the XSL stylesheet, and not relative to the XML data?
If you simply put : <link rel="stylesheet" type="text/css"
href="ui/demo.css" ></link>
in your XSL file, this link will always be relative to the location
where the XML file is.
For example, suppose I have following XML data (test.xml):
<?xml version="1.0" ?>
<?xml:stylesheet type="text/xsl" href="ui/show.xsl" ?>
<demo>text</demo>
In a sub-folder "ui" I stored a CSS file (demo.css):
..demo {
color:red;
}
and the following XSL file (show.xsl):
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="demo">
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="ui/demo.css" ></link>
</head>
<body>
<span class="demo"><xsl:value-of select="."/></span>
</body>
</html>
</xsl:template >
</xsl:stylesheet>
As you can see in show.xsl I had to use the relative path
"ui/demo.css" to include the CSS stylesheet, which is logic in the XSL
transformation sense, and it works, but is not a good solution,
because what if I move the XML file to another folder and change the
XSL reference in it? Then the reference to the CSS file will still be
relative to the XML data, and then it does not work anymore.
So, I am looking for a way to include these files relative to the XSL
file. I think there is no way to discover the "uri" to the XSL file,
from within the XSL file, is there? If so, this could be used to
adjust the references.
The only solution that I encountered so far is to store the CSS and JS
data in separate XSL files, and use the xsl:import or xsl:link, and
then use call-template to include the data. For testing and
maintenance I personally do not like this solution either...
Please help...