[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Finding first difference between 2 text strings


Subject: Re: [xsl] Finding first difference between 2 text strings
From: "James A. Robinson" <jim.robinson@xxxxxxxxxxxx>
Date: Thu, 10 Sep 2009 20:41:21 -0700

>   <xsl:function name="f:mismatch2" as="xs:integer?">
>     <xsl:param name="a" as="xs:string" />
>     <xsl:param name="b" as="xs:string" />
>     <xsl:variable name="aa" select="translate($a,'.+*\{}[]','&#xe001;&#xe002;&#xe003;&#xe004;&#xe005;&#xe006;&#xe007;&#xe008;')"/>
>     <xsl:variable name="bb" select="translate($b,'.+*\{}[]','&#xe001;&#xe002;&#xe003;&#xe004;&#xe005;&#xe006;&#xe007;&#xe008;')"/>
>     <xsl:variable name="r" select="concat('^:',replace($bb,'.','($0'),replace($bb,'.',')?'),'.*')"/>
>     <xsl:sequence  select="1+string-length(replace(concat(':',$aa),$r,'$1'))"/>
>   </xsl:function>

Wow, that's... very very impressive.  So you're replacing regular
expression values with placeholders in both strings, then wrapping ever
character in $bb with a regex expression, e.g., '(a)?', to finally
perform a regex replacement on $aa?  What does the leading colon
do?

Jim

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       jim.robinson@xxxxxxxxxxxx
Stanford University HighWire Press      http://highwire.stanford.edu/
+1 650 7237294 (Work)                   +1 650 7259335 (Fax)


Current Thread