xsl-list
[Top] [All Lists]

[xsl] Looking for a concise way of specifying an conditional attribute in output

2011-05-04 13:03:39
I'm looking for a more concise way of doing this particular pattern
that shows up a lot in (x)html forms.

..
<option value="{@value}>
 <xsl:if test="@value eq something"><xsl:attribute name="selected"
select="'selected'" /></xsl:if>
 other stuff
</option>
..

I tried this out, thinking that it might work...

<option value="{@value}>
 <xsl:value-of select="isSelected(@value,something)">
 other stuff
</option>

with a reusable function like this

<xsl:function name="isSelected">
 <xsl:param name="v1"/>
 <xsl:param name="v2"/>
 <xsl:if test="$v1 eq $v2"><xsl:attribute name="selected"
select="'selected'" /></xsl:if>
</xsl:function>

But instead I ended up with the word selected showing up inside of the
option element, not as an attribute.

I've been doing it the first way for years, and was just hoping I
could make it a little cleaner, but you must not be able to return
just an attribute from a function and have it make it's way into the
element containing the function call.

--
/John

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--