tags:

views:

40

answers:

3

Hello,

I cannot figure out a way to check if the value of an attribute is true or false. It's boolean, converted from dataset. When I select the value, I see it is either true or false, but my test does not get the expected behaviour. (it is always false.) I tried almost everything, this is my first xslt application, so help is appreciated.

      <xsl:if test="ispassive">
        <tr>
          <td>
            <em>pasif değil</em>
            <hr></hr>
          </td>
        </tr>
      </xsl:if>
+1  A: 

This xslt is looking for a node in the current context called ispassive.

So if your xml is

<Root>
   <ispassive />
</Root>

You'll get true. Generally, you should specify an xpath to the value you want to check. So if your xml is

<Root>
      <Node ispassive="true"/>
</Root>

and you replace

<xsl:if test="ispassive">

with

<xsl:if test="//@ispassive = 'true'">

Your stylesheet will work as expected.

Robert Christie
+1  A: 

Depending how you represent your booleans it could be a lot of things, what does your data look like?

Most likely scenario, false is represented as 0 and true could be any non 0 value.

<xsl:if test="$myvalue = 0">
    -- output if false --
</xsl:if>

but you're likely better of using xsl:choose

<xsl:choose>
    <xsl:when test="$myvalue = 1">
        -- output if false --
    </xsl:when>
    <xsl:otherwise>
        -- output if true --
    </xsl:otherwise>
</xsl:if>

You can leave out the otherwise, if you don't need it.

Kris
A: 
hazimdikenli