xsl-list
[Top] [All Lists]

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

2009-09-10 23:41:44

  <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(_dot_)robinson(_at_)stanford(_dot_)edu
Stanford University HighWire Press      http://highwire.stanford.edu/
+1 650 7237294 (Work)                   +1 650 7259335 (Fax)

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--