Re: [xsl] nested templates?

Subject: Re: [xsl] nested templates?
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Wed, 16 May 2001 16:16:51 -0400
[Alex Black]

> >> is it possible to construct an xslt stylesheet that is more similar to
> >> "complete" page, i.e. with nested templates:
> >
> > It is possible to design a "complete page" this is what is sometimes
> > called the pull method, in fact if you are doing that, you don't need
> > any xsl;template instructions at all, see the XSLT spec for an example
> > (or the FAQ for this list).
> I've seen that faq and _all_ of the examples are:
> xsl:stylesheet
> xsl:template
> xsl:apply-templates
> xsl:template
> xsl:template
> .. ad infinum.
> -- this is the "lots of little bits" method, which is not useful for
> production.

Too many "little bits" can be hard to manage and understand, but you should
remember that some  key principles of modern programming are to modularize,
encapsulate parts, minimize their interactions, and restrict the number of
things one part does.  Don't think for a minute that generating a page by
transforming a document with a stylesheet isn't programming!

I'm not sure what you got out of those FAQs, or just what you want to do,
but let me sketch out a middle way you could build an html page which
clearly shows the main components but keeps their implementation separated
and also clear.  Of course, this will only be a sketch to show the idea.
Please forgive the length of this post.

Even without any documentation, or seeing the source xml, this stylesheet
makes it clear what the page layout is and what is supposed to go on.  I
think such a stylesheet is clear, and easy to change.  Just fine for
production.  What more could a person want?  Fully nested templates would
make it harder, not easier, to design and maintain the page.


Tom P

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
<xsl:output method='html'/>

<!-- The source document specifies xml filenames for different xml files for
the style,
navigation panel, content panel, and footer panel.  Of course, they
could be in the same document as well.-->

<xsl:variable name='style' select='document(/page/style)'/>
<xsl:variable name='nav' select='document(/page/nav)'/>
<xsl:variable name='content' select='document(/page/content)'/>
<xsl:variable name='footer' select='document(/page/footer)'/>

<!--========MAIN PAGE LAYOUT =====-->
<xsl:template match="/">
<html><title>Demo Page</title>
<style><xsl:call-template name='css'/></style>

<table><tr><td><xsl:call-template name='left-hand-column'/></td>
   <td>xsl:call-template name='right-hand-column'/></td>
<div class='footer'><xsl:call-template name='footer'/></div>


<!--============= CSS Style directives ==============-->
<xsl:template name='css'>
 <!-- Use xsl:for-each to set the context to the style document-->
 <xsl:for-each select='$style'>
  body {background-color:<xsl:value-of select='skincolor'/>}
  <!-- More css commands would go here -->

<!--============ Left hand panel ============-->
<xsl:template name='left-hand-column'>
 <!-- Use xsl:for-each to set the context to the navigation bar document-->
 <xsl:for-each select='$nav'>
  <!-- xsl instructions to build the
  left-hand navigation panel would go here -->

<!-- Use the same approach for the other components-->


 XSL-List info and archive:

Current Thread