amxml 0.5.3

XML processor with some features of XPath 2.0 / 3.0 / 3.1
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
//
// xpath_impl/oper.rs
//
// amxml: XML processor with XPath.
// Copyright (C) 2018 KOYAMA Hiro <tac@amris.co.jp>
//

use std::cmp::Ordering;
use std::error::Error;

use dom::*;
use xpath_impl::eval::*;
use xpath_impl::xitem::*;
use xpath_impl::xsequence::*;

// ---------------------------------------------------------------------
// 4.2 Arithmatic Operators on Numeric Values
//       op_numeric_add
//       op_numeric_subtract
//       op_numeric_multiply
//       op_numeric_divide
//       op_numeric_integer_divide
//       op_numeric_mod
//       op_numeric_unary_plus
//       op_numeric_unary_minus
// ---------------------------------------------------------------------
//
pub fn op_numeric_add(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
    return op_numeric_operation(args, xitem_numeric_add);
}

pub fn op_numeric_subtract(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
    return op_numeric_operation(args, xitem_numeric_subtract);
}

pub fn op_numeric_multiply(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
    return op_numeric_operation(args, xitem_numeric_multiply);
}

pub fn op_numeric_divide(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
    return op_numeric_operation(args, xitem_numeric_divide);
}

pub fn op_numeric_integer_divide(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
    return op_numeric_operation(args, xitem_numeric_integer_divide);
}

pub fn op_numeric_mod(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
    return op_numeric_operation(args, xitem_numeric_mod);
}

pub fn op_numeric_unary_plus(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
    let arg = args[0].get_singleton_item()?;
    let result = xitem_numeric_unary_plus(&arg)?;
    return Ok(new_singleton(&result));
}

pub fn op_numeric_unary_minus(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
    let arg = args[0].get_singleton_item()?;
    let result = xitem_numeric_unary_minus(&arg)?;
    return Ok(new_singleton(&result));
}

// ---------------------------------------------------------------------
//
fn op_numeric_operation<F>(args: &Vec<XSequence>, mut func_op: F) -> Result<XSequence, Box<Error>>
    where F: FnMut(&XItem, &XItem) -> Result<XItem, Box<Error>> {

    let lhs = args[0].get_singleton_item()?;
    let rhs = args[1].get_singleton_item()?;
    let result = func_op(&lhs, &rhs)?;
    return Ok(new_singleton(&result));
}

// ---------------------------------------------------------------------
// 4.3 Comparison Operators on Numeric Values
//
// ---------------------------------------------------------------------
//
pub fn op_numeric_equal(args: &Vec<&XSequence>) -> Result<XSequence, Box<Error>> {
    return op_numeric_comparison(args, xitem_numeric_equal);
}

pub fn op_numeric_less_than(args: &Vec<&XSequence>) -> Result<XSequence, Box<Error>> {
    return op_numeric_comparison(args, xitem_numeric_less_than);
}

pub fn op_numeric_greater_than(args: &Vec<&XSequence>) -> Result<XSequence, Box<Error>> {
    return op_numeric_comparison(args, xitem_numeric_greater_than);
}

// ---------------------------------------------------------------------
//
fn op_numeric_comparison<F>(args: &Vec<&XSequence>, mut func_op: F) -> Result<XSequence, Box<Error>>
    where F: FnMut(&XItem, &XItem) -> Result<bool, Box<Error>> {

    let lhs = args[0].get_singleton_item()?;
    let rhs = args[1].get_singleton_item()?;
    let result = func_op(&lhs, &rhs)?;
    return Ok(new_singleton_boolean(result));
}

// ---------------------------------------------------------------------
// 5.3.6 fn:compare
//   (文字列の比較はopでなくfnとして実装)
// fn fn_compare(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
//
// ---------------------------------------------------------------------
// 7.2 Operators on Boolean Values
//
// ---------------------------------------------------------------------
//
pub fn op_boolean_equal(args: &Vec<&XSequence>) -> Result<XSequence, Box<Error>> {
    let lhs = args[0].get_singleton_boolean()?;
    let rhs = args[1].get_singleton_boolean()?;
    return Ok(new_singleton_boolean(lhs == rhs));
}

// ---------------------------------------------------------------------
//
pub fn op_boolean_less_than(args: &Vec<&XSequence>) -> Result<XSequence, Box<Error>> {
    let lhs = args[0].get_singleton_boolean()?;
    let rhs = args[1].get_singleton_boolean()?;
    return Ok(new_singleton_boolean(lhs < rhs));
}

