Reputation: 311
I have an XSLT file that works with an XML to process a HTML (currently using X-trans & Notepad++). What I want to do is split it into 3 files, The Header, the body and the footer.
So far I have tried to use xsl:import & xsl:include but whenever I try to process it says the file is not valid. I'm clearly missing something can anyone help?
Header XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html lang="en-GB">
<body style="font-family:'Praxis Com Light'; color:#632423; width:100%; font-size:14px !important;">
<xsl:variable>variable1</xsl:variable>
<xsl:variable>variable2</xsl:variable>
<xsl:variable>variable3</xsl:variable>
<div>Header</div>
</body>
</html>
</xsl:template>
Body XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html lang="en-GB">
<body style="font-family:'Praxis Com Light'; color:#632423; width:100%; font-size:14px !important;">
<xsl:include href="Header.xsl"/>
<xsl:variable>variable1</xsl:variable>
<xsl:variable>variable2</xsl:variable>
<xsl:variable>variable3</xsl:variable>
<table>Main XSL file</table>
<xsl:include href="Footer.xsl"/>
</body>
</html>
</xsl:template>
Footer XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html lang="en-GB">
<body style="font-family:'Praxis Com Light'; color:#632423; width:100%; font-size:14px !important;">
<xsl:variable>variable1</xsl:variable>
<xsl:variable>variable2</xsl:variable>
<xsl:variable>variable3</xsl:variable>
<p>Footer</p>
</body>
</html>
</xsl:template>
Upvotes: 2
Views: 135
Reputation: 167571
You can only use xsl:include
or xsl:import
as top level elements, i.e. as direct children of the xsl:stylesheet
respectively xsl:transform
element. Therefore a possible approach is
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="header>
<xsl:variable>variable1</xsl:variable>
<xsl:variable>variable2</xsl:variable>
<xsl:variable>variable3</xsl:variable>
<div>Header</div>
</xsl:template>
</xsl:stylesheet>
with
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="Header.xsl"/>
<xsl:include href="Footer.xsl"/>
<xsl:template match="/">
<html lang="en-GB">
<body style="font-family:'Praxis Com Light'; color:#632423; width:100%; font-size:14px !important;">
<xsl:call-template name="header"/>
<xsl:variable>variable1</xsl:variable>
<xsl:variable>variable2</xsl:variable>
<xsl:variable>variable3</xsl:variable>
<table>Main XSL file</table>
<xsl:call-template name="footer"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Instead of using named template it might be better to use template matching and perhaps modes but that depends on the structure of the XML to be processed.
Upvotes: 2