Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the logical equals condtion in XSLT?

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 &lt; and > is &gt; 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?

like image 963
Jack Thor Avatar asked Aug 13 '13 18:08

Jack Thor


People also ask

How do you use equal in XSLT?

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.

Is not equal to in XSLT?

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.

How do you write greater than or equal to in XSLT?

<xsl:if test="count(zone) &gt;= 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 .


1 Answers

= 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 ?

like image 134
StuartLC Avatar answered Nov 01 '22 03:11

StuartLC