Xsl literal with <xsl: if>

I need 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 tried this but it doesn't work:

<xsl:param name="result"  />
    <xsl:param name="column" />    

    <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?

+2


a source to share


2 answers


<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>

      

In the above code, you have committed exactly two mistakes.

Here's the adjusted 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>

      

Errors :

  • result

    means elements named result that are children of the context node. You want <xsl:variable>

    with a name result

    . By definition, the name of any reference <xsl:variable>

    must be a prefix character $

    .

  • <xsl:value-of select="QQQ"/>

    selects all the children of the current named node QQQ

    and outputs the string value of the first one. You only want to create a string 'QQQ'

    . By definition, to distinguish a string from a name, the string must be enclosed in quotation marks or in single quotes.

+3


a source


If you want to set the background color of an element, set the xsl: "style" attribute and the "background-color: # 669933" value. For instance:



<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>

      

0


a source







All Articles