|
Subject: Re: [xsl] monotonous nbsp coding From: Roger Glover <glover_roger@xxxxxxxxx> Date: Wed, 13 Nov 2002 15:36:46 -0800 (PST) |
Greg Faron <gfaron@xxxxxxxxxxxxxxxxxx> wrote:
> At 02:50 PM 11/13/2002, you wrote:
> ><td>
> > <xsl:choose>
> > <xsl:when test="string-length() > 0"><xsl:value-of select="."
> >/></xsl:when>
> > <xsl:otherwise> </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">
^^ Is this a typo?
> <xsl:text> </xsl:text>
> </xsl:if>
> </xsl:call-template>
Actually, since a named template does not change to another context node, you
should be able to dispense with the "xsl:param" altogether. Thus:
<xsl:template name="monotonous">
<xsl:value-of select="." />
<!-- put " " in place of nothing -->
<xsl:if test="string-length(.) = 0">
<xsl:text> </xsl:text>
</xsl:if>
<!-- or whatever other way to get an " "
into an empty "td" element -->
</xsl:call-template>
> and then you have
>
> <td>
> <xsl:call-template name="monotonous" />
> </td>
Actually, I would rather put the "td" element into the named template, like so:
<xsl:template name="tablecell">
<td>
<xsl:value-of select="." />
<xsl:if test="string-length(.) = 0">
<xsl:text> </xsl:text>
</xsl:if>
</td>
</xsl:template>
So that the markup surrounding the "call-template" element can be simplified
even further, to something like this:
<xsl:call-template name="tablecell"/>
> 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.
You don't need the "xsl:with-param" element. That would defeat the whole point
of the default value on the "xsl:param" element.
=====
-- Roger Glover
"Have you ever noticed, it's 'a penny for your thoughts',
but you put in your 'two cents worth'?....
Somebody somewhere is making a penny."
- Steven Wright
__________________________________________________
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] monotonous nbsp coding, Greg Faron | Thread | Re: [xsl] monotonous nbsp coding, Greg Faron |
| Re: [xsl] MathML and XSL, Gerard Milmeister | Date | Re: [xsl] monotonous nbsp coding, Greg Faron |
| Month |