xsl-list
[Top] [All Lists]

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

2011-05-05 03:26:02
<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>


As has been said you need xsl:sequence or xsl:copy-of to get the whole
node not just the value of the node, but you could also make that
function a little more generic to create any attribute:

<xsl:function name="f:createAtt">
  <xsl:param name="name"/>
  <xsl:param name="value"/>
  <xsl:attribute name="{$name}" select="$value"/>
</xsl:function>

and then call it passing the the name value pair for the attribute,
and put the condition in a predicate:

<foo>
  <xsl:sequence select="f:createAtt('foo', 'bar')[current()/@value =
$something]"/>


cheers
andrew



-- 
Andrew Welch
http://andrewjwelch.com

--~------------------------------------------------------------------
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>
--~--