[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to calculate attribute values with XSL ?

Subject: Re: How to calculate attribute values with XSL ?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 8 Jan 2002 08:56:33 +0000
xslt calculate
Hi Stig,

> I'm working with working with XSL for HTML output. A problem that
> has occured several times is that I want to calculate the values of
> HTML attributes based on input XML values, but I'm not able to find
> a sensible way to do it.

You can set the value of an attribute in two ways using XSLT - with
attribute value templates or with xsl:attribute. Attribute value
templates involve using {}s inside the attribute value - anything
within those {}s is interpreted as an expression, evaluated, and its
string value inserted. For example, you could do:

  <xsl:variable name="bgcolor">
    <xsl:choose>
      <xsl:when test="state = 'on' and ack = 'off'">#FF0000</xsl:when>
      <xsl:when test="state = 'on' and ack = 'on'">#008000</xsl:when>
      ...
    </xsl:choose>
  </xsl:variable>
  <tr bgcolor="{$bgcolor}">
    ...
  </tr>

Alternatively, you can use xsl:attribute just after opening the
element. The name attribute specifies the name of the attribute, and
the content of the xsl:attribute instruction gives the value for the
attribute, which you can calculate using XSLT instructions:

  <tr>
    <xsl:attribute name="bgcolor">
      <xsl:choose>
        <xsl:when test="state = 'on' and ack = 'off'">#FF0000</xsl:when>
        <xsl:when test="state = 'on' and ack = 'on'">#008000</xsl:when>
        ...
      </xsl:choose>
    </xsl:attribute>
    ...
  </tr>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.