• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

XSLT Boolean Question

 
Greenhorn
Posts: 25
Mac OS X Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've found an online resource for learning how to use booleans,
http://docstore.mik.ua/orelly/xml/xslt/appc_01.htm

Could someone please point me towards an example involving numbers i.e. to test the values of two elements using a boolean?
 
Marshal
Posts: 25677
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not quite following. What is it that you want to test about those two elements, and why do you want to use "a boolean"?

(That link you posted tells you how to use the boolean() function in XSLT. Did you want to work with boolean values instead? If so then there are operators such as = which produce boolean values.)
 
Martin Bluck
Greenhorn
Posts: 25
Mac OS X Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that's right, I'd like to work with the values, if I have two elements which each contain a value:



What like to do is run a test where an action is carried out.
I already know how to run an If test using this syntax.




So I'd like to be able to run a test to find the greater value using a boolean.
i.e. if (b > a) = true
 
Sheriff
Posts: 7647
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Martin Bluck wrote:So I'd like to be able to run a test to find the greater value using a boolean.
i.e. if (b > a) = true

Shouldn't you write:
Greater than write as & g t ; without spaces.
 
Saloon Keeper
Posts: 22265
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"boolean" is a property. You can have a boolean constant, variable, or expression. The defining characteristic is simply that there are only 2 possible values, typically designated as True/False, Yes/No, Aye/Nay (this was actually an option on one OS I used!), or whatever.

The expression "a > b" is a boolean expression. It can only result in a true or false answer. That's as opposed to, say, "a - b", which can result in any number of numerical answers.

Thus, the expression "if (b > a) = true" is redundant, since if b is greater than a, the result of that sub-expression is going to be true, reducing the equation to "if true = true", which is a tautology.

In XML - including XSL - there is a "gotcha", as Liutauras has observed and that's that the less-than and greater-than operators have ambiguous meanings in XML, since those characters are also part of the XML "magic character" set (< > & " ) and therefore should be represented in a way that doesn't confuse the XML parser, such as:


Which I had to edit a couple of times since it also confused the CodeRanch message parser!

Or, I believe:


The first case being the literal "a > b" expressed via XML entity escaping, the second one using an expression language operator - which is easier to type and to read. Assuming that XSL honors that notation and I didn't just mis-remember it from its use in EL.
 
Martin Bluck
Greenhorn
Posts: 25
Mac OS X Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's really useful, thanks Tim.

 
Get out of my mind! Look! A tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic