Changes

Jump to navigation Jump to search
1,505 bytes added ,  13:56, 11 October 2016
=Lookup Operator=
The lookup operator provides some syntactic sugar to access values of maps or array members at a specified position. It is introduced by the question mark ({{Code|?}}) and followed by a specifier. The specifier can be:
# A wildcard {{Code|*}},
<pre class="brush:xquery">
for let $map in maps := (
map { 'name': 'Guðrún', 'city': 'Reykjavík' },
map { 'name': 'Hildur', 'city': 'Akureyri' }
)
return $mapmaps[?name = 'Hildur'] ?city
</pre>
=String Constructor=
The string constructor has been inspired by [https://en.wikipedia.org/wiki/Here_document here document] literals of the Unix shell and various script languages. It allows you to generate strings that contain various characters that would otherwise be interpreted as XQuery delimiters.
The string constructors syntax uses two backticks and a square bracket for opening and closing a string:
<pre class="brush:xquery">
(: Returns "The This is a 'new syntax is 'very& ' flexible!' syntax." :)``["The This is a 'new syntax is 'very& ' flexible!' syntax."]``
</pre>
==Adaptive Serialization==
In BaseX, The {{Code|adaptive}} is used as the new default serialization method. It provides a intuitive textual representation for all XDM types, including maps and arrays, functions, attributes, and namespaces. All items will be separated using by the value of the {{Code|item-separator}} parameter, or which by default is a newline if no value character. It is specifiedutilized by the functions <code>[[Profiling Module#prof:dump|prof:dump]]</code> and <code>[http://www.w3.org/TR/xpath-functions-31/#func-trace fn:trace]</code>. Example:
<pre class="brush:xquery">
declare option output:method 'adaptive';
<element id='id0'/>/@id,
xs:token("abc"),
map { 'key': 'value' },
true#0
<pre class="brush:xml">
id="id0"xs:token("abc"),map {
"key": "value"
}
function fn:true#0
</pre>
</pre>
===fn:json-docsdoc===
; Signatures
(: result:
<map xmlns="http://www.w3.org/2005/xpath-functions/json">
<string key="message">world</string>
</map> :)
<pre class="brush:xquery">
(: returns "JSON" :)
xml-to-json(<string xmlns="http://www.w3.org/2005/xpath-functions/json">JSON</string>)
</pre>
==fn:sort==
 
{{Mark|Updated with Version 8.6:}} Collation argument was inserted between first and second argument.
; Signatures
* <code>fn:sort($input as item()*) as item()*</code>
* <code>fn:sort($input as item()*, $collation as xs:string?) as xs:anyAtomicType*)) as item()*</code>* <code>fn:sort($input as item()*, $collation as xs:string?, $key as function(item()*) as xs:anyAtomicType*)) as item()*</code>
Returns a new sequence with sorted {{Code|$input}} items, using an optional {{Code|$collation}}. If a sort {{Code|$key}} function is givensupplied, it will be applied on all items. The items of the resulting values will be sorted using the semantics of the {{Code|lt}} expression.
<pre class="brush:xquery">
sort(reverse(1 to 3)) (: yields 1, 2, 3 :),reverse(sort(1 to 3)) (: returns the sorted order in descending order :),sort((3, -2, 1), (), abs#1) (: yields 1, -2, 3 :),sort((1,2,3), (), function($x) { -$x }) (: yields 3, 2, 1 :),sort((1, 'a')) (: yields an error, as strings and integers cannot be compared :)
</pre>
fn:trace(<xml/>, "Node: ")/node() (: yields the debugging output "Node: <xml/>" :),
fn:trace(<xml/>)/node() (: returns the debugging output "<xml/>" :)
</pre>
 
==fn:string-join==
 
The type of the first argument is now <code>xs:anyAtomicType*</code>, and all items will be implicitly cast to strings:
 
<pre class="brush:xquery">
fn:string-join(1 to 3) (: yields the string "123" :)
</pre>
==fn:default-language==
 
{{Mark|Introduced with BaseX 8.4:}}
Returns the default language used for formatting numbers and dates. BaseX always returns {{Code|en}}.
(: returns 0 (both strings are compared as equal) :)
compare('a-b', 'ab', 'http://www.w3.org/2013/collation/UCA?alternate=shifted')
</pre>
 
=Enclosed Expressions=
 
''Enclosed expression'' is the syntactical term for the expressions that are specified inside a function body, try/catch clauses, node constructors and some other expressions. In the following example expressions, it’s the empty sequence:
 
<pre class="brush:xquery">
declare function local:x() { () };
try { () } catch * { () },
element x { () },
text { () }
</pre>
 
With XQuery 3.1, the expression can be omitted. The following query is equivalent to the upper one:
 
<pre class="brush:xquery">
declare function local:x() { };
try { } catch * { },
element x { }
text { }
</pre>
=Changelog=
 
;Version 8.6
 
* Updated: Collation argument was inserted between first and second argument.
;Version 8.4
* Added: [[#String Constructors|String Constructors]]* Added: , [[#fn:default-language|fn:default-language]], [[#Enclosed Expressions|Enclosed Expressions]]* Updated: [[#Adaptive Serialization|Adaptive Serialization]], [[#fn:string-join|fn:string-join]]
;Version 8.2
;Version 8.1
* Updated: arrays are now based on an efficient a [http://en.wikipedia.org/wiki/Finger_tree Finger Tree] implementation.
Introduced with Version 8.0.
 
[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu