I have this simple test in XSLT
<xsl:if test="isTrue = 'false'">
but I can't figure out how to do the logical equals operator here. I know <
is <
and >
is >
so what is the logical equals operator for XSLT? I tried &eq;
&et;
==
and =
, or is it that for XSLT you can only compare numbers?
To see if two elements are the same, XSLT compares their string values using the equals sign ("="). To demonstrate several variations on this, our next stylesheet compares the a element in the following with its sibling elements.
The "=" and "!= " operator in XPath can compare two sets of values. In general, if A and B are sets of values, then "=" returns true if there is any pair of values from A and B that are equal, while "!= " returns true if there is any pair that are unequal.
<xsl:if test="count(zone) >= 2"> This is a boolean expression because it uses the greater-than-or-equal boolean operator. If the count() function returns a value greater than or equal to 2, the test attribute is true . Otherwise, the test attribute is false .
=
should work just fine
e.g. This input Xml
<xml>
<SomeElement>1</SomeElement>
<SomeAttribute attr="true" />
</xml>
Through this transform:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/xml">
<xsl:if test="SomeElement=1">
Some Element is 1
</xsl:if>
<xsl:if test="SomeAttribute/@attr='true'">
Some Attribute is true
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Returns
Some Element is 1
Some Attribute is true
As expected. Possibly the error is in the path selector, not in the test
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With