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

Re: Question on translate() function

Subject: Re: Question on translate() function
From: "Syd Bauman s.bauman@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 25 Sep 2017 17:42:01 -0000
Re:  Question on translate() function
Right. Use the same number of number signs in the 3rd parameter as
you have chars you want replaced in the 2nd parameter. Reminder, in
this case (OP wants every character in 2nd param replaced by number
sign), it is better to have too many number signs in the 3rd param
than too few. (Although I don't think anyone would argue that having
the correct number of # is the right way to go.)

Mike, or other internals guru --

I have always presumed that translate() is faster than replace().[1]
I know that I, the mere XSLT programmer, am not supposed to worry my
pretty little head about optimization unless I actually have a
problem. And I know that if one of my students asked, that's what I
would answer: "You have 1 MiB of XML data, and that computer on your
lap would have been considered a supercomputer a mere two decades
ago. Yes, A is probably more efficient than B, but the number of
microseconds you save, even when added up over thousands of
iterations of this transformation, will end up being less time than
this conversation. Besides, we don't know what optimization the XSLT
engine is (or is not) doing -- for all we know it might be better at
optimizing B, even if un-optimized B is slower. So don't fret the
speed unless something is running too slow."

But I can't help it, sometimes -- I'd really like to know if
translate() is significantly more efficient (computationally) than
replace() or not.

Notes
-----
[1] Not sure why I have this prejudice. Perhaps because translate()
    was in XSLT1, but replace() was not; more likely because
    replace() uses regular expressions, which I imagine take quite a
    bit of computing; but most likely as a leftover from my IBM S360
    Assembler days, when a translate was done in a single machine
    instruction. (Of course, it only operated on the 256 8-bit chars
    of EBCDIC, not on Unicode.)


> translate($string ,'()''+-*$=' , '#')
> 
> That means "replace '(' by '#', remove any occurrences of ')' or '
> or '+' or '-' or '*' or '$' or '=', and leave anything else
> unchanged."
> 
> If you want all the characters in the second argument to be
> replaced by '#' characters then you need to write
> 
> translate($string ,'()''+-*$=' , '########')
> 
> Alternatively, use the replace() function.

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.