xsl-list
[Top] [All Lists]

Re: controller stylsheet. performance, best practices question

2003-04-23 09:36:17
Wouldn't pipelining (e.g. Cocoon/ AxKit) be able to help pare down the number of includes/imports needed? I was convinced of this last night but now I cannot remember how it would work...

The advantage to me seemed to be able to make decisions about the data in one stylesheet, and then pass on that decision as part of the data to the next one ...

simon

On Wednesday, April 23, 2003, at 02:45  AM, Terence Kearns wrote:

In an application I'm building, I've found myself applying an MVC pattern to how I call templates. I have once stylesheet used by all my web-based server scripts (PHP scripts). This website then calls different templates based on the context of the script.
Here is the script, questions to follow:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

    <!-- import templates implementing dynamic content -->
    <xsl:import href="xsl-inc_finder.xsl" />
    <xsl:import href="xsl-inc_subjects.xsl" />
    <xsl:import href="xsl-inc_requirements.xsl" />
    <xsl:import href="xsl-inc_listing.xsl" />
    <xsl:import href="xsl-inc_login.xsl" />

    <!-- set context used by the controller -->
    <xsl:param name="op" select="'<?php echo @$_GET["op"]; ?>'" />

    <!-- BEGIN MAIN PAGE TEMPLATE-->
    <xsl:template match="/">
<!-- blah blah blah. masses of literal content goes here -->
<!-- CALLS TO THE MAIN CONTENT BEGIN HERE -->
                <xsl:choose>
                    <xsl:when test="$op = 'finder'">
                        <xsl:call-template name="finderPage" />
                    </xsl:when>
                    <xsl:when test="$op = 'subjects'">
                        <xsl:call-template name="subjectsPage" />
                    </xsl:when>
                    <xsl:when test="$op = 'login'">
                        <xsl:call-template name="loginPage" />
                    </xsl:when>
                </xsl:choose>
<!-- CALLS TO THE MAIN CONTENT END HERE -->
<!-- blah blah blah. masses of literal content goes here -->
    </xsl:template>
    <!-- END MAIN PAGE TEMPLATE-->

</xsl:stylesheet>



Functionally, this appoach seems to work well for me. My questions is:
Is taking this sort of approach prone to big performance problems?
I can see that in many cases, most of the templates imported at the top of the style sheet will not even be used. They can't be included on the fly because they need to be top-level (can't be nested inside IF or CHOOSE).*

Any other observations about the merits of this approach appreciated.

cheers.

* I could probably use PHP code to include it on the fly, but I want to avoid doing so because I've made a rule for myself not to use server-side code embedded in the stylesheet. I've done so in the param of this example for purposes of clarity, normally I would send them to the processor directly from the PHP function call.


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list