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

Re: A nice way to implement the ANDing of the comparis

Subject: Re: A nice way to implement the ANDing of the comparison of pairs of items in a sequence?
From: Adam Retter <adam.retter@xxxxxxxxxxxxxx>
Date: Thu, 5 Sep 2013 20:56:46 +0100
Re:  A nice way to implement the ANDing of the comparis
If you have access to an XSLT processor, you could do something like
the following. Note that I have not thoroughly checked the Syntax as I
do not have an XSLT 3 processor.


<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:f="http://function"
    version="3.0">

    <xsl:output method="xml"/>

    <xsl:variable name="checkPairs"
        select="('Sally', 'Sally', 'Beth', 'beth', 'Mary', 'Mary')"
as="xs:string*"/>

    <xsl:template match="/">
        <!-- split the checkPairs sequence into two sequences -->
        <xsl:variable name="sq1" select="$checkPairs[position() mod 2 != 0]"/>
        <xsl:variable name="sq2" select="$checkPairs[position() mod 2 = 0]"/>

        <!-- compare the two sequences -->
        <xsl:variable name="results" select="for-each-pair($sq1, $sq2,
f:string-equal)"/>

        <!-- reduce the results -->
        <xsl:variable name="result" select="fold-left($results,
true(), f:and)"/>

    </xsl:template>


    <xsl:function name="f:string-equal">
        <xsl:param name="a" as="xs:string"/>
        <xsl:param name="b" as="xs:string"/>
        <xsl:value-of select="$a eq $b"/>
    </xsl:function>

    <xsl:function name="f:and">
        <xsl:param name="a" as="xs:boolean"/>
        <xsl:param name="b" as="xs:boolean"/>
        <xsl:value-of select="$a and $b"/>
    </xsl:function>

</xsl:stylesheet>

On 5 September 2013 19:51, Costello, Roger L. <costello@xxxxxxxxx> wrote:
> Hi Folks,
>
> The value of this variable is a sequence of strings:
>
> <xsl:variable name="checkPairs"
>      select="('Sally', 'Sally', 'Beth', 'Beth', 'Mary', 'Mary')" as="xs:string*"/>
>
> I want to compare consecutive items and then AND the result of the comparisons.
>
> That is, compare the first string to the second string, the third string to the fourth string, the fifth string to the sixth string, and so on. Then AND the results together.
>
> Thus,
>
>     ('Sally' eq 'Sally') and ('Beth' eq 'Beth') and ('Mary' eq 'Mary')
>
> returns true.
>
> But if the variable is this:
>
> <xsl:variable name="checkPairs"
>      select="('Sally', 'Beth', 'Beth', 'Beth', 'Mary', 'Mary')" as="xs:string*"/>
>
> the result is false since
>
>     ('Sally' eq 'Beth') and ('Beth' eq 'Beth') and ('Mary' eq 'Mary')
>
> is false.
>
> Is there a nice way to implement this?
>
> /Roger
>



-- 
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk

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.