- don't use xsl:for-each, use xsl:apply-templates
- don't use named templates, use xsl:apply-templates with a mode
- if a template just contains a choose/when, separate out the branches into individual templates
- instead of xsl:value-of use xsl:apply-templates
- one large template is bad, lots of specific small templates is good
so for example:
you could do:
or you could do:
both will output the same result.
Now if a requirement comes in to wrap the type in <b>, but only if its 'beer', if you have used apply-templates you can just add the
template:
...and then go home. However if you have use value-of earlier on,
you would need to go and modify that template first to change it to an apply-templates anyway.
This comment has been removed by the author.
ReplyDeleteVery good piece of advice! With my endless overriding of the default behavior of the DITA OT, I started thinking the same: my own code should be overridable if I don't wanna be late for dinner!
ReplyDeleteI hadn't really considered doing #4 before, but your example illustrates perfectly how it can really come in handy.
ReplyDeleteWell Scott,
Deleteeven I learn new best practices each day. Actually sharing your code on the mailinglists will have a tremendous impact on improving your own coding style and solution approach.
Cheers,
Robby