I have a custom datatype that is a drop down list where users will be able to specify certain look and feel attributes on the page properties.
There are roughly 10 items in the drop down list. I am trying to write the code to determine the selected value from this datatype (called titleColorPicker), but I'm having trouble since Xslt doesn't have an else feature. I could go with 10 if statements, but is there a more efficient way to do this?
I think I want to change the logic a bit and just put the value of the drop down list as the ID in the div statement. I'm having a bit of trouble with this. For example, the property is named titleColor (it's a custom DDL), but this doens't work.
But both approaches still end up with an empty value in the ID tag:
<div class="grid_12" id="" />
I have verified the name of the property is now titleColorPick (changed it to something different from the XSLT file name, and also verified that the current page has a value set.
The problem with empty tags self-closing is that they have no text/content ... hence they self-close. So if you add a HTML comment in there - then it wont self-close ... and you wont see any visible difference on the rendered webpage in your browser.
If that doesn't work, then it might be worthwhile posting your entire XSLT? - so that we can get a better understanding of how to solve your problem.
If/Then or Switch/Select functionality with XSLT?
Hi,
I have a custom datatype that is a drop down list where users will be able to specify certain look and feel attributes on the page properties.
There are roughly 10 items in the drop down list. I am trying to write the code to determine the selected value from this datatype (called titleColorPicker), but I'm having trouble since Xslt doesn't have an else feature. I could go with 10 if statements, but is there a more efficient way to do this?
Thank you!
--Kent Iler
Hi Kent,
You can use the <xsl:choose> element. For example:
It's similar logic to an if/else statement (in procedural programming), but you can have multiple <xsl:when> conditions in the same <xsl:choose>.
Good luck, Lee.
Thanks, Lee! I'll give that a shot!
I think I want to change the logic a bit and just put the value of the drop down list as the ID in the div statement. I'm having a bit of trouble with this. For example, the property is named titleColor (it's a custom DDL), but this doens't work.
<div class="grid_12" id="{data[@alias = 'titleColor']}">
Any ideas?
Thanks!
--Kent
Hi Kent
Try something like this:
Hope this makes sense to you.
/Kim A
Hi Kent, you should be able to add an id attribute like this:
<div class="grid_12">
<xsl:attribute name="id">
<xsl:value-of select="data[@alias='titleColorPicker']" />
</xsl:attribute>
BTW: xsl:if is also available...
I appreciate all the help, but still having trouble. I've tried:
<div class="grid_12">
<xsl:attribute name="id"><xsl:value-of select="$currentPage/data[@alias='titleColorPick']" /></xsl:attribute>
</div>
and
<div class="grid_12">
<xsl:attribute name="id">
<xsl:value-of select="data[@alias='titleColorPick']" />
</xsl:attribute>
But both approaches still end up with an empty value in the ID tag:
I have verified the name of the property is now titleColorPick (changed it to something different from the XSLT file name, and also verified that the current page has a value set.
Any ideas?
Thanks!
--Kent
It's another problem
http://our.umbraco.org/wiki/how-tos/xslt-useful-tips-and-snippets/stop-html-tags-from-self-closing
Petr
I checked that link, Petr, but it doesn't seem to apply. Here's the code that I have for the titleColorPick:
Hi Kent,
I'm pretty sure Petr is on the right line of thinking here. Try this modified XSLT:
The problem with empty tags self-closing is that they have no text/content ... hence they self-close. So if you add a HTML comment in there - then it wont self-close ... and you wont see any visible difference on the rendered webpage in your browser.
If that doesn't work, then it might be worthwhile posting your entire XSLT? - so that we can get a better understanding of how to solve your problem.
Cheers, Lee.
Here's the result from your code, Lee:
Here's the items from the custom drop down list - could it be something from the datatype configuration?
Here's the full XSLT:
I think that you should have a $currentPage/ in front of your data[@alias......But you said that you had tried this or?
Otherwise, try to print the value out in a textarea, to make sure that there is a value in the field. Try this:
Just to make sure. And by the way Kent, which version of Umbraco are you using?
/Kim A
That did it! Thanks to all who helped!
--Kent
Perfect Kent. Remember to mark one of all the answers in this thread as the solution, so that people know that this issue har been solved :)
/Kim A
is working on a reply...