Altova Mailing List Archives


Re: [xsl] XHTML templating (best method)

From: Antony Quinn <aquinn@--------->
To:
Date: 1/29/2007 10:10:00 AM
Kris,



Have you considered Eric van der Vlist's idea of "style-free 
stylesheets" [1] [2]? I've used this technique in several projects. The 
main benefit is that you can give the (pure) HTML template to a graphic 
designer while you concentrate on the "code" (XSLT). It's really MVC for 
XSLT, where XML is the model, HTML template the view, and XSLT the 
controller.



Cheers,



Antony



[1] http://www.xml.com/pub/a/2000/07/26/xslt/xsltstyle.html (original 
article)

[2] 
http://eric.van-der-vlist.com/blog/2368_The_influence_of_microformats_on_style-free_stylesheets.item 
(update)



Kris Leech wrote:
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.

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.