I use XSLT as template engine in my PHP framework. Some XSLT files are in different folders,so if I want to include/import xslt template not from main directory I have to type a lot:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="dir1/dir2/dir3/dir4/layout.xsl"/>
<xsl:template name="content">
<html>
<head>
<title>action.xsl</title>
</head>
<body>
test
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Is there any easy way to reduce this dir1/dir2/dir3/dir4/layout.xsl ? dir1/dir2/dir3/dir4/ are static (never changes).
Separate template with all includes does not fit, because each template requires different files, and after some time it is difficult to understand what’s included and where.
I thought perhaps it is possible to do something with xml:base <xsl:import href="layout.xsl" xml:base="dir1/dir2/dir3/dir4/" />, but do not know how.
Thanks
is possible in XSLT 2.0 but not in 1.0.
Did you try it in XSLT 2.0 (e.g. in Saxon), and if so, what was the result?
You cannot put import statements into templates; each import statement must be at the top level below the stylesheet element.