You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Balaji Loganathan <ba...@yahoo.com> on 2002/05/03 16:29:35 UTC

Best coding practice.

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

http://messenger.yahoo.com.au - Yahoo! Messenger
- A great way to communicate long-distance for FREE!

Re: Best coding practice.

Posted by Balaji Loganathan <ba...@yahoo.com>.
Dear 
Jeremias Maerki,J.Pietschmann and
 Chaumette Patrick Thanks a lot for your valuable
replys.I'm clear now.
Regards
Balaji


 --- "J.Pietschmann" <j3...@yahoo.de> wrote: >
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.
> 
> For a start, you should be aware that you actually
> ask
> for coding XSLT, not XSLFO. They aren't the same
> things
> at all, even though they are usually used toghether.
> 
> Another hint: using xsl:template has nothing to do
> with
> object orientation. XSLT is mainly a declarative
> language,
> the concept of object orientatitation is only
> relevant
> for advanced topics. However, using xsl:template
> usually
> makes transformations more robust, flexible, modular
> and
> easier to maintain.
> 
> Regarding performance, using xsl:template will not
> improve
> processing speed. It will be slightly slower due to
> matching
> overhead, however, processors are specifically
> optimized for
> doing this, so there is no measurable performance
> loss from
> using xsl:template unless you have literally
> thousands of
> templates or hundreds of very badly designed
> templates.
> 
> J.Pietschmann
> 
> 
> 
> 
>  

http://messenger.yahoo.com.au - Yahoo! Messenger
- A great way to communicate long-distance for FREE!

Re: Best coding practice.

Posted by "J.Pietschmann" <j3...@yahoo.de>.
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.

For a start, you should be aware that you actually ask
for coding XSLT, not XSLFO. They aren't the same things
at all, even though they are usually used toghether.

Another hint: using xsl:template has nothing to do with
object orientation. XSLT is mainly a declarative language,
the concept of object orientatitation is only relevant
for advanced topics. However, using xsl:template usually
makes transformations more robust, flexible, modular and
easier to maintain.

Regarding performance, using xsl:template will not improve
processing speed. It will be slightly slower due to matching
overhead, however, processors are specifically optimized for
doing this, so there is no measurable performance loss from
using xsl:template unless you have literally thousands of
templates or hundreds of very badly designed templates.

J.Pietschmann






Re: Best coding practice.

Posted by Jeremias Maerki <je...@outline.ch>.
Balaji,
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
are.

As for checking for mandatory elements there are several points to
consider:
- 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


Cheers,
Jeremias Maerki