xsl-list
[Top] [All Lists]

Re: monotonous nbsp coding

2002-11-13 15:06:00
At 02:50 PM 11/13/2002, you wrote:
<td>
  <xsl:choose>
    <xsl:when test="string-length() &gt; 0"><xsl:value-of select="."
/></xsl:when>
    <xsl:otherwise>&nbsp;</xsl:otherwise>
  </xsl:choose>
</td>

This gets monotonous after a while.  It would be nice if <xsl:value-of>
could take an attribute which would provide a default value if the select
produces an empty result!

  Make a template that does just that.
<xsl:template name="monotonous">
  <xsl:param name="str" select="." />
  <xsl:value-of select="$str" />
  <xsl:if test="string-length() = 0">
    <xsl:text>&nbsp;</xsl:text>
  </xsl:if>
</xsl:call-template>

and then you have

<td>
  <xsl:call-template name="monotonous" />
</td>

I don't think you need to explicitly pass the parameter because of the default value, but play with it to make sure. You may need to include the line
<xsl:with-param name="str" select="." />
but I hope not.


Greg Faron
Integre Technical Publishing Co.



XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>