getChoiceLabel question

I’ve almost finished converting my templates to Velocity and I’m trying to get an assembly template to display the label of a checkbox choice (rather than the Y that is stored in the db).

This function works: $rx.keyword.getChoiceLabel(contenttypename, fieldname, value)

but I need a way to check if the value is “Y” for each checkbox choice and then display the label if it is a “Y” and not empty.:confused:

I tried
#ifnotnull(“topic”) [li]$rx.keyword.getChoiceLabel(“Bio”, “topic”, “Y”) [/li]

(This is meant to produce a bulleted list of topics that a speaker will discuss based on a predefined list that they submit to us)

I’m not real clear on exactly what you’re trying to do. It sounds like you want to display values from a checkbox group based on whether they are checked or not.

Look at this thread http://forum.percussion.com/showthread.php?t=132 which answers some of your questions.

Perhaps you can clarify what you want the display to look like rather than what the code looks like.

Dave

Basically, I’m trying to get a list of topics to be listed rather than a list of "Y"s. The “Bio” content editor allows our end users to check any number of topics that a speaker is an “expert” on. i.e. accounting; estate planning; tax planning; etc.

Currently, if I use #fieldIfSet(accounting) and they have it checked it will display “Y” (and if it’s not checked it displays nothing). If I use the $rx.keyword.getChoiceLabel(“Bio”, “Accounting”, “Y”) the template will display the topic label “Accounting” regardless of whether or not the speaker is an expert in that topic (because I’ve set the value to Y).

I’m looking for a way to put conditional logic on the value attribute of the getChoiceLabel function. i.e. if the value is Y (or not null) for accounting; display the label; otherwise, don’t display anything.

The way checkbox groups work in HTML is that they have a value only when they are “checked” and they are “null” when they are unchecked.

What you have to do is get the list of values for the field, and then for each value, display the label for that value.

Sinisa had a pretty good code example in the thread sent you above:

http://forum.percussion.com/showpost.php?p=466&postcount=5


#set($myList = $user.psoListTools.asList($sys.item.getProperty("rx:myfield").getValues()))

#foreach($a in $myList)
#set($lbl = $rx.keyword.getLabel('myKwd',$a.getString()))
$label$delimiter
#end

If I have a single checkbox (i.e. ungrouped) which has a value of either Y or null and I want it to display alternate text if the value is Y and nothing if it’s null - how do I do this?

I’ve looked at the code sample - what are the variables referring to $a; $lbl; $label; $delimiter, and mykwd?

This is what the previous markup looked like (but I would prefer if in velocity I could read the label (defined in the sys_SingleCheckbox “choices defined for this control only”):
xsl:if test="//acct_career_ed!=’’">
li>
xsl:choose>
xsl:when test="$syscommand=‘editrc’">
span psxedit=“acct_career_ed”>
xsl:value-of select="/
/acct_career_ed" />
/span>
/xsl:when>
xsl:otherwise>
xsl:text>Accounting Careers and Education</xsl:text>
/xsl:otherwise>
/xsl:choose>
/li>
/xsl:if>

I had a look at some of the other posts and I found one with some code (http://forum.percussion.com/showthread.php?t=112)that I used along with the function that was sent originally and it seems to work. There may be a better way …

#if($sys.item.getProperty("rx:estate_planning").String.length() > 0)<li> $rx.keyword.getChoiceLabel("Bio", "estate_planning", "Y")</li>#end

It might be better to use $sys.item.hasProperty(), as you won’t get an error if the property is null.

I’m still not clear on how you got the “choice list”, as I didn’t think that was exposed, but if the keywords are working for you, go with it.

Dave

Hi
Is there a way of doing this (i.e. accessing the keyword labels of checkboxtree) from within an XSL template?
Thanks

Ben

Ben,

There are 2 general ways to do this in an XSL assembler.

The first (and simplest) way is to do an outer join in the query resource to the RXLOOKUP table (or whatever table your keywords are stored in). You’ll need to add the label column to the mapper, and then it will be available directly in the XML.

The second way is to use a document() call to a separate query resource (supplying the id as a parameter). This is a little more complicated, but it gives you more control over what happens when the keyword is not found.

Dave

Thanks Dave
Think I’ll go for the second of these as the node labels are stored and retrieved from a variety of xml files.
Thanks Ben