Project

Profile

Help

How to connect?
Download (1.42 KB) Statistics
| Branch: | Revision:

he / src / use-cases / xmp / addq10.xq @ a31dd97a

1
xquery version "1.0";
2
(: Additional Use Case addq10 :)
3
(: Use typeswitch :)
4

    
5
declare namespace f="my.uri";
6
declare function f:show-atomic-type($p) {
7
  typeswitch ($p)
8
    case $i as xs:integer return concat("integer ", string($i))
9
    case xs:string return "string"
10
    case $b as xs:boolean return concat("boolean ", string($b))
11
    case xs:decimal return "decimal"
12
    case xs:double return "double"
13
    case xs:anyAtomicType+ return "atomic sequence"
14
    case xs:anyAtomicType return "atomic value"
15
    case xs:anyAtomicType? return "empty sequence"
16
    default return "not an atomic value"
17
};
18

    
19
declare function f:show-node-kind($p) {
20
  typeswitch ($p)
21
    case $e as element() return "element"
22
    case $a as attribute() return "attribute"
23
    case $t as text() return "text"
24
    case $c as comment() return "comment"
25
    case $p as processing-instruction() return "pi"
26
    case $d as document-node() return "document"
27
    case node()+ return "node sequence"
28
    default return "unknown"
29
}; 
30
   
31
<test>
32
<t1>{f:show-atomic-type(1)}</t1>
33
<t1>{f:show-atomic-type(true())}</t1>
34
<t1>{f:show-atomic-type(1.1)}</t1>
35
<t1>{f:show-atomic-type(1.3e4)}</t1>
36
<t1>{f:show-atomic-type("jimmy")}</t1>
37
<t1>{f:show-atomic-type((1,2,3))}</t1>
38
<t1>{f:show-atomic-type(<a/>)}</t1>
39
<t2>{f:show-node-kind(<a/>)}</t2>
40
<t2>{f:show-node-kind(attribute little {"big"})}</t2>
41
<t2>{f:show-node-kind(text {"tittle-tattle"})}</t2>
42
</test>
(2-2/38)