[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] If/then/else confusion

Subject: Re: [xsl] If/then/else confusion
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 25 Dec 2012 15:34:22 -0500

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