Saturday 20 September 2003 — This is more than 21 years old. Be careful.
All About Symbian shows a neat trick: using an XSLT stylesheet to style an RSS feed for those that simply click their RSS feed. Very nice, and I may do the same here eventually.
But looking at the stylesheet itself, it looks like they’ve fallen into a common pitfall: writing unusually verbose XSLT.
The same thing happened to me a few years ago at work. A friend asked why the heck XSLT was so great, if it took so much to do so little? I asked to see the XSLT. It looked similar to this snippet of All About Symbian’s stylesheet:
<xsl:element name="form">
<xsl:attribute name="action"><xsl:value-of select="rss:link"/></xsl:attribute>
<xsl:attribute name="method">POST</xsl:attribute>
<center><div class="textinput-form">
<xsl:element name="input">
<xsl:attribute name="name"><xsl:value-of select="rss:name"/></xsl:attribute>
<xsl:attribute name="type">text</xsl:attribute>
</xsl:element>
<xsl:text> </xsl:text>
<xsl:element name="input">
<xsl:attribute name="value"><xsl:value-of select="rss:title"/></xsl:attribute>
<xsl:attribute name="type">submit</xsl:attribute>
</xsl:element>
</div></center>
</xsl:element>
Why all this rigamarole? You never need to use <xsl:element> unless you are going to compute the name of the element. You never need to use <xsl:attribute> unless you are computing the name of the attribute, or the text of the attribute is some large complex template call or something. For simple cases (as we have here), the whole thing can be drastically simplified:
<form action='{rss:link}' method='POST'>
<center><div class='textinput-form'>
<input name='{rss:name}' type='text'/>
<xsl:text> </xsl:text>
<input value='{rss:title}' type='submit'/>
</div></center>
</form>
Now you can read the code, and see what it does.
Comments
-Russ
I think the problem is all the sample XSLT code I've found is written in such a horrendously verbose manner, and you know what they say -- monkey-see, monkey-do.
I blame some of the XSLT tutorials out there that demonstrate the "you can create a tag on the fly using xsl:element!"
Jeni Tennison's has several wise things to say about writing XSLT, especially on the use of Named Templates (avoid them in favor of the mode attribute where possible.)
And Sean, you scare me.
Add a comment: