|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to calculate attribute values with XSL ?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








