diff software/eXist/webapp/mpdl/util/functx.xql @ 7:5589d865af7a

Erstellung XQL/XSL Applikation
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 08 Feb 2011 15:16:46 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software/eXist/webapp/mpdl/util/functx.xql	Tue Feb 08 15:16:46 2011 +0100
@@ -0,0 +1,62 @@
+xquery version "1.0";
+
+module namespace functx = "http://www.functx.com"; 
+
+declare function functx:path-to-node-with-pos( $node as node()? )  as xs:string {
+  string-join(
+    for $ancestor in $node/ancestor-or-self::*
+      let $sibsOfSameName := $ancestor/../*[name() = name($ancestor)]
+    return 
+      concat(name($ancestor),
+        if (count($sibsOfSameName) <= 1)
+        then ''
+        else concat('[', functx:index-of-node($sibsOfSameName, $ancestor),']'))
+      , '/')
+ };
+ 
+declare function functx:index-of-node( $nodes as node()*, $nodeToFind as node() ) as xs:integer* {
+  for $seq in (1 to count($nodes))
+  return $seq[$nodes[$seq] is $nodeToFind]
+};
+ 
+declare function functx:substring-before-last( $arg as xs:string?, $delim as xs:string ) as xs:string {
+  if (matches($arg, functx:escape-for-regex($delim)))
+  then replace($arg,
+           concat('^(.*)', functx:escape-for-regex($delim),'.*'),
+           '$1')
+  else ''
+};
+
+declare function functx:substring-after-last( $arg as xs:string?, $delim as xs:string ) as xs:string {
+  replace ($arg,concat('^.*',functx:escape-for-regex($delim)),'')
+};
+
+declare function functx:escape-for-regex( $arg as xs:string? ) as xs:string {
+  replace($arg,
+           '(\.|\[|\]|\\|\||\-|\^|\$|\?|\*|\+|\{|\}|\(|\))','\\$1')
+};
+
+declare function functx:trim($arg as xs:string?) as xs:string {
+  replace(replace($arg,'\s+$',''),'^\s+','')
+};
+ 
+ declare function functx:value-intersect 
+  ( $arg1 as xs:anyAtomicType* ,
+    $arg2 as xs:anyAtomicType* )  as xs:anyAtomicType* {
+       
+  distinct-values($arg1[.=$arg2])
+};
+
+declare function functx:value-except 
+  ( $arg1 as xs:anyAtomicType* ,
+    $arg2 as xs:anyAtomicType* )  as xs:anyAtomicType* {
+       
+  distinct-values($arg1[not(.=$arg2)])
+};
+
+declare function functx:value-union 
+  ( $arg1 as xs:anyAtomicType* ,
+    $arg2 as xs:anyAtomicType* )  as xs:anyAtomicType* {
+       
+  distinct-values(($arg1, $arg2))
+};
\ No newline at end of file