Subject: Re: [xsl] How to calculate attribute values with XSL ? From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 8 Jan 2002 08:56:33 +0000 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to calculate attribute va, stig . garberg | Thread | RE: [xsl] How to calculate attribut, Michael Kay |
Re: Crossposting (Was: Re: Case of , Jeni Tennison | Date | RE: mapping (Was: Re: [xsl] Re: . i, DPawson |
Month |