[xsl] XHTML templating (best method)

Subject: [xsl] XHTML templating (best method)
From: Kris Leech <krisleech@xxxxxxxxxxxxxxx>
Date: Fri, 26 Jan 2007 10:23:18 +0000
Hello, What is the best way to setup a XHTML templating system so that I have the concept of outer layout template and inner view template.
The outer layout would contain the usual header, footer & navigation div's that would be same on every page.
The inner view would be the template that actually transformed the XML data, and so different for every page.


I can think of a few ways to do this myself (below), is there a standard or commonly used way of doing this?
Are there any gotcha's in my reasoning below, other than that they both require creating a temporary file which would need a random filename.


1.) Append the 'view' template under the 'layout' template to make a temporary file

[FILE]
<xsl:template match="/">
<html>
<body>
<h2>This is the layout</h2> <xsl:apply-templates/> </body>
</html>
</xsl:template>


<xsl:template match="content">
<h3>This the view</h3>
<xsl:value-of select="/a"/>
<xsl:value-of select="/b"/>
</xsl:template>
[/FILE]

Using this method the XML would need to constructed in such a way that there was a root node containing a content node.


2.) The 'layout' template has an include/import. The problem is the filename of the 'view' template is different every time so I would either need to parse the layout template for the include filename and replace it with the correct one, again this would involve creating a temporary file.


[FILE]
<xsl:template match="/">
<html>
<body>
<h2>This is the layout</h2> <xsl:include href="view.xsl" />
</body>
</html>
</xsl:template>
[/FILE]


[FILE]
<h3>This the view</h3>
<xsl:value-of select="/a"/>
<xsl:value-of select="/b"/>
[/FILE]

By the way how do relative paths work in includes are they relative to the template with the include?


Many thanks, K.


Current Thread