Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

XSL: how to expand, not replace attribute

Posted on 2003-02-27
2
Medium Priority
?
381 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

564 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