Thunderstruck
Thunderstruck

Reputation: 345

Why is my following XSL enters inside IF condition although expression is evaluated as false?

Could there be any reason for a XSL to enter into the scope even if the if condition is false? That's sounds like an absurd question but I cannot figure why this is happening for my following xsl-

<xsl:if test="count(../../TaskItems_Sheet/TaskItems[TaskReference=$taskRefMain and ../../TaskItems_Sheet/TaskItems/StartDate/text() = $varTaskStartDate] )>0">
   <ns0:TaskItem>
       <ns0:Add>

even though there is no task with matching both TaskReference & StartDate, it enters into the scope. The count is zero and the test expression is evaluated as false when I debug. Any idea about what I could've done wrong? Please let me know if more info is needed.

Upvotes: 0

Views: 45

Answers (1)

Tim C
Tim C

Reputation: 70648

Although I can't confirm this without seeing more complete code samples, I think the logic in your current expression. It is not looking for a single TaskItem with matching both TaskReference and StartDate, but it is looking for a TaskItem matching TaskReference for which there is another (possibly different) TaskItem that matches StartDate

I think your expression should be simplified to this

<xsl:if 
     test="count(../../TaskItems_Sheet/TaskItems[TaskReference=$taskRefMain and StartDate/text() = $varTaskStartDate]) > 0">

Upvotes: 1

Related Questions