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

Re: Tokenize followed by compare or satisfies using c

Subject: Re: Tokenize followed by compare or satisfies using contains()?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 2 Sep 2016 19:02:41 -0000
Re:  Tokenize followed by compare or satisfies using  c
Well, the tokenize() seems more correct: presumably if $link-classes is
"green" and $node/@class is "pale-green" you want the answer to be false,
which it will be with the tokenize() approach but not with the contains()
approach.

But shouldn't the regex for the tokenize case be '\s+' rather than ' '?

Performance of course is product dependent and you just have to measure it.
Intrinsically, tokenizing is more complex than just searching for a
substring.

Michael Kay
Saxonica


> On 2 Sep 2016, at 17:04, Eliot Kimber ekimber@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> In the DITA processing code, where we are using XSLT 2 and checking for
> string matches in attribute values, I have the requirement to see if any
> of a number of strings might match.
>
> The current code is:
>
> some $c in $link-classes satisfies contains($node/@class, $c))
>
> Where $link-classes is a sequence of strings and @class is a
> blank-delimited sequence of strings.
>
>
> Another way to do this check would be:
>
> $link-classes = tokenize($node/@class, ' ')
>
> This is a check that will be made a lot so performance may important (or
> it may not be). The tokenize version seems simpler and clearer to me but
> the satisfies approach has a certain elegance that I also like.
>
> My question: is there any reason to prefer one or the other of these? I
> realize that XSLT 3 provides a new way to do token matching in strings but
> for now we're stuff with XSLT 2.
>
> Cheers,
>
> Eliot
> --
> Eliot Kimber
> http://contrext.com

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.