[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Looking for a concise way of specifying an condit

Subject: Re: Looking for a concise way of specifying an conditional attribute in output
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 04 May 2011 14:09:25 -0400
Re:  Looking for a concise way of specifying an  condit
At 2011-05-04 13:03 -0500, John McGowan wrote:
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.

Because you are using <xsl:value-of/> you are getting the text.


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.

Use <xsl:copy-of/> and you should be fine. That copies the attribute node, not the attribute value, to the option element.


I hope this helps.

. . . . . . . . . . . Ken

--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.