[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: John McGowan <john@xxxxxxxxxxxxx>
Date: Thu, 5 May 2011 15:06:45 -0500
Re:  Looking for a concise way of specifying an  condit
Thank you Andrew, Michael and Ken!

I use value-of so much I forgot about it's impact on "non-strings".
This information also helped me with a very similar issue I just ran
into today where I was writing a function that was returning a boolean
true or false, but it was always true... because value-of was turning
it into a string.


On Thu, May 5, 2011 at 3:25 AM, Andrew Welch <andrew.j.welch@xxxxxxxxx>
>> <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


Current Thread


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.
First Name
Last Name
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.