// ---------------------------------------------------------------------
//
pub fn op_boolean_greater_than(args: &Vec<&XSequence>) -> Result<XSequence, Box<Error>> {
    let lhs = args[0].get_singleton_boolean()?;
    let rhs = args[1].get_singleton_boolean()?;
    return Ok(new_singleton_boolean(lhs > rhs));
}

// ---------------------------------------------------------------------
// 17.1 Functions that Operate on Maps
//
// ---------------------------------------------------------------------
// 17.1.1 op:same-key
// op:same-key($k1 as xs:anyAtomicType, $k2 as xs:anyAtomicType) as xs:boolean
//
// 若干厳密さに欠ける (例えば、"3" と3が同じになってしまう) が、
// 当面、raw_stringとして比較する。
//
// (1) string (、anyURI、untypedAtomic) どうしの場合:
//     fn:codepoint-equal($k1, $k2) で比較する。
// (2) decimal、double (、float) どうしの場合:
//                  ** おそらくintegerも。
//     (2-a) NaN、INF、-INF どうしならばtrue
//     (2-b) 精度を損なわないようdecimalに変換して比較
// (3) date、time、dateTime、... どうしの場合:
//     fn:deep-equal($k1, $k2) で比較する。
// (4) boolean (、hexBinary、...) どうしの場合:
//     fn:deep-equal($k1, $k2) で比較する。
//
//pub fn op_same_key(args: &Vec<&XSequence>) -> Result<XSequence, Box<Error>> {
//    let k1 = args[0].get_singleton_item()?
//    let k2 = args[1].get_singleton_item()?
//
//    let result = k1.op_same_key(&k2);
//    return Ok(new_singleton_boolean(result));
//}

// ---------------------------------------------------------------------
// Functions and Operators on Nodes
//   (XPath 3.1 では演算子の項に載っていない)
//          is_same_node
//          node_before
//          node_after
//
pub fn op_is_same_node(args: &Vec<XSequence>, eval_env: &EvalEnv) -> Result<XSequence, Box<Error>> {
    return op_node_compare(args, eval_env, Ordering::Equal);
}

pub fn op_node_before(args: &Vec<XSequence>, eval_env: &EvalEnv) -> Result<XSequence, Box<Error>> {
    return op_node_compare(args, eval_env, Ordering::Less);
}

pub fn op_node_after(args: &Vec<XSequence>, eval_env: &EvalEnv) -> Result<XSequence, Box<Error>> {
    return op_node_compare(args, eval_env, Ordering::Greater);
}

fn op_node_compare(args: &Vec<XSequence>, eval_env: &EvalEnv,
                    ordering: Ordering) -> Result<XSequence, Box<Error>> {
    let node1 = args[0].get_singleton_node()?;
    let node2 = args[1].get_singleton_node()?;
    let result = eval_env.compare_by_doc_order(&node1, &node2);
    return Ok(new_singleton_boolean(result == ordering));
}

// ---------------------------------------------------------------------
// Functions and Operators on Sequences
//   (XPath 3.1 では演算子の項に載っていない)
//
// ---------------------------------------------------------------------
// op:concatenate
// op:concatenate($seq1 as item()*, $seq2 as item()*) as item()*
//
pub fn op_concatenate(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
    let mut result = new_xsequence();
    result.append(&args[0]);
    result.append(&args[1]);
    return Ok(result);
}

// ---------------------------------------------------------------------
// Equals, Union, Intersection and Except
//   (XPath 3.1 では演算子の項に載っていない)
//
pub fn op_union(args: &Vec<XSequence>, eval_env: &EvalEnv) -> Result<XSequence, Box<Error>> {
    let mut node_array: Vec<NodePtr> = vec!{};
    for n in args[0].to_nodeset().iter() {          // lhs
        node_array.push(n.rc_clone());
    }
    for n in args[1].to_nodeset().iter() {          // rhs
        node_array.push(n.rc_clone());
    }
    eval_env.sort_by_doc_order(&mut node_array);
    return Ok(new_xsequence_from_node_array(&node_array));
}

pub fn op_intersect(args: &Vec<XSequence>, _eval_env: &EvalEnv) -> Result<XSequence, Box<Error>> {
    let mut node_array: Vec<NodePtr> = vec!{};
    let rhs = args[1].to_nodeset();
    for n in args[0].to_nodeset().iter() {          // lhs
        if rhs.contains(&n) {
            node_array.push(n.rc_clone());
        }
    }
    // eval_env.sort_by_doc_order(&mut node_array);
    return Ok(new_xsequence_from_node_array(&node_array));
}

