Reusable XSL Stylesheets and Templates
By Tony Marston2005-04-20
Introduction
This technique has been practised for many years with traditional programming languages, but can it be applied to a relatively recent language such as XSL, and if so, then how?
In my dynamic web application all my HTML output is produced using XSL transformations. The PHP code for each page extracts the data from the database, puts it into an XML file, then transforms it using the contents of a static XSL file. Each page may contain several different "zones", and the contents of each zone can be built using a different XSL template. Where the same zone appears in more than one page and therefore requires the same XSL template the code for that template need not be duplicated in each XSL stylesheet - it can be maintained in a single external file and incorporated into the XSL stylesheet at runtime by means of an
statement. Take the following screen shots as examples:
Figure 1 - a LIST screen
This layout can be used for any number of database tables - all that changes is the title, the column headings and the data area. The contents of the pagination area, menu, navigation and action bars are supplied in the XML file or as parameters to the transformation process, therefore common templates can be used in the XSL file without any modification.
Figure 2 - a DETAIL screen
This layout can be used for any number of database tables - all that changes is the title and the data area. The contents of the scrolling area, menu, navigation and action bars are supplied in the XML file, therefore common templates can be used in the XSL file without any modification.
Within these two different layouts there are common zones - the menu bar, title, navigation bar and action bar - which can be dealt with by common templates and thus do not require separate copies of the same code.
Tutorial pages:
|
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "Reusable XSL Stylesheets and Templates"
You must be logged in to post a comment.
Link to This Tutorial Page!

