Re: [xsl] If/then/else confusion

Subject: Re: [xsl] If/then/else confusion
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Tue, 25 Dec 2012 15:00:10 -0500
Can you provide some sample input for which the Prefix='A' is not
working? Are you using XSLT 1 or XSLT 2 (or 3)? It can make a big
difference, here.

I'm not sure I understand the problem thoroughly, but remember that
in XSLT 2 (and I presume in 3)
  Prefix != 'A'
means "is there any member of the sequence of my children <Prefix>
elements whose string value is not 'A'?", not "are all of the members
of the sequence of my children <Prefix> elements something other than

I'm not sure that's very well expressed. Here is an experiment you
can run to prove the point.

<?xml version="1.0" encoding="UTF-8"?>
  <sort-us-maybe n="1">
  <sort-us-maybe n="2">
  <sort-us-maybe n="3">

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=""; version="2.0">

  <xsl:output method="text"/>

  <xsl:template match="/stuff">
    <xsl:apply-templates select="sort-us-maybe"/>

  <xsl:template match="sort-us-maybe">
    <xsl:value-of select="concat( @n, '--')"/>
    <xsl:text>&#x0A;Prefix=A: </xsl:text>
    <xsl:value-of select="Prefix = 'A'"/>
    <xsl:text>&#x0A;Prefix!=A: </xsl:text>
    <xsl:value-of select="Prefix != 'A'"/>
    <xsl:text>&#x0A;not(Prefix=A): </xsl:text>
    <xsl:value-of select="not( Prefix = 'A' )"/>
    <xsl:text>&#x0A;not(Prefix!=A): </xsl:text>
    <xsl:value-of select="not( Prefix != 'A' )"/>



Prefix=A: true
Prefix!=A: true
not(Prefix=A): false
not(Prefix!=A): false
Prefix=A: false
Prefix!=A: true
not(Prefix=A): true
not(Prefix!=A): false
Prefix=A: true
Prefix!=A: false
not(Prefix=A): false
not(Prefix!=A): true

> Hello, 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"/>
> However, my new task is to not sort by (1) <Prefix> if the prefix
> is 'A' or, (2) if the <CatalogName> contains 'SG'.
> In the positive the statement look is:
> <xsl:sort select="if( Prefix='A' or contains(CatalogName, 'SG')) then
> '' else Prefix"/>
> That statement somehow works for the second filter, [the contains],
> but not the first [the prefix='A'].
> I have no idea what is going on and would appreciate any help I can
> get. Thanks.

Current Thread