WTF of the day...

Oct 23, 2009 15:52

While you can use booleans all day long inside a template in XSLT 1.0, you can *NOT* pass them as values across template application or call boundaries. They invisibly become strings, leading to interesting things such as:

flag?
not(flag)?

flag is true...

flag is false...

When check_something returns true, as above, then you get the following output:

flag? true
not(flag?) false
flag is true...

But if you change that true() in check_something to false(), you get...

flag? false
not(flag?) false
flag is true...

Why? Because value-of, the only way to transport a function value back out of the template, converts the boolean to a string. Either 'true' or 'false'. Which means in the second case, the string is 'false', leading to the correct output for the first line, has a boolean value of true (non-empty), which when not-ted, gives the *boolean* value on the second line, and when checked as a flag, is of course again true.  Note complete lack of any differentiation in the output between the booleans and the strings.

You have to do an explicit check against the *STRING* 'true' at the call site. Change the xsl:if in the template to use test="$flag = 'true'" and it works as expected.

If you're expecting a really insane language model, that is.
Previous post Next post
Up