Hey Rob,
In my lib I have a function that protects all regexp special characters.
Maybe a bit too much heavy machinery for what it does but it works ;-)
I gladly receive improvements.
declare function route:re-escape($string as xs:string)
as xs:string {
let $regexp-chars := ('.','*','+','|','?','(',')','[',']','{','}','^')
return
(: Note that '\' and '$' in the fold caused invalid pattern errors
therefore put them in separate replace :)
fold-left(
$regexp-chars,
replace(replace($string, '\\', '\\\\'), '\$', '\\\$'),
function($a, $b) {
replace($a, '\'||$b, '\\'||$b )
}
)
};
--Marc
On Fri, Aug 15, 2014 at 11:55 AM, Rob Stapper <[email protected]>
wrote:
> Hi,
>
>
>
> How can I construct the relative path between two elements in an xml-file.
>
> Most probably overlooking the obvious I ended up with the solution below,
> which, unfortunately, triggers an runtime-error.
>
>
>
> My not-working solution:
>
>
>
> let $xml :=
>
> <xml>
>
> <A>
>
> <B/>
>
> </A>
>
> </xml>
>
> let $b := $xml//B
>
> let $a := $xml//A
>
>
>
> return replace( string( path( $b))
>
> , string( path( $a))
>
> , ''
>
> )
>
>
>
> Two questions:
>
> - How to retrieve the relative path between two element within a
> xml-file?
>
> - Why does the solution above trigger an error? Can it be a bug?
> ( oops, three questions)
>
>
>
> Thnx in advance for the reply,
>
> Rob Stapper
>
>
> ------------------------------
> <http://www.avast.com/>
>
> Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus
> <http://www.avast.com/> actief is.
>
>
--
--Marc