Re: [xsl] Imagine that the semantics of comparison operations was this

Subject: Re: [xsl] Imagine that the semantics of comparison operations was this
From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 2 Mar 2025 21:29:30 -0000
On Sun, 2025-03-02 at 15:24 +0000, Roger L Costello costello@xxxxxxxxx
wrote:

>
> <xsl:variable name="isDifferent" select="$FIRST ne $SECOND"
> as="xs:boolean"/>
> <xsl:variable name="APPEND" as="xs:string?">
> B B B  <xsl:if test="$isDifferent eq true()">
> B B B B B B B  <xsl:sequence select="concat($FIRST, $SECOND)"/>
> B B B  </xsl:if>
> </xsl:variable>

We could also write,
  <xsl:variable name="APPEND" as="xs:string"
   select="if ($FIRST ne $SECOND)
           then concat($FIRST, $SECOND)
           else ''" />

Generally i prefer this to tricks with predicates as it says what is
meant directly.

We could also write a function to do it, e.g.
  <xsl:variable name="mitre:append-when-unequal"
    as="function($s1 as xs:string, $s2 as xs:string)
    as xs:string
    {
       (: join unequal strings :)      B 
       if ($s1 eq $s2) then ''
       else $s1 || $s2
    }
    "/

and use it in XPath expressions with
  $mitr:append-when-unequal(title, $new-title)
or whatever - using functions to give names to ideas helps people
understand what youbve written.

liam


--
Liam Quin,B https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations: B http://www.fromoldbooks.org

Current Thread