pub fn op_except(args: &Vec<XSequence>, _eval_env: &EvalEnv) -> Result<XSequence, Box<Error>> {
    let mut node_array: Vec<NodePtr> = vec!{};
    let rhs = args[1].to_nodeset();
    for n in args[0].to_nodeset().iter() {          // lhs
        if ! rhs.contains(&n) {
            node_array.push(n.rc_clone());
        }
    }
    // eval_env.sort_by_doc_order(&mut node_array);
    return Ok(new_xsequence_from_node_array(&node_array));
}

// ---------------------------------------------------------------------
// Functions and Operators that Generate Sequences
//          to
//   (XPath 3.1 では演算子の項に載っていない)
//
pub fn op_to(args: &Vec<XSequence>) -> Result<XSequence, Box<Error>> {
    let firstval = args[0].get_singleton_integer()?;
    let lastval = args[1].get_singleton_integer()?;
    let mut seq = new_xsequence();
    for n in firstval ..= lastval {
        seq.push(&new_xitem_integer(n));
    }
    return Ok(seq);
}

// =====================================================================
//
#[cfg(test)]
mod test {
//    use super::*;

    use xpath_impl::helpers::compress_spaces;
    use xpath_impl::helpers::subtest_xpath;
    use xpath_impl::helpers::subtest_eval_xpath;

