1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the documentation of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21 ** of its contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
46 xmlpatterns myQuery.xq
50 declare namespace c = "http://cookbook/namespace";
51 doc('cookbook.xml')//c:recipe/c:title
55 declare default element namespace "http://cookbook/namespace";
56 doc('cookbook.xml')//recipe/title
60 <title xmlns="http://cookbook/namespace">Quick and Easy Mushroom Soup</title>
61 <title xmlns="http://cookbook/namespace">Cheese on Toast</title>
62 <title xmlns="http://cookbook/namespace">Hard-Boiled Eggs</title>
70 doc('cookbook.xml')//@xml:*
74 doc('cookbook.xml')//@*:name
78 declare default element namespace "http://cookbook/namespace";
79 doc('cookbook.xml')/cookbook/@*
83 declare default element namespace "http://cookbook/namespace";
84 doc("cookbook.xml")/cookbook/recipe[title = "Hard-Boiled Eggs"]
88 declare default element namespace "http://cookbook/namespace";
89 doc('cookbook.xml')//method[string-length(.) = 0]
93 declare default element namespace "http://cookbook/namespace";
94 doc('cookbook.xml')//method[string-length() = 0]
98 declare default element namespace "http://cookbook/namespace";
99 doc('cookbook.xml')/cookbook/recipe[2]
103 declare default element namespace "http://cookbook/namespace";
104 doc('cookbook.xml')/cookbook/recipe[position() = 2]
108 declare default element namespace "http://cookbook/namespace";
109 doc('cookbook.xml')/cookbook/recipe[position() > 1]
113 declare default element namespace "http://cookbook/namespace";
114 doc('cookbook.xml')/cookbook/recipe[last()]
118 declare default element namespace "http://cookbook/namespace";
119 doc('cookbook.xml')/cookbook/recipe[last() - 1]
123 doc('cookbook.xml')//recipe
127 doc('cookbook.xml')//recipe/title
135 <html xmlns="http://www.w3.org/1999/xhtml/"
136 xml:id="{doc("other.html")/html/@xml:id}"/>
140 doc('cookbook.xml')/descendant-or-self::element(recipe)/child::element(title)
148 <cookbook xmlns="http://cookbook/namespace">
152 for $i in doc("cookbook.xml")//@xml:*
157 for $i in doc("cookbook.xml")//@*:name
162 declare default element namespace "http://cookbook/namespace";
163 for $i in doc("cookbook.xml")/cookbook/@*
168 <p xml:id="MushroomSoup"/>
169 <p xml:id="CheeseOnToast"/>
170 <p xml:id="HardBoiledEggs"/>
174 <p name="Fresh mushrooms"/>
176 <p name="Olive oil"/>
180 <p name="Vegetable soup cube"/>
181 <p name="Ground black pepper"/>
182 <p name="Dried parsley"/>
189 <p xmlns="http://cookbook/namespace" count="3"/>
193 <method xmlns="http://cookbook/namespace"/>
197 declare default element namespace "http://cookbook/namespace";
198 doc('cookbook.xml')//recipe[string-length(method) = 0]
202 <recipe xmlns="http://cookbook/namespace" xml:id="HardBoiledEggs">
203 <title>Hard-Boiled Eggs</title>
204 <ingredient name="Eggs" quantity="3" unit="eggs"/>
205 <time quantity="3" unit="minutes"/>
211 declare default element namespace "http://cookbook/namespace";
212 doc('cookbook.xml')/cookbook/recipe[method[empty(step)]]
216 declare default element namespace "http://cookbook/namespace";
217 doc('cookbook.xml')/cookbook/recipe[not(normalize-space(method))]
221 <e>{sum((1, 2, 3))}</e>
229 declare variable $insertion := "example";
230 <p class="important {$insertion} obsolete"/>
234 <p class="important example obsolete"/>
238 declare default element namespace "http://cookbook/namespace";
239 let $docURI := 'cookbook.xml'
240 return if(doc-available($docURI))
241 then doc($docURI)//recipe/<oppskrift>{./node()}</oppskrift>
242 else <oppskrift>Failed to load {$docURI}</oppskrift>
261 let $doc := doc('doc.txt')
262 return $doc/doc/p[1]/span[1]
266 for $a in doc('doc.txt')/doc/p/span[1]
271 doc('doc.txt')/doc/p/span[1]
275 doc('doc.txt')//p/<p>{span/node()}</p>
290 for $a in doc('doc.txt')//p
291 return <p>{$a/span/node()}</p>