[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: controller stylsheet. performance, best practices

Subject: Re: controller stylsheet. performance, best practices question
From: "Braumüller, Hans" <H.Braumueller@xxxxxxxxxxxx>
Date: Wed, 23 Apr 2003 17:46:52 +0200
best practices template
Dear Michael,

i am trying to understand what you mean and have search in google for an example from Novatchev, but have not succeed.

If you could explain it a litte further i would appreciate it very much. A time ago i do implement "dynamic templates" and failed.

I cannot figure out how the template xyzPage with mode="switch" is getting involved when i call

from template match="/" following in my switch.xml parameter p with xyz:

<xsl:apply-templates
select="document('switch.xml')/switch/*[name()=$p]">
  <xsl:with-param name="current-node" select="."/>
</xsl:apply-templates>

Then i am in node xyz in switch.xml

I do not see how template xyzPage with mode="switch" is applied then
?


Thanks for your patience,

Hans Braumüller 
-- + -- 
Mail Art Not War
http://crosses.net

 



An alternative you might consider is the Novatchev "dynamic templates"
method.

Change

<xsl:template name="xyz">

to

<xsl:template match="xyzPage" mode="switch">
  <xsl:param name="$current-node"/>

Create an element <xyz/> (e.g. in a document switch.xml)

Change

<xsl:choose>
  <xsl:when test="$p='xyz'">
    <xsl:call-template name="xyzPage"/>
  etc. etc.

to

<xsl:apply-templates
select="document('switch.xml')/switch/*[name()=$p]">
  <xsl:with-param name="current-node" select="."/>
</xsl:apply-templates>

For greater efficiency, use keys.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx  

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Terence Kearns
> Sent: 23 April 2003 07:46
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  controller stylsheet. performance, best 
> practices question
> 
> 
> 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.
> 
> 
> -- 
> Terence Kearns: Web Developer
> University of Canberra: +61 2 6201 5516
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.