One of the most annoying behaviours for a programmer is when someone is using a
language or a method which he isn’t familiar and he directly finds out it’s done in a ugly way. So don’t leave the trash behind you for maintainers bu write proper, nice solutions. Some examples for XSLT, simple stuff to do, but common forgotten are listed below:
- xsl:output should be configured correctly
By default, on creation, the xsL:ouput line, look like this:
<xsl:output method=”html” indent=”no” encoding=”UTF-8″ />
When building a valid xhtml you should change the output-method to xml. And do not forget to change the encoding when you create chinese or vietnamese sites ;-). But when you change the encoding, do not forget the encoding in the first line(<?xml ?>)…
For western sites, this following output line is the most likeliest:
<xsl:output method=”xml” indent=”no” encoding=”iso-8859-1″ />
- Remove unused variables
By default Sitecore delivers the ‘$home’. When it is unused, remove it. Same for unused parameters. Altough the 4 default Sitecore parameters can be left there.
- Avoid comments in templates
As templates are most of the time already full with advanced presentation logic, tests, etc, leave comments out of it. Just describe your template above the method.
- Avoid templates longer then 10-12 lines
Xslt is itself more then complex. Guess nearly everybody agrees on that vision. But, as you are able to read here, in some circumstances, it is definitelly usefull. Still, and this one also applies to C#/VB methods, try to create simple templates, with the simpel guideline that between 10 and 12 lines are the absolute maximum for a template.
Hope this will help you guys a little while using,debugging, documenting and maintaining XSLT-renderings.