use compact syntax
2006-06-15 | lang/xsl convention
Some tips about xsl writing:
- remove useless template, parameter,…
- for attribute definition, use compact syntax instead of xsl:attribute and xsl:value-of
replace:
<toto>
<xsl:attribute name="foo"><xsl:value-of select="/x/z"/></xsl:attribute>
...
</toto>
by:
<toto foo="\{/x/z\}">
...
</toto>
- don’t use xsl:attribute if the attribute is always present and the value is constante.
replace:
<toto>
<xsl:attribute name="foo">bar</xsl:attribute>
...
</toto>
by:
<toto foo="bar">
...
</toto>
- use compact empty node syntax
replace:
<toto>
</toto>
by:
<toto/>
- use xsl:if instead of xsl:choose with 2 choices, if possible
replace:
<table>
<xsl:choose>
<xsl:when test="/page/data/notfirsttime ='no'">
<tr>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<td>Rows Fetched:</td>
<td><xsl:value-of select="data/totalrows"/></td>
</tr>
</xsl:otherwise>
</xsl:choose>
</table>
by:
<table>
<tr>
<xsl:if test="/page/data/notfirsttime !='no'">
<td>Rows Fetched:</td>
<td><xsl:value-of select="data/totalrows"/></td>
</xsl:if>
</tr>
</table>