Re: push v. pull (was Never use for-each)
[Graham Seaman] > The end result is that now my html output is completely entangled with the > xsl code. The html structure is hard to follow without actually walking > through the code. Changing the design has become something that only > someone who knows the code well can do easily (and even then I've > found it is very easy to write very frqgile xsl :-(. This is something I > was always told was bad. So I guess I'm doing it wrong. How do people > use a push style and make it easy for designers to make changes? Or is > this the wrong question? > One reason the html might get entangled is that the html was not really designed but just grown. In many cases it's better to design the document into semi-independent parts that get generated by different templates. You could call this a "document architecture". For example, if you want to create a page with four quadrants, using a table structure, you could do something like this: <xsl:template match='page'> <table> <tr><xsl:apply-templates select='quadrant1'/> <xsl:apply-templates select='quadrant2'/> </tr> <tr><xsl:apply-templates select='quadrant3'/> <xsl:apply-templates select='quadrant4'/> </tr> </table> </xsl:template> This gives better separation. You could go further - this was just an illustration, and of course depends on an assumed xml document structure. The idea is to think about the html result as a series of building blocks, whose content is supplied by xslt templates. In fact, the xml for each block could come from different files, brought in by document(), and the stylesheets for each major block could be imported. With this approach, you can end up with a main driver file that coordinates and customizes the parts. The building blocks give you a chance to avoid the spaghetti. You have to have some html bits in the xslt templates, but they don't have to become spaghetti, never to be separated again. Here's a fragment from a real working stylesheet of mine: <h3><xsl:value-of select='title'/></h3> <xsl:apply-templates select='header'/> <form action='landaction.html' method='post'> <xsl:apply-templates select='file'/> <xsl:apply-templates select='section'/> <input type='submit' value='Send Questionnaire Data'/> </form> The "file" template create a hidden field with a data value, and the "section" template handles a series of recursive (nested) sections. Of course, the template for "section" is more complicated than this, but this part is the driver for an extremely complex form. You can easily see the structure of the html, and I wouldn't call it "entangled". Cheers, Tom P XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format