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 checkin开发者_C百科g whether the tag exists and direclty check for the value.
<xsl:if test="$status='On'">
//do something
</xsl:if>
is it a correct practice.,
<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.
you should use xpath expressions
<xsl:if test="/path/node = 'On'">
</xsl:if>
or is $status a xsl param?
精彩评论