[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

XSL XPATH condition in attribute value

Posted on 2008-10-16
6
Medium Priority
?
2,367 Views
Last Modified: 2013-11-18
Hi, experts

is there any way to use conditions in XSL/XPATH in attribute's value?
I need something like this:

...
<div id='lr-{@id}' style="display:{IF @expanded='yes' THEN 'block' ELSE 'none'}">
...

At this time I have this code:
But with more variables comes lot of code. :(
<xsl:variable name="visibility">
  <xsl:choose>
	  <xsl:when test="@expanded='yes'">
	   <xsl:value-of select="'block'"/>
	  </xsl:when>
	  <xsl:otherwise>
	   <xsl:value-of select="'none'"/>
	  </xsl:otherwise>
 </xsl:choose>
</xsl:variable>

Open in new window

0
Comment
Question by:JohnSixkiller
  • 4
  • 2
6 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22729687
If you would be using XSLT2, you can have the choice in your XPath...
the code would not be far off from what you have in your pseudo code

In XSLT1, you would need the xsl:choose approach
very close to what you did, except that you don't necessarily need the variable, you could use an xsl:attribute

<div id='lr-{@id}'>
   <xsl:attribute name="style=">
          <xsl:text>display:</xsl:text>
          <xsl:choose>
        <xsl:when test="@expanded='yes'">
           <xsl:text>block</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:text>none</xsl:text>
        </xsl:otherwise>
          </xsl:choose>
   </xsl:attribute>

{IF @expanded='yes' THEN 'block' ELSE 'none'}">
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22729690
sorry, drop the last line
0
 
LVL 11

Author Comment

by:JohnSixkiller
ID: 22730005
Thank you for quick response, can you give me an example of XPATH2 version?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 22730034
you just need lowercase, the rest fits
    <div id='lr-{@id}' style="display:{if(@expanded='yes') then ('block') else ('none')}"/>
0
 
LVL 11

Author Closing Comment

by:JohnSixkiller
ID: 31506665
Ok, thanks for your time.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22730230
welcome
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question