I have to write a simple condition in XSL:
IF column=0 AND IF result = .35
set background color to green and write $result
ELSE IF result = 0.10
set background color to white and write the word "QQQ"
I have tried this but it doesn't work:
<xsl:param name="result" />
<xsl:param name="column" /&开发者_如何转开发gt;
<xsl:if test="$result = 0.35 and $column = 0">
<xsl:attribute name='background-color'>#669933</xsl:attribute>
<xsl:value-of select="result"/>
</xsl:if>
<xsl:if test="$result = 0.10">
<xsl:value-of select="QQQ"/>
</xsl:if>
Any suggestions?
<xsl:if test="$result = 0.35 and $column = 0"> <xsl:attribute name='background-color'>#669933</xsl:attribute> <xsl:value-of select="result"/> </xsl:if> <xsl:if test="$result = 0.10"> <xsl:value-of select="QQQ"/> </xsl:if>
You have committed exactly two errors in the code above.
Here is the corrected version:
<xsl:if test="$result = 0.35 and $column = 0">
<xsl:attribute name='background-color'>#669933</xsl:attribute>
<xsl:value-of select="$result"/>
</xsl:if>
<xsl:if test="$result = 0.10">
<xsl:value-of select="'QQQ'"/>
</xsl:if>
The errors are:
result
means the elements named result that are children of the context node. You want the<xsl:variable>
namedresult
. By definition the name of any referenced<xsl:variable>
should be prefixed by the$
character.<xsl:value-of select="QQQ"/>
selects all children of the current node namedQQQ
and outputs the string value of the first of them. You want just the string'QQQ'
to be produced. By definition, to distinguish a string from a name, the string must be enclosed in quotes or in apostrophes.
If you want to set the background color of an element, set the "name" of the xsl:attribute to "style" and the value to "background-color: #669933". For example:
<div>
<xsl:if test="$result = 0.35 and $column = 0">
<xsl:attribute name='style'>background-color:#669933</xsl:attribute>
<xsl:value-of select="$result"/>
</xsl:if>
<xsl:if test="$result = 0.10">
<xsl:attribute name='style'>background-color:#ffffff</xsl:attribute>
<xsl:value-of select="'QQQ'"/>
</xsl:if>
</div>
精彩评论