Re: [xsl] xsl/xslt coding standard

Subject: Re: [xsl] xsl/xslt coding standard
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 15 Aug 2002 00:51:24 -0600 (MDT)
Marcin Jackowski wrote:
> How do you build and format your xsl stylesheets?

I write all stylesheets using a text editor like TextPad or pico.
No exceptions.

Re: coding style... not sure if this kind of stuff is what you mean,
but here's what I do...

Generally no column restrictions, though I often prefer to keep the
xsl:stylesheet start tag within 80 columns. It looks nice if you line
up all the attributes one above the other. :)

When I was using very large stylesheets that I didn't share with anybody, and
a text editor with configurable tab widths, I greatly preferred tabs for
indenting, to keep the file sizes down. When I was using a Makefile to manage
the compilation of non-XSLT code in the same project, I had it also produce
condensed versions of my stylesheets (identity transform + whitespace and
comment removal.. see http://skew.org/xml/ under condense.xsl), resulting in
relatively unreadable but slightly more efficient versions for the application
to use.

When writing stylesheets to share with the world, I use 2-space indents,
which also look good in email.

Literal result element names I try to keep to all lowercase or camelCase.

Variable names I usually camelCase or hyphenate-like-this.

I add frequent comments to explain why I'm doing whatever I'm doing.

Use character references like "&#160;" ...don't waste your time with entities.


General advice:

I don't like the push/pull metaphors, but in general, I try to push as much as
possible (using apply-templates and many match templates, rather than for-each
and long XPaths in one big template).

xsl:import and template modes can be *very* useful. Learn when.

The XPath and XSLT specs are your friends as well. Perhaps they are a bit
thick with technical terminology and poorly organized at first (I mean, what's
with explaining the XPath data model at the very end?), but they are
invaluable references once you get over the hump.

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

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


Current Thread