|
Subject: RE: [xsl] How to calculate attribute values with XSL ? From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Tue, 8 Jan 2002 10:12:56 -0000 |
> 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.
>
> For instance if I want to change the background colour
> (bccolor attribute) of a
> table row based on the XML tags <state> and <ack>, where
> (<state>on</state> and
> <ack>off</ack>) shall give bgcolor="#ff0000", while
> (<state>on</state> and
> <ack>on</ack>) shall give bgcolor="#008000".
>
> I can solve this by writing :
> <xsl:if test="state = 'on' and ack = 'off'">
> <tr bgcolor="#ff0000">table contents</tr>
> </if>
> <xsl:if test="state = 'on' and ack = 'on'">
> <tr bgcolor="#008000">table contents</tr>
> </if>
>
Use
<tr>
<xsl:attribute name="bgcolor">
<xsl:if test="state = 'on' and ack = 'on'">#ff0000</xsl:if>
<xsl:if test="state = 'on' and ack = 'off'">#008000</xsl:if>
</xsl:attribute>
table contents
</tr>
In XSLT 2.0, you can do it all within an attribute value template if you
want:
<tr bgcolor="{if (....) then '#ff0000' else ....}">
Mike Kay
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] How to calculate attribut, Jeni Tennison | Thread | RE: mapping (Was: Re: [xsl] Re: . i, DPawson |
| RE: [xsl] XSLT/XPath Conformance - , Michael Kay | Date | Re: XPath's role (Was: Re: [xsl] Re, Jeni Tennison |
| Month |