?
Solved

XSL XPATH condition in attribute value

Posted on 2008-10-16
6
Medium Priority
?
2,362 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
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

762 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