?
Solved

XSL: how to expand, not replace attribute

Posted on 2003-02-27
2
Medium Priority
?
349 Views
Last Modified: 2012-06-27
I can reach the result that I want, but I want to know if there is a better way.

There is an XML datafile, with different records, and different selection criteria.

I want records that are "selected" to have a special fontcolor.
I want records that are "found" to have a special backgroundcolor.


    <xsl:if test="selected = 'True'">
        <xsl:attribute name="style">color:#FF8700</xsl:attribute>
    </xsl:if>
    <xsl:if test="found='True'">
        <xsl:attribute name="style">background:#CCFFCC</xsl:attribute>
    </xsl:if>


Both attributes are done through the style.
The last style replaces the first style completely, although they can go together very well.

What I want is that the styles add up to each other, so that records that are both "selected" and "found" get both style attributes.

Of course I can expand the possible condition, or use <xsl:when>.
In further development there might be more criteria, and the number of possible combinations grows very rapidly then.

Question(s):
- Is there a way that an attribute will not replace an earlier attribute, but expand it.
- Or is there another way i can avoid to mention explicitely all possible combinations of conditions.









0
Comment
Question by:sybe
[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
2 Comments
 
LVL 3

Accepted Solution

by:
NetWize earned 400 total points
ID: 8034511
1. Create a variable with all the styles concatenated
2. Assign this variable as style

<xsl:variable name="mystyle">
  <xsl:if test="selected = 'True'">
       <xsl:value-of select="'color:#FF8700; '"/>
   </xsl:if>
   <xsl:if test="found='True'">
       <xsl:value-of select="background:#CCFFCC; '"/>
   </xsl:if>
</xsl:variable>

<xsl:attribute name="style">
  <xsl:value-of select="mystyle"/>
</xsl:attribute>

Im not quite sure if the IF works inside the variable...
0
 
LVL 28

Author Comment

by:sybe
ID: 8034972
thanks, tried it and it worked
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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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