xsl-list
[Top] [All Lists]

Re: [xsl] Escaping Characters in replace()

2013-10-15 12:08:34
Nathan Tallman <ntallman(_at_)gmail(_dot_)com> writes:

[…]

Why didn't you need to escape the period in the third argument of
replace ()?  (When I insert one, my processor throws an error; so, I
understand it's wrong, but not why.

        The second argument to replace () is a regular expression of the
        flavor that uses ‘.’ to denote “any character.”  (The regular
        expression to match a literal period is produced by “escaping”
        such a special character with a ‘\’, thus forming ‘\.’.)

        On the contrary, the replacement string is not a regular
        expression, ‘.’ (as well as a number of other characters) is
        always taken literally there, and needs no escaping whatsoever.
        Moreover, I guess that ‘\’ plays its own, different role there.
        (I’m not exactly familiar with XPath versions other than 1.0.)

Also, I seem to be able to delete the backslash in front of the
period in the second argument without causing problems...  Why is
that?)

        The probable cause is that the source text doesn’t contain any
        sequences of the form ⟨any character other than‘.’⟩⟨"⟩ in the
        context replace () is applied to.  Otherwise, these would also
        be replaced with ⟨".⟩, as in:

   Source: <unittitle>"Mary had a little lamb"</unittitle>
   Result: <unittitle>"Mary had a little lam."</unittitle>

-- 
FSF associate member #7257

--~------------------------------------------------------------------
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>
--~--