[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: If/then/else confusion

Subject: Re: If/then/else confusion
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 25 Dec 2012 15:34:22 -0500
Re:  If/then/else confusion
At 2012-12-25 12:19 -0700, Mark Wilson wrote:
I am trying to modify a sort-select statement I worked out a very long time ago. In the original, I wanted not to sort by a <Prefix> if it were an 'A' and this code does just that:

<xsl:sort select="if( Prefix!='A' ) then Prefix else ''"/>

I am not sure why its positive version does not work:
<xsl:sort select="if( Prefix='A' ) then '' else Prefix"/>

Those two expressions are not polar opposites because at least one of the operands is a node set.


This is an important issue that I bring up in the classroom because of the confusion of dealing with node sets.

The result of the comparison is initialized as false() and then the comparisons begin with members of the node set. If the node set is empty, there are no comparisons and so false() is returned.

So, if you have an element Prefix, then "Prefix != 'A'" returns true() if, say, Prefix has the value 'B'. But, "Prefix != 'A'" returns false() if there are no Prefix elements. One might think that that expression returning false() would imply that there is a Prefix and it has the value 'A'. It doesn't in this example (though it would be true if, in fact, there were a Prefix and it has the value 'A'). This is not intuitive and you need to know about how comparisons work with node sets.

The polar opposite of "Prefix = 'A'" is "not( Prefix = 'A')".

I have no idea what is going on and would appreciate any help I can get.

I hope this helps explain your situation.


And a Merry Christmas to you and other readers who celebrate it!

. . . . . . . . Ken


-- Contact us for world-wide XML consulting and instructor-led training Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.