Mercurial > kallithea
annotate rhodecode/public/js/mode/xquery/index.html @ 4029:c9bcfe2d2ade
codecleaner
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 21 Jun 2013 01:11:16 +0200 |
parents | a60a0e9092c6 |
children |
rev | line source |
---|---|
4029 | 1 <!doctype html> |
2 <html> | |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 <!-- |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 /* |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 Copyright (C) 2011 by MarkLogic Corporation |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 Author: Mike Brevoort <mike@brevoort.com> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 Permission is hereby granted, free of charge, to any person obtaining a copy |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 of this software and associated documentation files (the "Software"), to deal |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 in the Software without restriction, including without limitation the rights |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 copies of the Software, and to permit persons to whom the Software is |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 furnished to do so, subject to the following conditions: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 The above copyright notice and this permission notice shall be included in |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 all copies or substantial portions of the Software. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 THE SOFTWARE. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 */ |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 --> |
4029 | 27 <head> |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 <meta charset="utf-8"> |
4029 | 29 <title>CodeMirror: XQuery mode</title> |
30 <link rel="stylesheet" href="../../lib/codemirror.css"> | |
31 <script src="../../lib/codemirror.js"></script> | |
32 <script src="xquery.js"></script> | |
33 <link rel="stylesheet" href="../../doc/docs.css"> | |
34 <link rel="stylesheet" href="../../theme/xq-dark.css"> | |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 <style type="text/css"> |
4029 | 36 .CodeMirror { |
37 border-top: 1px solid black; border-bottom: 1px solid black; | |
38 height:400px; | |
39 } | |
40 </style> | |
41 </head> | |
42 <body> | |
43 <h1>CodeMirror: XQuery mode</h1> | |
44 | |
45 <div class="cm-s-default"> | |
46 <textarea id="code" name="code"> | |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 xquery version "1.0-ml"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 (: this is |
4029 | 49 : a |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 "comment" :) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 let $let := <x attr="value">"test"<func>function() $var {function()} {$var}</func></x> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 let $joe:=1 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 return element element { |
4029 | 54 attribute attribute { 1 }, |
55 element test { 'a' }, | |
56 attribute foo { "bar" }, | |
57 fn:doc()[ foo/@bar eq $let ], | |
58 //x } | |
59 | |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 (: a more 'evil' test :) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 (: Modified Blakeley example (: with nested comment :) ... :) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 declare private function local:declare() {()}; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 declare private function local:private() {()}; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 declare private function local:function() {()}; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 declare private function local:local() {()}; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 let $let := <let>let $let := "let"</let> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 return element element { |
4029 | 68 attribute attribute { try { xdmp:version() } catch($e) { xdmp:log($e) } }, |
69 attribute fn:doc { "bar" castable as xs:string }, | |
70 element text { text { "text" } }, | |
71 fn:doc()[ child::eq/(@bar | attribute::attribute) eq $let ], | |
72 //fn:doc | |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 xquery version "1.0-ml"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 (: Copyright 2006-2010 Mark Logic Corporation. :) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 (: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 : Licensed under the Apache License, Version 2.0 (the "License"); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 : you may not use this file except in compliance with the License. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 : You may obtain a copy of the License at |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 : |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 : http://www.apache.org/licenses/LICENSE-2.0 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 : |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 : Unless required by applicable law or agreed to in writing, software |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 : distributed under the License is distributed on an "AS IS" BASIS, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 : See the License for the specific language governing permissions and |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 : limitations under the License. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 :) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 module namespace json = "http://marklogic.com/json"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 declare default function namespace "http://www.w3.org/2005/xpath-functions"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 (: Need to backslash escape any double quotes, backslashes, and newlines :) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 declare function json:escape($s as xs:string) as xs:string { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 let $s := replace($s, "\\", "\\\\") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 let $s := replace($s, """", "\\""") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 let $s := replace($s, codepoints-to-string((13, 10)), "\\n") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 let $s := replace($s, codepoints-to-string(13), "\\n") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 let $s := replace($s, codepoints-to-string(10), "\\n") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 return $s |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 }; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 declare function json:atomize($x as element()) as xs:string { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 if (count($x/node()) = 0) then 'null' |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 else if ($x/@type = "number") then |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
111 let $castable := $x castable as xs:float or |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
112 $x castable as xs:double or |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 $x castable as xs:decimal |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 return |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 if ($castable) then xs:string($x) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 else error(concat("Not a number: ", xdmp:describe($x))) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 else if ($x/@type = "boolean") then |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 let $castable := $x castable as xs:boolean |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 return |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 if ($castable) then xs:string(xs:boolean($x)) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 else error(concat("Not a boolean: ", xdmp:describe($x))) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 else concat('"', json:escape($x), '"') |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 }; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 (: Print the thing that comes after the colon :) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 declare function json:print-value($x as element()) as xs:string { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 if (count($x/*) = 0) then |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 json:atomize($x) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 else if ($x/@quote = "true") then |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 concat('"', json:escape(xdmp:quote($x/node())), '"') |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 else |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 string-join(('{', |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 string-join(for $i in $x/* return json:print-name-value($i), ","), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 '}'), "") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 }; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 (: Print the name and value both :) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 declare function json:print-name-value($x as element()) as xs:string? { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 let $name := name($x) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
140 let $first-in-array := |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 count($x/preceding-sibling::*[name(.) = $name]) = 0 and |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 (count($x/following-sibling::*[name(.) = $name]) > 0 or $x/@array = "true") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
143 let $later-in-array := count($x/preceding-sibling::*[name(.) = $name]) > 0 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 return |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 if ($later-in-array) then |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
147 () (: I was handled previously :) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 else if ($first-in-array) then |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
149 string-join(('"', json:escape($name), '":[', |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
150 string-join((for $i in ($x, $x/following-sibling::*[name(.) = $name]) return json:print-value($i)), ","), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 ']'), "") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
152 else |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
153 string-join(('"', json:escape($name), '":', json:print-value($x)), "") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
154 }; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
155 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
156 (:~ |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
157 Transforms an XML element into a JSON string representation. See http://json.org. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
158 <p/> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
159 Sample usage: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
160 <pre> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
161 xquery version "1.0-ml"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
162 import module namespace json="http://marklogic.com/json" at "json.xqy"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 json:serialize(&lt;foo&gt;&lt;bar&gt;kid&lt;/bar&gt;&lt;/foo&gt;) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 </pre> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 Sample transformations: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
166 <pre> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
167 &lt;e/&gt; becomes {"e":null} |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
168 &lt;e&gt;text&lt;/e&gt; becomes {"e":"text"} |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
169 &lt;e&gt;quote " escaping&lt;/e&gt; becomes {"e":"quote \" escaping"} |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
170 &lt;e&gt;backslash \ escaping&lt;/e&gt; becomes {"e":"backslash \\ escaping"} |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
171 &lt;e&gt;&lt;a&gt;text1&lt;/a&gt;&lt;b&gt;text2&lt;/b&gt;&lt;/e&gt; becomes {"e":{"a":"text1","b":"text2"}} |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
172 &lt;e&gt;&lt;a&gt;text1&lt;/a&gt;&lt;a&gt;text2&lt;/a&gt;&lt;/e&gt; becomes {"e":{"a":["text1","text2"]}} |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
173 &lt;e&gt;&lt;a array="true"&gt;text1&lt;/a&gt;&lt;/e&gt; becomes {"e":{"a":["text1"]}} |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
174 &lt;e&gt;&lt;a type="boolean"&gt;false&lt;/a&gt;&lt;/e&gt; becomes {"e":{"a":false}} |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
175 &lt;e&gt;&lt;a type="number"&gt;123.5&lt;/a&gt;&lt;/e&gt; becomes {"e":{"a":123.5}} |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
176 &lt;e quote="true"&gt;&lt;div attrib="value"/&gt;&lt;/e&gt; becomes {"e":"&lt;div attrib=\"value\"/&gt;"} |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
177 </pre> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
178 <p/> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
179 Namespace URIs are ignored. Namespace prefixes are included in the JSON name. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 <p/> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
181 Attributes are ignored, except for the special attribute @array="true" that |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
182 indicates the JSON serialization should write the node, even if single, as an |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
183 array, and the attribute @type that can be set to "boolean" or "number" to |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
184 dictate the value should be written as that type (unquoted). There's also |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
185 an @quote attribute that when set to true writes the inner content as text |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
186 rather than as structured JSON, useful for sending some XHTML over the |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
187 wire. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
188 <p/> |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
189 Text nodes within mixed content are ignored. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
190 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
191 @param $x Element node to convert |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
192 @return String holding JSON serialized representation of $x |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
193 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
194 @author Jason Hunter |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
195 @version 1.0.1 |
4029 | 196 |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
197 Ported to xquery 1.0-ml; double escaped backslashes in json:escape |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 :) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
199 declare function json:serialize($x as element()) as xs:string { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
200 string-join(('{', json:print-name-value($x), '}'), "") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
201 }; |
4029 | 202 </textarea> |
203 </div> | |
204 | |
205 <script> | |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
206 var editor = CodeMirror.fromTextArea(document.getElementById("code"), { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
207 lineNumbers: true, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
208 matchBrackets: true, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
209 theme: "xq-dark" |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
210 }); |
4029 | 211 </script> |
212 | |
213 <p><strong>MIME types defined:</strong> <code>application/xquery</code>.</p> | |
214 | |
215 <p>Development of the CodeMirror XQuery mode was sponsored by | |
216 <a href="http://marklogic.com">MarkLogic</a> and developed by | |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
217 <a href="https://twitter.com/mbrevoort">Mike Brevoort</a>. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
218 </p> |
4029 | 219 |
220 </body> | |
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
221 </html> |