xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremias Maerki <jeremias.mae...@outline.ch>
Subject Re: Best coding practice.
Date Fri, 03 May 2002 15:47:38 GMT
xsl:template mainly helps you split up your processing in handy parts
that may even be reused instead of copy-pasted. Copy-Paste is often A
Bad Thing (TM). That's probably one of the top ten best practices in
every computer language.

Processing speed is always one thing. Maintainability of code and code
reuse are another. Sometimes they contradict each other. It does not
always make sense to go for speed over maintenance costs. In the past
I've often went for lower maintenance cost and it has almost always paid
off. What I want to say is this: If you're doing quite a lot of XSLT you
should learn how to work with templates. It will make life easier. As
Patrick said xsl:template with a match attribute (probably!) won't be so
fast, but a named template (xsl:template name="xy"...) should be
relatively fast. But don't take that as a definitive rule. Some things
may be faster with one implementation of XSLT, slower with another.

I know some people who have always asked for definitive and simple rules,
but often they don't exist. Often you have to try something out and measure
the performance. Then you change it if it's not good enough and measure
again. Experimenting can help you get a feel on how fast certain things

As for checking for mandatory elements there are several points to
- Structure checking (or in other words: Validation) is for DTDs and XML
  Schemas and the like...
- ..., normally. You can of course let this checking code in your XSLT,
  but as soon as you're in production and you can rely on getting valid
  XML those checks are not really necessary.
- If you have an unreliable source of XML (for example many different
  producers sending you XML Files of the Internet) then it's probably
  best to use XML Schema or DTD validation.

My suggestion to you: Measure the performance of your current XSLT, then
read into xsl:template and do a refactoring cycle structuring the code
into handy parts using xsl:template, then measure again and decide which
one of those two approaches you like more using the criterias: Speed,
maintanability and possibility of code reuse.

On 03.05.2002 16:29:35 Balaji Loganathan wrote:
> Hi,
>   Is there is any best practice for coding the XSL:FO,
>     that is always
>     1. use xsl:template
>     2. check whether the element exist or not even for
> mandatory elements.
>   My xsl is of 578 lines,Suddenly i felt that my code
> is not object oriented beacuse no where i have used
>   xsl:template.
>   I construct the PDF line after line.Does this affect
> the processing speed.
>   Does using xsl:template increases the processing
> speed.
>   Please comment.
>   Regards
>   Balaji

Jeremias Maerki

View raw message