[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] Re: RE: How to filter characters from a string?
Subject: [xsl] Re: RE: How to filter characters from a string? From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Sat, 30 Mar 2002 07:14:11 -0800 (PST) |
Greg Faron <gfaron at integretechpub dot com> wrote: > At 02:11 PM 3/29/2002, you wrote: > >Write a translate that removes all the characters that are allowed in > >base64. The result of this translate is a string containing all the > >characters that aren't allowed, i.e. the ones you want to remove. > > Use this as the second parameter for another translate(): > > > >translate($x, translate($x, 'ABCDE...abcde...12345...', ''), '') > > Oooh, I like that one. This way the second translate() is > customized for every argument, but easily coded (and maintained). Do > you know of any way to benchmark Microsoft XSLT operations so that I > could see which is faster? I suspect that the double translate() is > better than the template solution posted earlier. Mike's solution is fantastic -- extremely nice and elegant! On the other side, double translate means two passes over the string. Even if Mike's algorithm is coded in Assembler, it will be slower than a one-pass algorithm for fairly big strings. I checked this statement and it is true. Compared to the str-filter() (a DVC variant) the double translate is lightningly faster for very short strings, but its execution time grows very steeply when the input string is doubled. So, at length of around 45000 characters the str-filter() - based transformation overtook the double translate. The results in seconds were: str-filter() double-translate() ----------- ------------------ 1.095 1.308 This was measured on a P4 1.7GHz 256MB RAM with MSXML4. For strings with this length or longer, the str-filter() function will be much faster. For example the same two transformations on a 90000 long string resulted in: str-filter() double-translate() ----------- ------------------ 2.114 11.562 Bellow is the text of the DVC variant of str-filter(). str-filterDVC.xsl: ----------------- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:template name="str-filter"> <xsl:param name="pStr"/> <xsl:param name="pController" select="/.."/> <xsl:param name="pElName" select="'str'"/> <xsl:if test="not($pController)"> <xsl:message terminate="yes">[str-filter]Error: pController not specified.</xsl:message> </xsl:if> <xsl:element name="{$pElName}"> <xsl:call-template name="_str-filter"> <xsl:with-param name="pStr" select="$pStr"/> <xsl:with-param name="pController" select="$pController"/> </xsl:call-template> </xsl:element> </xsl:template> <xsl:template name="_str-filter"> <xsl:param name="pStr" /> <xsl:param name="pController" select="/.."/> <xsl:variable name="vLen" select="string-length($pStr)"/> <xsl:choose> <xsl:when test="$vLen = 1"> <xsl:variable name="vHolds"> <xsl:apply-templates select="$pController"> <xsl:with-param name="arg1" select="$pStr"/> </xsl:apply-templates> </xsl:variable> <xsl:if test="string($vHolds)"> <xsl:copy-of select="$pStr"/> </xsl:if> </xsl:when> <xsl:when test="$vLen > 1"> <xsl:variable name="vHalf" select="floor($vLen div 2)"/> <xsl:call-template name="_str-filter"> <xsl:with-param name="pStr" select="substring($pStr, 1, $vHalf)"/> <xsl:with-param name="pController" select="$pController"/> </xsl:call-template> <xsl:call-template name="_str-filter"> <xsl:with-param name="pStr" select="substring($pStr, $vHalf + 1)"/> <xsl:with-param name="pController" select="$pController"/> </xsl:call-template> </xsl:when> </xsl:choose> </xsl:template> </xsl:stylesheet> I think this is just an example of the potential of useful functionality and efficiency, offered by the functional programming library FXSL. Cheers, Dimitre Novatchev. __________________________________________________ Do You Yahoo!? Yahoo! Greetings - send holiday greetings for Easter, Passover http://greetings.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: Re: How to filter charact, Dimitre Novatchev | Thread | [xsl] Re: RE: How to filter charact, Dimitre Novatchev |
RE: [xsl] XML String as Parameter.., Ramesh B | Date | [xsl] Re: RE: How to filter charact, Dimitre Novatchev |
Month |
Keywords