flash
flash

Reputation: 1229

validating whether a element exists and has some specific value in xsl

how to check the tag exists and the value is 'On' do something in xsl

please correct me.,

<xsl:if test="$status and $status='On'">

 //do something

</xsl:if>

can we skip checking whether the tag exists and direclty check for the value.

<xsl:if test="$status='On'">

     //do something

    </xsl:if>

is it a correct practice.,

Upvotes: 2

Views: 3258

Answers (2)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243579

<xsl:if test="$status and $status='On'">

The above is redundant, because if $status='On' then the boolean value of $status is true.

Therefore, the expression contained in the @test attribute of the above xslt instruction is equivalent to just: $status='On', which is shorter.

This completely answers the question.

It seems to me that you want to test if $status is defined and then test for its value. This is not correct -- if a reference is made to an undefined xsl:variable, this causes an error as per the W3 XSLT specification.

Upvotes: 3

Ivo
Ivo

Reputation: 3436

you should use xpath expressions

<xsl:if test="/path/node = 'On'">

</xsl:if>

or is $status a xsl param?

Upvotes: 2

Related Questions