Solved

XSL XPATH condition in attribute value

Posted on 2008-10-16
6
2,361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 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

Industry Leaders: 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!

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

717 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