PageRenderTime 14ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/xquery/functx.xqm

http://transcriptstudio4isha.googlecode.com/
Unknown | 72 lines | 64 code | 8 blank | 0 comment | 0 complexity | 2a03b5c8e0782a34b1adad47f182342c MD5 | raw file
 1xquery version "1.0";
 2
 3module namespace functx = "http://www.functx.com"; 
 4declare function functx:add-attributes 
 5  ( $elements as element()* ,
 6    $attrNames as xs:QName* ,
 7    $attrValues as xs:anyAtomicType* )  as element()? {
 8       
 9   for $element in $elements
10   return element { node-name($element)}
11                  { for $attrName at $seq in $attrNames
12                    return if ($element/@*[node-name(.) = $attrName])
13                           then ()
14                           else attribute {$attrName}
15                                          {$attrValues[$seq]},
16                    $element/@*,
17                    $element/node() }
18};
19
20declare function functx:remove-attributes($elements as element()*, $attrNames as xs:QName*) as element() {       
21	for $element in $elements
22	return element
23		{node-name($element)}
24		{
25			$element/@*[not(node-name(.) = $attrNames)],
26			$element/node()
27		}
28};
29 
30declare function functx:add-or-update-attributes($elements as element()*, $attrNames as xs:QName*, $attrValues as xs:anyAtomicType*) as element()? {
31	for $element in $elements
32	return element
33		{node-name($element)}
34		{
35		for $attrName at $seq in $attrNames
36		return attribute {$attrName}
37		                 {$attrValues[$seq]},
38			$element/@*[not(node-name(.) = $attrNames)],
39			$element/node()
40		}
41};
42
43declare function functx:remove-elements($elements as element()*, $names as xs:string*) as element()* 
44{			 
45	for $element in $elements
46	return element
47		{node-name($element)}
48		{
49			$element/@*,
50			$element/*[not(local-name(.) = $names)]
51		}
52};
53
54declare function functx:contains-word($string as xs:string?, $word as xs:string) as xs:boolean
55{
56	let $upString := upper-case($string)
57	let $upWord := upper-case($word)
58	return
59		matches($upString, concat("^(.*\W)?", $upWord, "(\W.*)?$"))
60};
61
62declare function functx:distinct-nodes( $nodes as node()* )  as node()* 
63{       
64    	for $seq in (1 to count($nodes))
65    	return 
66		$nodes[$seq][not(functx:is-node-in-sequence(.,$nodes[position() < $seq]))]
67};
68
69declare function functx:is-node-in-sequence( $node as node()? ,$seq as node()* )  as xs:boolean 
70{       
71   	some $nodeInSeq in $seq satisfies $nodeInSeq is $node
72 };