membersound
membersound

Reputation: 86925

How to evaluate xsl:if for numbers?

https://xsltfiddle.liberty-development.net/pPJ8LV9

<person age="18"/>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>


    <xsl:template match="person">
      <xsl:variable name="given" select="12" />

      <xs:if test="(@age &lt; $given)">
          <xsl:value-of select="(@age &lt; $given)"/>
          <xsl:text>&#10;</xsl:text>
          <xsl:text>SHOULD NOT PRING</xsl:text>
      </xs:if>

  </xsl:template>
</xsl:stylesheet>

Result:

false
SHOULD NOT PRING

Why on earth does it print, when the condition obviously evaluates to false?

Upvotes: 0

Views: 102

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117165

You need to change:

xs:if

to:

xsl:if

What you have now is not a condition, but a literal result element. You can see this if you change the output method to xml.


P.S. Not sure why you need the parentheses.

Upvotes: 1

Related Questions