    // -----------------------------------------------------------------
    // 6.2 Operators on Numeric Values
    // 加減乗 (優先度、左結合、型の昇格)
    //
    #[test]
    fn test_numeric_operators() {
        let xml = compress_spaces(r#"
<a base="base">
</a>
        "#);

        subtest_eval_xpath("numeric_operators", &xml, &[
            ( "10 - 3 - 4", "3" ),
            ( "10.5 - 3", "7.5" ),
            ( "10.5 - 3 - 1.5", "6.0" ),
            ( "1.05e1 - 3 - 1.5", "6e0" ),
            ( "10 - (3 - 4)", "11" ),
            ( "16 - 6 - 3 - 4", "3" ),
            ( "18 - 2 - 6 - 3 - 4", "3" ),
            ( "1 + 2 * 4 + 2", "11" ),
            ( "1 + 2 * 4 - 2", "7" ),
        ]);
    }

    // -----------------------------------------------------------------
    // div: op:numeric-divide
    //
    #[test]
    fn test_numeric_divide() {
        let xml = compress_spaces(r#"
<a base="base">
</a>
        "#);

        subtest_eval_xpath("numeric_divide", &xml, &[
            ( "6 div 2", "3.0" ),         // Integer div Integer => Decimal
            ( "5 div 2", "2.5" ),         // Integer div Integer => Decimal
            ( "5.0 div 2", "2.5" ),
            ( "9.6 div 2.4", "4.0" ),

            ( "7 div 0", "Dynamic Error" ),
            ( "-7 div 0", "Dynamic Error" ),
            ( "7.0 div 0", "Dynamic Error" ),
            ( "-7.0 div 0", "Dynamic Error" ),
            ( "7 div 0.0e0", "+Infinity" ),
            ( "-7 div 0.0e0", "-Infinity" ),
            ( "7.0e0 div 0.0e0", "+Infinity" ),
            ( "-7.0e0 div 0.0e0", "-Infinity" ),

            ( "0.0e0 div 0.0e0", "NaN" ),
            ( "0 div 0", "Dynamic Error" ),
        ]);
    }

    // -----------------------------------------------------------------
    // idiv: op:numeric-integer-divide
    //
    #[test]
    fn test_numeric_integer_divide() {
        let xml = compress_spaces(r#"
<a base="base">
</a>
        "#);

        subtest_eval_xpath("numeric_integer_divide", &xml, &[
            ( "10 idiv 3", "3" ),
            ( "3 idiv -2", "-1" ),
            ( "-3 idiv 2", "-1" ),
            ( "-3 idiv -2", "1" ),
            ( "9.0 idiv 3", "3" ),
            ( "-3.5 idiv 3", "-1" ),
            ( "3.0 idiv 4", "0" ),
            ( "3.1e1 idiv 6", "5" ),
            ( "3.1e1 idiv 7", "4" ),

            ( "7 idiv 0", "Dynamic Error" ),
            ( "7.0 idiv 0", "Dynamic Error" ),

            // XIDoubleの扱い: JavaやC++の実装とは違っている。
            ( "0.0e0 div 0.0e0", "NaN" ),
            ( "(0.0e0 div 0.0e0) idiv 5", "Dynamic Error" ), // NaN idiv any = Error
            ( "5 idiv (0.0e0 div 0.0e0)", "Dynamic Error" ), // any idiv NaN = Error
            ( "7.0e0 div 0.0e0", "+Infinity" ),
            ( "(7.0e0 div 0.0e0) idiv 5", "Dynamic Error" ),    // +∞ idiv N = Error
            ( "5 idiv (7.0e0 div 0.0e0)", "0" ),   // N idiv +∞ = 0
            ( "5 idiv (-7.0e0 div 0.0e0)", "0" ),  // N idiv -∞ = 0
            ( "0.0e0 idiv 5", "0" ),              // 0 idiv N = 0

        ]);
    }

    // -----------------------------------------------------------------
    // mod: op:numeric-mod
    //
    #[test]
    fn test_numeric_mod() {
        let xml = compress_spaces(r#"
<a base="base">
</a>
        "#);

        subtest_eval_xpath("numeric_mod", &xml, &[
            ( "10 mod 3", "1" ),
            ( "6 mod -2", "0" ),
            ( "5 mod 2", "1" ),
            ( "5 mod -2", "1" ),
            ( "-5 mod 2", "-1" ),
            ( "-5 mod -2", "-1" ),
            ( "7 mod 0", "Dynamic Error" ),
            ( "7.0 mod 0", "Dynamic Error" ),

            ( "3.5 mod 1.5", "0.5" ),
            ( "3.5 mod -1.5", "0.5" ),
            ( "-3.5 mod 1.5", "-0.5" ),
            ( "-3.5 mod -1.5", "-0.5" ),
            ( "4.5 mod 1.2", "0.9000000000000001" ),  // 0.9
// Decimalの精度???
            ( "1.23e2 mod 0.6e1", "3e0" ),            // 123 mod 6 = 3

            // XIDoubleの扱い:
            ( "0.0e0 div 0.0e0", "NaN" ),
            ( "(0.0e0 div 0.0e0) mod 5", "NaN" ), // NaN mod any = NaN
            ( "5 mod (0.0e0 div 0.0e0)", "NaN" ), // any mod NaN = NaN
            ( "7.0e0 div 0.0e0", "+Infinity" ),
            ( "5 mod (7.0e0 div 0.0e0)", "5e0" ),   // N mod +∞ = N
            ( "5 mod (-7.0e0 div 0.0e0)", "5e0" ),  // N mod -∞ = N
            ( "0.0e0 mod 5", "0e0" ),              // 0 mod N = 0
        ]);
    }

    // -----------------------------------------------------------------
    // (負のゼロ)
    //
    #[test]
    fn test_minus_zero() {
        let xml = compress_spaces(r#"
<a base="base">
</a>
        "#);

        subtest_eval_xpath("minus_zero", &xml, &[
            ( "round(-0.2)", "0.0" ),
            ( "round(0.2)", "0.0" ),
            ( "1.0 div round(-0.2)", "Dynamic Error" ),     // 負のゼロで除算
            ( "1.0 div round(0.2)", "Dynamic Error" ),      // 正のゼロで除算
            ( "1.0 div ceiling(-0.2e0)", "-Infinity" ),

            ( "0 = -0", "true" ),
            ( "0 != -0", "false" ),
            ( "0 > -0", "false" ),
            ( "0 = -0.0", "true" ),
            
            ( "1.0 div (-0e0)", "-Infinity" ),
            ( "1.0 div (- (4e0 - 4e0))", "-Infinity" ),
            ( "1.0 div -(-0e0)", "+Infinity" ),
        ]);
    }

    // -----------------------------------------------------------------
    // 14.6 op:is-same-node
    //
    #[test]
    fn test_op_is_same_node() {
        let xml = compress_spaces(r#"
<a base="base">
    <p id="A" img="A"/>
    <p id="B" img="B"/>
</a>
        "#);
        subtest_eval_xpath("op_is_same_node", &xml, &[
            ( r#"/a/p[@id="A"] is /a/p[@img="A"]"#, "true" ),
            ( r#"/a/p[@id="A"] is /a/p[@img="B"]"#, "false" ),
        ]);
    }

    // -----------------------------------------------------------------
    // 14.7 op:node-before
    //
    #[test]
    fn test_op_node_before() {
        let xml = compress_spaces(r#"
<a base="base">
    <p id="A"/>
    <p id="B"/>
</a>
        "#);
        subtest_eval_xpath("op_node_before", &xml, &[
            ( r#"/a/p[@id="A"] << /a/p[@id="B"]"#, "true" ),
            ( r#"/a/p[@id="B"] << /a/p[@id="A"]"#, "false" ),
        ]);
    }

    // -----------------------------------------------------------------
    // 14.8 op:node-after
    //
    #[test]
    fn test_op_node_after() {
        let xml = compress_spaces(r#"
<a base="base">
    <p id="A"/>
    <p id="B"/>
</a>
        "#);
        subtest_eval_xpath("op_node_after", &xml, &[
            ( r#"/a/p[@id="A"] >> /a/p[@id="B"]"#, "false" ),
            ( r#"/a/p[@id="B"] >> /a/p[@id="A"]"#, "true" ),
        ]);
    }

    // -----------------------------------------------------------------
    // 15.3.2 op:union
    //
    #[test]
    fn test_op_union() {
        let xml = compress_spaces(r#"
<a base="base">
    <left>
        <p img="LA">LA</p>
        <p img="LB">LB</p>
    </left>
    <right>
        <q img="RA">RA</q>
        <q img="RB">RB</q>
        <q img="RC">RC</q>
        <p img="RX">RX</p>
    </right>
    <sel img="T" ans="true" />
    <sel img="F" ans="false" />
</a>
        "#);
        subtest_xpath("op_union", &xml, false, &[
            ( "/a/sel[@ans = string(count(/a/left/p | /a/right/q) = 5)]", "T" ),
            ( "/a/left/p | /a/right/q", "LALBRARBRC" ),
            ( "/a/right/q | /a/left/p", "LALBRARBRC" ), // 文書順に整列
            ( "/a//q | /a/right/q", "RARBRC" ),         // 重複を除いて整列
            // ---------------------------------------------
            ( "(/a/left/p | /a/right/q)[3]", "RA" ),
            ( "(/a/right/q | /a/left/p)[3]", "RA" ), // 「RC」ではない
            // ---------------------------------------------
            ( "(/a/left | /a/right)/p", "LALBRX" ),
            ( "(/a/right | /a/left)/p", "LALBRX" ),
            ( "(/a/left | /a/right)//p", "LALBRX" ),
            ( "(/a/right | /a/left)//p", "LALBRX" ),
        ]);
    }

    // -----------------------------------------------------------------
    // 15.3.3 op:intersect
    //
    #[test]
    fn test_op_intersect() {
        let xml = compress_spaces(r#"
<a base="base">
    <p img="x11" a="1" b="1"/>
    <p img="x12" a="1" b="2"/>
    <p img="x13" a="1" b="3"/>
    <p img="x21" a="2" b="1"/>
    <p img="x22" a="2" b="2"/>
    <p img="x23" a="2" b="3"/>
    <p img="x31" a="3" b="1"/>
    <p img="x32" a="3" b="2"/>
    <p img="x33" a="3" b="3"/>
</a>
        "#);
        subtest_xpath("op_intersect", &xml, false, &[
            ( r#"/a/p[@a="1"] intersect /a/p[@b="1"]"#, "x11" ),
            ( r#"/a/p[@a>="2"] intersect /a/p[@b>="2"]"#, "x22x23x32x33" ),
            ( r#"/a/p[@b>="2"] intersect /a/p[@a>="2"]"#, "x22x23x32x33" ),
        ]);
    }

    // -----------------------------------------------------------------
    // 15.3.4 op:except
    //
    #[test]
    fn test_op_except() {
        let xml = compress_spaces(r#"
<a base="base">
    <p img="x11" a="1" b="1"/>
    <p img="x12" a="1" b="2"/>
    <p img="x13" a="1" b="3"/>
    <p img="x21" a="2" b="1"/>
    <p img="x22" a="2" b="2"/>
    <p img="x23" a="2" b="3"/>
    <p img="x31" a="3" b="1"/>
    <p img="x32" a="3" b="2"/>
    <p img="x33" a="3" b="3"/>
</a>
        "#);
        subtest_xpath("op_except", &xml, false, &[
            ( r#"/a/p[@a="1"] except /a/p[@b="1"]"#, "x12x13" ),
        ]);
    }

    // -----------------------------------------------------------------
    // 15.5.1 op:to
    //
    #[test]
    fn test_op_to() {
        let xml = compress_spaces(r#"
<root base="base">
</root>
        "#);
        subtest_eval_xpath("op_to", &xml, &[
            ( "1 to 3", "(1, 2, 3)" ),
            ( "3 to 1", "()" ),
            ( "5 to 5", "5" ),
        ]);
    }

}