14 September 2006

util:GetString

It might be not obvious but is common practice to use util:GetString(string, default).

A xsl:choose used to display the title of an item can be replaced as follows:


<xsl:choose>
<xsl:when test="sc:fld('menutitle',.)">
<xsl:value-of select="sc:fld('menutitle',.)">
</xsl:when>
<xsl:when test="sc:fld('title',.)">
<xsl:value-of select="sc:fld('title',.)">
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="./@name">
</xsl:otherwise>
</xsl:choose>


simpler call:


<xsl:value-of select="util:GetString(util:GetString(sc:fld('title',.), sc:fld('menutitle',.)),@name)"/>

No comments: