REC-xpath-19991116
114 KB
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>XML Path Language (XPath)</title>
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-REC">
<style type="text/css">code { font-family: monospace }</style>
</head>
<body>
<div class="head">
<a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/WWW/w3c_home" alt="W3C" height="48" width="72"></a>
<h1>XML Path Language (XPath)<br>Version 1.0</h1>
<h2>W3C Recommendation 16 November 1999</h2>
<dl>
<dt>This version:</dt>
<dd>
<a href="http://www.w3.org/TR/1999/REC-xpath-19991116">http://www.w3.org/TR/1999/REC-xpath-19991116</a>
<br>
(available in <a href="http://www.w3.org/TR/1999/REC-xpath-19991116.xml">XML</a> or
<a href="http://www.w3.org/TR/1999/REC-xpath-19991116.html">HTML</a>)
</dd>
<dt>Latest version:</dt>
<dd>
<a href="http://www.w3.org/TR/xpath">http://www.w3.org/TR/xpath</a>
<br>
</dd>
<dt>Previous versions:</dt>
<dd>
<a href="http://www.w3.org/TR/1999/PR-xpath-19991008">http://www.w3.org/TR/1999/PR-xpath-19991008</a>
<br>
<a href="http://www.w3.org/1999/08/WD-xpath-19990813">http://www.w3.org/1999/08/WD-xpath-19990813</a>
<br>
<a href="http://www.w3.org/1999/07/WD-xpath-19990709">http://www.w3.org/1999/07/WD-xpath-19990709</a>
<br>
<a href="http://www.w3.org/TR/1999/WD-xslt-19990421">http://www.w3.org/TR/1999/WD-xslt-19990421</a>
<br>
</dd>
<dt>Editors:</dt>
<dd>
James Clark
<a href="mailto:jjc@jclark.com"><jjc@jclark.com></a>
<br>
Steve DeRose
(Inso Corp. and Brown University)
<a href="mailto:Steven_DeRose@Brown.edu"><Steven_DeRose@Brown.edu></a>
<br>
</dd>
</dl>
<p class="copyright">
<a href="http://www.w3.org/Consortium/Legal/ipr-notice.html#Copyright">
Copyright</a> © 1999 <a href="http://www.w3.org">W3C</a><sup>®</sup>
(<a href="http://www.lcs.mit.edu">MIT</a>,
<a href="http://www.inria.fr/">INRIA</a>,
<a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C
<a href="http://www.w3.org/Consortium/Legal/ipr-notice.html#Legal_Disclaimer">liability</a>,
<a href="http://www.w3.org/Consortium/Legal/ipr-notice.html#W3C_Trademarks">trademark</a>,
<a href="http://www.w3.org/Consortium/Legal/copyright-documents.html">document use</a> and
<a href="http://www.w3.org/Consortium/Legal/copyright-software.html">software licensing</a> rules apply.
</p>
<hr title="Separator for header">
</div>
<h2>
<a name="abstract">Abstract</a>
</h2>
<p>XPath is a language for addressing parts of an XML
document, designed to be used by both XSLT and
XPointer.</p>
<h2>
<a name="status">Status of this document</a>
</h2>
<p>This document has been reviewed by W3C Members and other interested
parties and has been endorsed by the Director as a W3C <a href="http://www.w3.org/Consortium/Process/#RecsW3C">Recommendation</a>. It
is a stable document and may be used as reference material or cited as
a normative reference from other documents. W3C's role in making the
Recommendation is to draw attention to the specification and to
promote its widespread deployment. This enhances the functionality and
interoperability of the Web.</p>
<p>The list of known errors in this specification is available at
<a href="http://www.w3.org/1999/11/REC-xpath-19991116-errata">http://www.w3.org/1999/11/REC-xpath-19991116-errata</a>.</p>
<p>Comments on this specification may be sent to <a href="mailto:www-xpath-comments@w3.org">www-xpath-comments@w3.org</a>; <a href="http://lists.w3.org/Archives/Public/www-xpath-comments">archives</a>
of the comments are available.</p>
<p>The English version of this specification is the only normative
version. However, for translations of this document, see <a href="http://www.w3.org/Style/XSL/translations.html">http://www.w3.org/Style/XSL/translations.html</a>.</p>
<p>A list of current W3C Recommendations and other technical documents
can be found at <a href="http://www.w3.org/TR">http://www.w3.org/TR</a>.</p>
<p>This specification is joint work of the XSL Working Group and the
XML Linking Working Group and so is part of the <a href="http://www.w3.org/Style/Activity">W3C Style activity</a> and
of the <a href="http://www.w3.org/XML/Activity">W3C XML
activity</a>.</p>
<h2>
<a name="contents">Table of contents</a>
</h2>1 <a href="#section-Introduction">Introduction</a>
<br>2 <a href="#location-paths">Location Paths</a>
<br> 2.1 <a href="#section-Location-Steps">Location Steps</a>
<br> 2.2 <a href="#axes">Axes</a>
<br> 2.3 <a href="#node-tests">Node Tests</a>
<br> 2.4 <a href="#predicates">Predicates</a>
<br> 2.5 <a href="#path-abbrev">Abbreviated Syntax</a>
<br>3 <a href="#section-Expressions">Expressions</a>
<br> 3.1 <a href="#section-Basics">Basics</a>
<br> 3.2 <a href="#section-Function-Calls">Function Calls</a>
<br> 3.3 <a href="#node-sets">Node-sets</a>
<br> 3.4 <a href="#booleans">Booleans</a>
<br> 3.5 <a href="#numbers">Numbers</a>
<br> 3.6 <a href="#strings">Strings</a>
<br> 3.7 <a href="#exprlex">Lexical Structure</a>
<br>4 <a href="#corelib">Core Function Library</a>
<br> 4.1 <a href="#section-Node-Set-Functions">Node Set Functions</a>
<br> 4.2 <a href="#section-String-Functions">String Functions</a>
<br> 4.3 <a href="#section-Boolean-Functions">Boolean Functions</a>
<br> 4.4 <a href="#section-Number-Functions">Number Functions</a>
<br>5 <a href="#data-model">Data Model</a>
<br> 5.1 <a href="#root-node">Root Node</a>
<br> 5.2 <a href="#element-nodes">Element Nodes</a>
<br> 5.2.1 <a href="#unique-id">Unique IDs</a>
<br> 5.3 <a href="#attribute-nodes">Attribute Nodes</a>
<br> 5.4 <a href="#namespace-nodes">Namespace Nodes</a>
<br> 5.5 <a href="#section-Processing-Instruction-Nodes">Processing Instruction Nodes</a>
<br> 5.6 <a href="#section-Comment-Nodes">Comment Nodes</a>
<br> 5.7 <a href="#section-Text-Nodes">Text Nodes</a>
<br>6 <a href="#section-Conformance">Conformance</a>
<br>
<h3>Appendices</h3>A <a href="#section-References">References</a>
<br> A.1 <a href="#section-Normative-References">Normative References</a>
<br> A.2 <a href="#section-Other-References">Other References</a>
<br>B <a href="#infoset">XML Information Set Mapping</a> (Non-Normative)<br>
<hr>
<h2>
<a name="section-Introduction"></a>1 Introduction</h2>
<p>XPath is the result of an effort to provide a common syntax and
semantics for functionality shared between XSL Transformations <a href="#XSLT">[XSLT]</a> and XPointer <a href="#XPTR">[XPointer]</a>. The primary purpose
of XPath is to address parts of an XML <a href="#XML">[XML]</a> document.
In support of this primary purpose, it also provides basic facilities
for manipulation of strings, numbers and booleans. XPath uses a
compact, non-XML syntax to facilitate use of XPath within URIs and XML
attribute values. XPath operates on the abstract, logical structure
of an XML document, rather than its surface syntax. XPath gets its
name from its use of a path notation as in URLs for navigating through
the hierarchical structure of an XML document.</p>
<p>In addition to its use for addressing, XPath is also designed so
that it has a natural subset that can be used for matching (testing
whether or not a node matches a pattern); this use of XPath is
described in <a href="http://www.w3.org/TR/WD-xslt#patterns">XSLT</a>.</p>
<p>XPath models an XML document as a tree of nodes. There are
different types of nodes, including element nodes, attribute nodes and
text nodes. XPath defines a way to compute a <a href="#dt-string-value">string-value</a> for each type of node.
Some types of nodes also have names. XPath fully supports XML
Namespaces <a href="#XMLNAMES">[XML Names]</a>. Thus, the name of a node is
modeled as a pair consisting of a local part and a possibly null
namespace URI; this is called an <a href="#dt-expanded-name">expanded-name</a>. The data model is
described in detail in <a href="#data-model">[<b>5 Data Model</b>]</a>.</p>
<p>The primary syntactic construct in XPath is the expression. An
expression matches the production <a href="#NT-Expr">Expr</a>. An
expression is evaluated to yield an object, which has one of the
following four basic types:</p>
<ul>
<li>node-set (an unordered collection of nodes without duplicates)</li>
<li>boolean (true or false)</li>
<li>number (a floating-point number)</li>
<li>string (a sequence of UCS characters)</li>
</ul>
<p>Expression evaluation occurs with respect to a context. XSLT and
XPointer specify how the context is determined for XPath expressions
used in XSLT and XPointer respectively. The context consists of:</p>
<ul>
<li>a node (<a name="dt-context-node"></a>the
<b>context node</b>)</li>
<li>a pair of non-zero positive integers (<a name="dt-context-position"></a>the <b>context
position</b> and <a name="dt-context-size"></a>the <b>context size</b>)</li>
<li>a set of variable bindings</li>
<li>a function library</li>
<li>the set of namespace declarations in scope for the
expression</li>
</ul>
<p>The context position is always less than or equal to the
context size.</p>
<p>The variable bindings consist of a mapping from variable names to
variable values. The value of a variable is an object, which can be of
any of the types that are possible for the value of an expression,
and may also be of additional types not specified here.</p>
<p>The function library consists of a mapping from function names to
functions. Each function takes zero or more arguments and returns a
single result. This document defines a core function library that all
XPath implementations must support (see <a href="#corelib">[<b>4 Core Function Library</b>]</a>).
For a function in the core function library, arguments and result are
of the four basic types. Both XSLT and XPointer extend XPath by
defining additional functions; some of these functions operate on the
four basic types; others operate on additional data types defined by
XSLT and XPointer.</p>
<p>The namespace declarations consist of a mapping from prefixes to
namespace URIs.</p>
<p>The variable bindings, function library and namespace declarations
used to evaluate a subexpression are always the same as those used to
evaluate the containing expression. The context node, context
position, and context size used to evaluate a subexpression are
sometimes different from those used to evaluate the containing
expression. Several kinds of expressions change the context node; only
predicates change the context position and context size (see <a href="#predicates">[<b>2.4 Predicates</b>]</a>). When the evaluation of a kind of expression is
described, it will always be explicitly stated if the context node,
context position, and context size change for the evaluation of
subexpressions; if nothing is said about the context node, context
position, and context size, they remain unchanged for the
evaluation of subexpressions of that kind of expression.</p>
<p>XPath expressions often occur in XML attributes. The grammar
specified in this section applies to the attribute value after XML 1.0
normalization. So, for example, if the grammar uses the character
<code><</code>, this must not appear in the XML source as
<code><</code> but must be quoted according to XML 1.0 rules by,
for example, entering it as <code>&lt;</code>. Within expressions,
literal strings are delimited by single or double quotation marks,
which are also used to delimit XML attributes. To avoid a quotation
mark in an expression being interpreted by the XML processor as
terminating the attribute value the quotation mark can be entered as a
character reference (<code>&quot;</code> or
<code>&apos;</code>). Alternatively, the expression can use single
quotation marks if the XML attribute is delimited with double
quotation marks or vice-versa.</p>
<p>One important kind of expression is a location path. A location
path selects a set of nodes relative to the context node. The result
of evaluating an expression that is a location path is the node-set
containing the nodes selected by the location path. Location paths
can recursively contain expressions that are used to filter sets of
nodes. A location path matches the production <a href="#NT-LocationPath">LocationPath</a>.</p>
<p>In the following grammar, the non-terminals <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> and <a href="http://www.w3.org/TR/REC-xml-names#NT-NCName">NCName</a> are defined in <a href="#XMLNAMES">[XML Names]</a>, and <a href="http://www.w3.org/TR/REC-xml#NT-S">S</a> is defined in
<a href="#XML">[XML]</a>. The grammar uses the same EBNF notation as
<a href="#XML">[XML]</a> (except that grammar symbols always have initial
capital letters).</p>
<p>Expressions are parsed by first dividing the character string to be
parsed into tokens and then parsing the resulting sequence of tokens.
Whitespace can be freely used between tokens. The tokenization
process is described in <a href="#exprlex">[<b>3.7 Lexical Structure</b>]</a>.</p>
<h2>
<a name="location-paths"></a>2 Location Paths</h2>
<p>Although location paths are not the most general grammatical
construct in the language (a <a href="#NT-LocationPath">LocationPath</a> is a special case of an <a href="#NT-Expr">Expr</a>), they are the most important construct and
will therefore be described first.</p>
<p>Every location path can be expressed using a straightforward but
rather verbose syntax. There are also a number of syntactic
abbreviations that allow common cases to be expressed concisely. This
section will explain the semantics of location paths using the
unabbreviated syntax. The abbreviated syntax will then be explained
by showing how it expands into the unabbreviated syntax (see <a href="#path-abbrev">[<b>2.5 Abbreviated Syntax</b>]</a>).</p>
<p>Here are some examples of location paths using the unabbreviated
syntax:</p>
<ul>
<li>
<p>
<code>child::para</code> selects the
<code>para</code> element children of the context node</p>
</li>
<li>
<p>
<code>child::*</code> selects all element
children of the context node</p>
</li>
<li>
<p>
<code>child::text()</code> selects all text
node children of the context node</p>
</li>
<li>
<p>
<code>child::node()</code> selects all the
children of the context node, whatever their node type</p>
</li>
<li>
<p>
<code>attribute::name</code> selects the
<code>name</code> attribute of the context node</p>
</li>
<li>
<p>
<code>attribute::*</code> selects all the
attributes of the context node</p>
</li>
<li>
<p>
<code>descendant::para</code> selects the
<code>para</code> element descendants of the context node</p>
</li>
<li>
<p>
<code>ancestor::div</code> selects all <code>div</code>
ancestors of the context node</p>
</li>
<li>
<p>
<code>ancestor-or-self::div</code> selects the
<code>div</code> ancestors of the context node and, if the context node is a
<code>div</code> element, the context node as well</p>
</li>
<li>
<p>
<code>descendant-or-self::para</code> selects the
<code>para</code> element descendants of the context node and, if the context node is
a <code>para</code> element, the context node as well</p>
</li>
<li>
<p>
<code>self::para</code> selects the context node if it is a
<code>para</code> element, and otherwise selects nothing</p>
</li>
<li>
<p>
<code>child::chapter/descendant::para</code>
selects the <code>para</code> element descendants of the
<code>chapter</code> element children of the context node</p>
</li>
<li>
<p>
<code>child::*/child::para</code> selects
all <code>para</code> grandchildren of the context node</p>
</li>
<li>
<p>
<code>/</code> selects the document root (which is
always the parent of the document element)</p>
</li>
<li>
<p>
<code>/descendant::para</code> selects all the
<code>para</code> elements in the same document as the context node</p>
</li>
<li>
<p>
<code>/descendant::olist/child::item</code> selects all the
<code>item</code> elements that have an <code>olist</code> parent and
that are in the same document as the context node</p>
</li>
<li>
<p>
<code>child::para[position()=1]</code> selects the first
<code>para</code> child of the context node</p>
</li>
<li>
<p>
<code>child::para[position()=last()]</code> selects the last
<code>para</code> child of the context node</p>
</li>
<li>
<p>
<code>child::para[position()=last()-1]</code> selects
the last but one <code>para</code> child of the context node</p>
</li>
<li>
<p>
<code>child::para[position()>1]</code> selects all
the <code>para</code> children of the context node other than the
first <code>para</code> child of the context node</p>
</li>
<li>
<p>
<code>following-sibling::chapter[position()=1]</code>
selects the next <code>chapter</code> sibling of the context node</p>
</li>
<li>
<p>
<code>preceding-sibling::chapter[position()=1]</code>
selects the previous <code>chapter</code> sibling of the context
node</p>
</li>
<li>
<p>
<code>/descendant::figure[position()=42]</code> selects
the forty-second <code>figure</code> element in the
document</p>
</li>
<li>
<p>
<code>/child::doc/child::chapter[position()=5]/child::section[position()=2]</code>
selects the second <code>section</code> of the fifth
<code>chapter</code> of the <code>doc</code> document
element</p>
</li>
<li>
<p>
<code>child::para[attribute::type="warning"]</code>
selects all <code>para</code> children of the context node that have a
<code>type</code> attribute with value <code>warning</code>
</p>
</li>
<li>
<p>
<code>child::para[attribute::type='warning'][position()=5]</code>
selects the fifth <code>para</code> child of the context node that has
a <code>type</code> attribute with value
<code>warning</code>
</p>
</li>
<li>
<p>
<code>child::para[position()=5][attribute::type="warning"]</code>
selects the fifth <code>para</code> child of the context node if that
child has a <code>type</code> attribute with value
<code>warning</code>
</p>
</li>
<li>
<p>
<code>child::chapter[child::title='Introduction']</code>
selects the <code>chapter</code> children of the context node that
have one or more <code>title</code> children with <a href="#dt-string-value">string-value</a> equal to
<code>Introduction</code>
</p>
</li>
<li>
<p>
<code>child::chapter[child::title]</code> selects the
<code>chapter</code> children of the context node that have one or
more <code>title</code> children</p>
</li>
<li>
<p>
<code>child::*[self::chapter or self::appendix]</code>
selects the <code>chapter</code> and <code>appendix</code> children of
the context node</p>
</li>
<li>
<p>
<code>child::*[self::chapter or
self::appendix][position()=last()]</code> selects the last
<code>chapter</code> or <code>appendix</code> child of the context
node</p>
</li>
</ul>
<p>There are two kinds of location path: relative location paths
and absolute location paths.</p>
<p>A relative location path consists of a sequence of one or more
location steps separated by <code>/</code>. The steps in a relative
location path are composed together from left to right. Each step in
turn selects a set of nodes relative to a context node. An initial
sequence of steps is composed together with a following step as
follows. The initial sequence of steps selects a set of nodes
relative to a context node. Each node in that set is used as a
context node for the following step. The sets of nodes identified by
that step are unioned together. The set of nodes identified by
the composition of the steps is this union. For example,
<code>child::div/child::para</code> selects the
<code>para</code> element children of the <code>div</code> element
children of the context node, or, in other words, the
<code>para</code> element grandchildren that have <code>div</code>
parents.</p>
<p>An absolute location path consists of <code>/</code> optionally
followed by a relative location path. A <code>/</code> by itself
selects the root node of the document containing the context node. If
it is followed by a relative location path, then the location path
selects the set of nodes that would be selected by the relative
location path relative to the root node of the document containing the
context node.</p>
<h5>Location Paths</h5>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-LocationPath"></a>[1] </td><td>LocationPath</td><td> ::= </td><td><a href="#NT-RelativeLocationPath">RelativeLocationPath</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-AbsoluteLocationPath">AbsoluteLocationPath</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-AbsoluteLocationPath"></a>[2] </td><td>AbsoluteLocationPath</td><td> ::= </td><td>'/' <a href="#NT-RelativeLocationPath">RelativeLocationPath</a>?</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-AbbreviatedAbsoluteLocationPath">AbbreviatedAbsoluteLocationPath</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-RelativeLocationPath"></a>[3] </td><td>RelativeLocationPath</td><td> ::= </td><td><a href="#NT-Step">Step</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-RelativeLocationPath">RelativeLocationPath</a> '/' <a href="#NT-Step">Step</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-AbbreviatedRelativeLocationPath">AbbreviatedRelativeLocationPath</a></td><td></td>
</tr>
</tbody>
</table>
<h3>
<a name="section-Location-Steps"></a>2.1 Location Steps</h3>
<p>A location step has three parts:</p>
<ul>
<li>
<p>an axis, which specifies the tree relationship between the
nodes selected by the location step and the context node,</p>
</li>
<li>
<p>a node test, which specifies the node type and <a href="#dt-expanded-name">expanded-name</a> of the nodes selected
by the location step, and</p>
</li>
<li>
<p>zero or more predicates, which use arbitrary expressions to
further refine the set of nodes selected by the location
step.</p>
</li>
</ul>
<p>The syntax for a location step is the axis name and node test
separated by a double colon, followed by zero or more expressions each
in square brackets. For example, in
<code>child::para[position()=1]</code>, <code>child</code> is the name
of the axis, <code>para</code> is the node test and
<code>[position()=1]</code> is a predicate.</p>
<p>The node-set selected by the location step is the node-set that
results from generating an initial node-set from the axis and
node-test, and then filtering that node-set by each of the predicates
in turn.</p>
<p>The initial node-set consists of the nodes having the relationship
to the context node specified by the axis, and having the node type
and <a href="#dt-expanded-name">expanded-name</a> specified
by the node test. For example, a location step
<code>descendant::para</code> selects the <code>para</code> element
descendants of the context node: <code>descendant</code> specifies
that each node in the initial node-set must be a descendant of the
context; <code>para</code> specifies that each node in the initial
node-set must be an element named <code>para</code>. The available
axes are described in <a href="#axes">[<b>2.2 Axes</b>]</a>. The available node tests
are described in <a href="#node-tests">[<b>2.3 Node Tests</b>]</a>. The meaning of some
node tests is dependent on the axis.</p>
<p>The initial node-set is filtered by the first predicate to generate
a new node-set; this new node-set is then filtered using the second
predicate, and so on. The final node-set is the node-set selected by
the location step. The axis affects how the expression in each
predicate is evaluated and so the semantics of a predicate is defined
with respect to an axis. See <a href="#predicates">[<b>2.4 Predicates</b>]</a>.</p>
<h5>Location Steps</h5>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-Step"></a>[4] </td><td>Step</td><td> ::= </td><td><a href="#NT-AxisSpecifier">AxisSpecifier</a>
<a href="#NT-NodeTest">NodeTest</a>
<a href="#NT-Predicate">Predicate</a>*</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-AbbreviatedStep">AbbreviatedStep</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-AxisSpecifier"></a>[5] </td><td>AxisSpecifier</td><td> ::= </td><td><a href="#NT-AxisName">AxisName</a> '::'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-AbbreviatedAxisSpecifier">AbbreviatedAxisSpecifier</a>
</td><td></td>
</tr>
</tbody>
</table>
<h3>
<a name="axes"></a>2.2 Axes</h3>
<p>The following axes are available:</p>
<ul>
<li>
<p>the <code>child</code> axis contains the children of the
context node</p>
</li>
<li>
<p>the <code>descendant</code> axis contains the descendants of
the context node; a descendant is a child or a child of a child and so
on; thus the descendant axis never contains attribute or namespace
nodes</p>
</li>
<li>
<p>the <code>parent</code> axis contains the <a href="#dt-parent">parent</a> of the context node, if there is
one</p>
</li>
<li>
<p>the <code>ancestor</code> axis contains the ancestors of the
context node; the ancestors of the context node consist of the
<a href="#dt-parent">parent</a> of context node and the
parent's parent and so on; thus, the ancestor axis will always include
the root node, unless the context node is the root node</p>
</li>
<li>
<p>the <code>following-sibling</code> axis contains all the
following siblings of the context node; if the
context node is an attribute node or namespace node, the
<code>following-sibling</code> axis is empty</p>
</li>
<li>
<p>the <code>preceding-sibling</code> axis contains all the
preceding siblings of the context node; if the context node is an
attribute node or namespace node, the <code>preceding-sibling</code>
axis is empty</p>
</li>
<li>
<p>the <code>following</code> axis contains all nodes in the
same document as the context node that are after the context node in
document order, excluding any descendants and excluding attribute
nodes and namespace nodes</p>
</li>
<li>
<p>the <code>preceding</code> axis contains all nodes in the
same document as the context node that are before the context node in
document order, excluding any ancestors and excluding attribute nodes
and namespace nodes</p>
</li>
<li>
<p>the <code>attribute</code> axis contains the attributes of
the context node; the axis will be empty unless the context node is an
element</p>
</li>
<li>
<p>the <code>namespace</code> axis contains the namespace nodes
of the context node; the axis will be empty unless the context node
is an element</p>
</li>
<li>
<p>the <code>self</code> axis contains just the context node
itself</p>
</li>
<li>
<p>the <code>descendant-or-self</code> axis contains the context
node and the descendants of the context node</p>
</li>
<li>
<p>the <code>ancestor-or-self</code> axis contains the context
node and the ancestors of the context node; thus, the ancestor axis
will always include the root node</p>
</li>
</ul>
<blockquote>
<b>NOTE: </b>The <code>ancestor</code>, <code>descendant</code>,
<code>following</code>, <code>preceding</code> and <code>self</code>
axes partition a document (ignoring attribute and namespace nodes):
they do not overlap and together they contain all the nodes in the
document.</blockquote>
<h5>Axes</h5>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-AxisName"></a>[6] </td><td>AxisName</td><td> ::= </td><td>'ancestor'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'ancestor-or-self'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'attribute'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'child'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'descendant'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'descendant-or-self'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'following'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'following-sibling'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'namespace'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'parent'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'preceding'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'preceding-sibling'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'self'</td><td></td>
</tr>
</tbody>
</table>
<h3>
<a name="node-tests"></a>2.3 Node Tests</h3>
<p>
<a name="dt-principal-node-type"></a>Every axis has a <b>principal node type</b>. If an axis
can contain elements, then the principal node type is element;
otherwise, it is the type of the nodes that the axis can
contain. Thus,</p>
<ul>
<li>For the attribute axis, the principal node type is attribute.</li>
<li>For the namespace axis, the principal node type is namespace.</li>
<li>For other axes, the principal node type is element.</li>
</ul>
<p>A node test that is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>
is true if and only if the type of the node (see <a href="#data-model">[<b>5 Data Model</b>]</a>)
is the principal node type and has
an <a href="#dt-expanded-name">expanded-name</a> equal to
the <a href="#dt-expanded-name">expanded-name</a> specified
by the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>. For example,
<code>child::para</code> selects the <code>para</code> element
children of the context node; if the context node has no
<code>para</code> children, it will select an empty set of nodes.
<code>attribute::href</code> selects the <code>href</code> attribute
of the context node; if the context node has no <code>href</code>
attribute, it will select an empty set of nodes.</p>
<p>A <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> in the node test is
expanded into an <a href="#dt-expanded-name">expanded-name</a> using the namespace
declarations from the expression context. This is the same way
expansion is done for element type names in start and end-tags except
that the default namespace declared with <code>xmlns</code> is not
used: if the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> does not have
a prefix, then the namespace URI is null (this is the same way
attribute names are expanded). It is an error if the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> has a prefix for which there is
no namespace declaration in the expression context.</p>
<p>A node test <code>*</code> is true for any node of the principal
node type. For example, <code>child::*</code> will select all element
children of the context node, and <code>attribute::*</code> will
select all attributes of the context node.</p>
<p>A node test can have the form <a href="http://www.w3.org/TR/REC-xml-names#NT-NCName">NCName</a><code>:*</code>. In this
case, the prefix is expanded in the same way as with a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, using the context namespace
declarations. It is an error if there is no namespace declaration for
the prefix in the expression context. The node test will be true for
any node of the principal type whose <a href="#dt-expanded-name">expanded-name</a> has the namespace URI
to which the prefix expands, regardless of the local part of the
name.</p>
<p>The node test <code>text()</code> is true for any text node. For
example, <code>child::text()</code> will select the text node
children of the context node. Similarly, the node test
<code>comment()</code> is true for any comment node, and the node test
<code>processing-instruction()</code> is true for any processing
instruction. The <code>processing-instruction()</code> test may have
an argument that is <a href="#NT-Literal">Literal</a>; in this case, it
is true for any processing instruction that has a name equal to the
value of the <a href="#NT-Literal">Literal</a>.</p>
<p>A node test <code>node()</code> is true for any node of any type
whatsoever.</p>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-NodeTest"></a>[7] </td><td>NodeTest</td><td> ::= </td><td><a href="#NT-NameTest">NameTest</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-NodeType">NodeType</a> '(' ')'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'processing-instruction' '(' <a href="#NT-Literal">Literal</a> ')'</td><td></td>
</tr>
</tbody>
</table>
<h3>
<a name="predicates"></a>2.4 Predicates</h3>
<p>An axis is either a forward axis or a reverse axis. An axis that
only ever contains the context node or nodes that are after the
context node in <a href="#dt-document-order">document
order</a> is a forward axis. An axis that only ever contains
the context node or nodes that are before the context node in <a href="#dt-document-order">document order</a> is a reverse axis.
Thus, the ancestor, ancestor-or-self, preceding, and preceding-sibling
axes are reverse axes; all other axes are forward axes. Since the self
axis always contains at most one node, it makes no difference whether
it is a forward or reverse axis. <a name="dt-proximity-position"></a>The <b>proximity position</b> of a
member of a node-set with respect to an axis is defined to be the
position of the node in the node-set ordered in document order if the
axis is a forward axis and ordered in reverse document order if the
axis is a reverse axis. The first position is 1.</p>
<p>A predicate filters a node-set with respect to an axis to produce a
new node-set. For each node in the node-set to be filtered, the <a href="#NT-PredicateExpr">PredicateExpr</a> is evaluated with that node
as the context node, with the number of nodes in the node-set as the
context size, and with the <a href="#dt-proximity-position">proximity position</a> of the node
in the node-set with respect to the axis as the context position; if
<a href="#NT-PredicateExpr">PredicateExpr</a> evaluates to true for
that node, the node is included in the new node-set; otherwise, it is
not included.</p>
<p>A <a href="#NT-PredicateExpr">PredicateExpr</a> is evaluated by
evaluating the <a href="#NT-Expr">Expr</a> and converting the result
to a boolean. If the result is a number, the result will be converted
to true if the number is equal to the context position and will be
converted to false otherwise; if the result is not a number, then the
result will be converted as if by a call to the
<b><a href="#function-boolean">boolean</a></b> function. Thus a location path
<code>para[3]</code> is equivalent to
<code>para[position()=3]</code>.</p>
<h5>Predicates</h5>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-Predicate"></a>[8] </td><td>Predicate</td><td> ::= </td><td>'[' <a href="#NT-PredicateExpr">PredicateExpr</a> ']'</td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-PredicateExpr"></a>[9] </td><td>PredicateExpr</td><td> ::= </td><td><a href="#NT-Expr">Expr</a></td><td></td>
</tr>
</tbody>
</table>
<h3>
<a name="path-abbrev"></a>2.5 Abbreviated Syntax</h3>
<p>Here are some examples of location paths using abbreviated
syntax:</p>
<ul>
<li>
<p>
<code>para</code> selects the <code>para</code> element children of
the context node</p>
</li>
<li>
<p>
<code>*</code> selects all element children of the
context node</p>
</li>
<li>
<p>
<code>text()</code> selects all text node children of the
context node</p>
</li>
<li>
<p>
<code>@name</code> selects the <code>name</code> attribute of
the context node</p>
</li>
<li>
<p>
<code>@*</code> selects all the attributes of the
context node</p>
</li>
<li>
<p>
<code>para[1]</code> selects the first <code>para</code> child of
the context node</p>
</li>
<li>
<p>
<code>para[last()]</code> selects the last <code>para</code> child
of the context node</p>
</li>
<li>
<p>
<code>*/para</code> selects all <code>para</code> grandchildren of
the context node</p>
</li>
<li>
<p>
<code>/doc/chapter[5]/section[2]</code> selects the second
<code>section</code> of the fifth <code>chapter</code> of the
<code>doc</code>
</p>
</li>
<li>
<p>
<code>chapter//para</code> selects the <code>para</code> element
descendants of the <code>chapter</code> element children of the
context node</p>
</li>
<li>
<p>
<code>//para</code> selects all the <code>para</code> descendants of
the document root and thus selects all <code>para</code> elements in the
same document as the context node</p>
</li>
<li>
<p>
<code>//olist/item</code> selects all the <code>item</code>
elements in the same document as the context node that have an
<code>olist</code> parent</p>
</li>
<li>
<p>
<code>.</code> selects the context node</p>
</li>
<li>
<p>
<code>.//para</code> selects the <code>para</code> element
descendants of the context node</p>
</li>
<li>
<p>
<code>..</code> selects the parent of the context node</p>
</li>
<li>
<p>
<code>../@lang</code> selects the <code>lang</code> attribute
of the parent of the context node</p>
</li>
<li>
<p>
<code>para[@type="warning"]</code> selects all <code>para</code>
children of the context node that have a <code>type</code> attribute with
value <code>warning</code>
</p>
</li>
<li>
<p>
<code>para[@type="warning"][5]</code> selects the fifth
<code>para</code> child of the context node that has a <code>type</code>
attribute with value <code>warning</code>
</p>
</li>
<li>
<p>
<code>para[5][@type="warning"]</code> selects the fifth
<code>para</code> child of the context node if that child has a
<code>type</code> attribute with value <code>warning</code>
</p>
</li>
<li>
<p>
<code>chapter[title="Introduction"]</code> selects the
<code>chapter</code> children of the context node that have one or
more <code>title</code> children with <a href="#dt-string-value">string-value</a> equal to
<code>Introduction</code>
</p>
</li>
<li>
<p>
<code>chapter[title]</code> selects the <code>chapter</code>
children of the context node that have one or more <code>title</code>
children</p>
</li>
<li>
<p>
<code>employee[@secretary and @assistant]</code> selects all
the <code>employee</code> children of the context node that have both a
<code>secretary</code> attribute and an <code>assistant</code>
attribute</p>
</li>
</ul>
<p>The most important abbreviation is that <code>child::</code> can be
omitted from a location step. In effect, <code>child</code> is the
default axis. For example, a location path <code>div/para</code> is
short for <code>child::div/child::para</code>.</p>
<p>There is also an abbreviation for attributes:
<code>attribute::</code> can be abbreviated to <code>@</code>. For
example, a location path <code>para[@type="warning"]</code> is short
for <code>child::para[attribute::type="warning"]</code> and so selects
<code>para</code> children with a <code>type</code> attribute with
value equal to <code>warning</code>.</p>
<p>
<code>//</code> is short for
<code>/descendant-or-self::node()/</code>. For example,
<code>//para</code> is short for
<code>/descendant-or-self::node()/child::para</code> and so will
select any <code>para</code> element in the document (even a
<code>para</code> element that is a document element will be selected
by <code>//para</code> since the document element node is a child of
the root node); <code>div//para</code> is short for
<code>div/descendant-or-self::node()/child::para</code> and so
will select all <code>para</code> descendants of <code>div</code>
children.</p>
<blockquote>
<b>NOTE: </b>The location path <code>//para[1]</code> does
<i>not</i> mean the same as the location path
<code>/descendant::para[1]</code>. The latter selects the first
descendant <code>para</code> element; the former selects all descendant
<code>para</code> elements that are the first <code>para</code>
children of their parents.</blockquote>
<p>A location step of <code>.</code> is short for
<code>self::node()</code>. This is particularly useful in
conjunction with <code>//</code>. For example, the location path
<code>.//para</code> is short for</p>
<pre>self::node()/descendant-or-self::node()/child::para</pre>
<p>and so will select all <code>para</code> descendant elements of the
context node.</p>
<p>Similarly, a location step of <code>..</code> is short for
<code>parent::node()</code>. For example, <code>../title</code> is
short for <code>parent::node()/child::title</code> and so will
select the <code>title</code> children of the parent of the context
node.</p>
<h5>Abbreviations</h5>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-AbbreviatedAbsoluteLocationPath"></a>[10] </td><td>AbbreviatedAbsoluteLocationPath</td><td> ::= </td><td>'//' <a href="#NT-RelativeLocationPath">RelativeLocationPath</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-AbbreviatedRelativeLocationPath"></a>[11] </td><td>AbbreviatedRelativeLocationPath</td><td> ::= </td><td><a href="#NT-RelativeLocationPath">RelativeLocationPath</a> '//' <a href="#NT-Step">Step</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-AbbreviatedStep"></a>[12] </td><td>AbbreviatedStep</td><td> ::= </td><td>'.'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| '..'</td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-AbbreviatedAxisSpecifier"></a>[13] </td><td>AbbreviatedAxisSpecifier</td><td> ::= </td><td>'@'?</td><td></td>
</tr>
</tbody>
</table>
<h2>
<a name="section-Expressions"></a>3 Expressions</h2>
<h3>
<a name="section-Basics"></a>3.1 Basics</h3>
<p>A <a href="#NT-VariableReference">VariableReference</a> evaluates
to the value to which the variable name is bound in the set of
variable bindings in the context. It is an error if the variable name
is not bound to any value in the set of variable bindings in the
expression context.</p>
<p>Parentheses may be used for grouping.</p>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-Expr"></a>[14] </td><td>Expr</td><td> ::= </td><td><a href="#NT-OrExpr">OrExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-PrimaryExpr"></a>[15] </td><td>PrimaryExpr</td><td> ::= </td><td><a href="#NT-VariableReference">VariableReference</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| '(' <a href="#NT-Expr">Expr</a> ')'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-Literal">Literal</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-Number">Number</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-FunctionCall">FunctionCall</a></td><td></td>
</tr>
</tbody>
</table>
<h3>
<a name="section-Function-Calls"></a>3.2 Function Calls</h3>
<p>A <a href="#NT-FunctionCall">FunctionCall</a> expression is
evaluated by using the <a href="#NT-FunctionName">FunctionName</a> to
identify a function in the expression evaluation context function
library, evaluating each of the <a href="#NT-Argument">Argument</a>s,
converting each argument to the type required by the function, and
finally calling the function, passing it the converted arguments. It
is an error if the number of arguments is wrong or if an argument
cannot be converted to the required type. The result of the <a href="#NT-FunctionCall">FunctionCall</a> expression is the result
returned by the function.</p>
<p>An argument is converted to type string as if by calling the
<b><a href="#function-string">string</a></b> function. An argument is converted to
type number as if by calling the <b><a href="#function-number">number</a></b> function.
An argument is converted to type boolean as if by calling the
<b><a href="#function-boolean">boolean</a></b> function. An argument that is not of
type node-set cannot be converted to a node-set.</p>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-FunctionCall"></a>[16] </td><td>FunctionCall</td><td> ::= </td><td><a href="#NT-FunctionName">FunctionName</a> '(' ( <a href="#NT-Argument">Argument</a> ( ',' <a href="#NT-Argument">Argument</a> )* )? ')'</td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-Argument"></a>[17] </td><td>Argument</td><td> ::= </td><td><a href="#NT-Expr">Expr</a></td><td></td>
</tr>
</tbody>
</table>
<h3>
<a name="node-sets"></a>3.3 Node-sets</h3>
<p>A location path can be used as an expression. The expression
returns the set of nodes selected by the path.</p>
<p>The <code>|</code> operator computes the union of its operands,
which must be node-sets.</p>
<p>
<a href="#NT-Predicate">Predicate</a>s are used to filter
expressions in the same way that they are used in location paths. It
is an error if the expression to be filtered does not evaluate to a
node-set. The <a href="#NT-Predicate">Predicate</a> filters the
node-set with respect to the child axis.</p>
<blockquote>
<b>NOTE: </b>The meaning of a <a href="#NT-Predicate">Predicate</a>
depends crucially on which axis applies. For example,
<code>preceding::foo[1]</code> returns the first <code>foo</code>
element in <i>reverse document order</i>, because the axis that
applies to the <code>[1]</code> predicate is the preceding axis; by
contrast, <code>(preceding::foo)[1]</code> returns the first
<code>foo</code> element in <i>document order</i>, because the
axis that applies to the <code>[1]</code> predicate is the child
axis.</blockquote>
<p>The <code>/</code> and <code>//</code> operators compose an
expression and a relative location path. It is an error if the
expression does not evaluate to a node-set. The <code>/</code>
operator does composition in the same way as when <code>/</code> is
used in a location path. As in location paths, <code>//</code> is
short for <code>/descendant-or-self::node()/</code>.</p>
<p>There are no types of objects that can be converted to node-sets.</p>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-UnionExpr"></a>[18] </td><td>UnionExpr</td><td> ::= </td><td><a href="#NT-PathExpr">PathExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-UnionExpr">UnionExpr</a> '|' <a href="#NT-PathExpr">PathExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-PathExpr"></a>[19] </td><td>PathExpr</td><td> ::= </td><td><a href="#NT-LocationPath">LocationPath</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-FilterExpr">FilterExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-FilterExpr">FilterExpr</a> '/' <a href="#NT-RelativeLocationPath">RelativeLocationPath</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-FilterExpr">FilterExpr</a> '//' <a href="#NT-RelativeLocationPath">RelativeLocationPath</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-FilterExpr"></a>[20] </td><td>FilterExpr</td><td> ::= </td><td><a href="#NT-PrimaryExpr">PrimaryExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-FilterExpr">FilterExpr</a> <a href="#NT-Predicate">Predicate</a></td><td></td>
</tr>
</tbody>
</table>
<h3>
<a name="booleans"></a>3.4 Booleans</h3>
<p>An object of type boolean can have one of two values, true and
false.</p>
<p>An <code>or</code> expression is evaluated by evaluating each
operand and converting its value to a boolean as if by a call to the
<b><a href="#function-boolean">boolean</a></b> function. The result is true if either
value is true and false otherwise. The right operand is not evaluated
if the left operand evaluates to true.</p>
<p>An <code>and</code> expression is evaluated by evaluating each
operand and converting its value to a boolean as if by a call to the
<b><a href="#function-boolean">boolean</a></b> function. The result is true if both
values are true and false otherwise. The right operand is not
evaluated if the left operand evaluates to false.</p>
<p>An <a href="#NT-EqualityExpr">EqualityExpr</a> (that is not just
a <a href="#NT-RelationalExpr">RelationalExpr</a>) or a <a href="#NT-RelationalExpr">RelationalExpr</a> (that is not just an <a href="#NT-AdditiveExpr">AdditiveExpr</a>) is evaluated by comparing the
objects that result from evaluating the two operands. Comparison of
the resulting objects is defined in the following three paragraphs.
First, comparisons that involve node-sets are defined in terms of
comparisons that do not involve node-sets; this is defined uniformly
for <code>=</code>, <code>!=</code>, <code><=</code>,
<code><</code>, <code>>=</code> and <code>></code>. Second,
comparisons that do not involve node-sets are defined for
<code>=</code> and <code>!=</code>. Third, comparisons that do not
involve node-sets are defined for <code><=</code>,
<code><</code>, <code>>=</code> and <code>></code>.</p>
<p>If both objects to be compared are node-sets, then the comparison
will be true if and only if there is a node in the first node-set and
a node in the second node-set such that the result of performing the
comparison on the <a href="#dt-string-value">string-value</a>s of the two nodes is
true. If one object to be compared is a node-set and the other is a
number, then the comparison will be true if and only if there is a
node in the node-set such that the result of performing the comparison
on the number to be compared and on the result of converting the
<a href="#dt-string-value">string-value</a> of that node to
a number using the <b><a href="#function-number">number</a></b> function is true. If
one object to be compared is a node-set and the other is a string,
then the comparison will be true if and only if there is a node in the
node-set such that the result of performing the comparison on the
<a href="#dt-string-value">string-value</a> of the node and
the other string is true. If one object to be compared is a node-set
and the other is a boolean, then the comparison will be true if and
only if the result of performing the comparison on the boolean and on
the result of converting the node-set to a boolean using the
<b><a href="#function-boolean">boolean</a></b> function is true.</p>
<p>When neither object to be compared is a node-set and the operator
is <code>=</code> or <code>!=</code>, then the objects are compared by
converting them to a common type as follows and then comparing them.
If at least one object to be compared is a boolean, then each object
to be compared is converted to a boolean as if by applying the
<b><a href="#function-boolean">boolean</a></b> function. Otherwise, if at least one
object to be compared is a number, then each object to be compared is
converted to a number as if by applying the
<b><a href="#function-number">number</a></b> function. Otherwise, both objects to be
compared are converted to strings as if by applying the
<b><a href="#function-string">string</a></b> function. The <code>=</code> comparison
will be true if and only if the objects are equal; the <code>!=</code>
comparison will be true if and only if the objects are not equal.
Numbers are compared for equality according to IEEE 754 <a href="#IEEE754">[IEEE 754]</a>. Two booleans are equal if either both are true or
both are false. Two strings are equal if and only if they consist of
the same sequence of UCS characters.</p>
<blockquote>
<b>NOTE: </b>If <code>$x</code> is bound to a node-set, then
<code>$x="foo"</code> does not mean the same as
<code>not($x!="foo")</code>: the former is true if and only if
<i>some</i> node in <code>$x</code> has the string-value
<code>foo</code>; the latter is true if and only if <i>all</i>
nodes in <code>$x</code> have the string-value
<code>foo</code>.</blockquote>
<p>When neither object to be compared is a node-set and the operator
is <code><=</code>, <code><</code>, <code>>=</code> or
<code>></code>, then the objects are compared by converting both
objects to numbers and comparing the numbers according to IEEE 754.
The <code><</code> comparison will be true if and only if the first
number is less than the second number. The <code><=</code>
comparison will be true if and only if the first number is less than
or equal to the second number. The <code>></code> comparison will
be true if and only if the first number is greater than the second
number. The <code>>=</code> comparison will be true if and only if
the first number is greater than or equal to the second number.</p>
<blockquote>
<b>NOTE: </b>
When an XPath expression occurs in an XML document, any
<code><</code> and <code><=</code> operators must be quoted
according to XML 1.0 rules by using, for example,
<code>&lt;</code> and <code>&lt;=</code>. In the following
example the value of the <code>test</code> attribute is an XPath
expression:
<pre><xsl:if test="@value &lt; 10">...</xsl:if></pre>
</blockquote>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-OrExpr"></a>[21] </td><td>OrExpr</td><td> ::= </td><td><a href="#NT-AndExpr">AndExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-OrExpr">OrExpr</a> 'or' <a href="#NT-AndExpr">AndExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-AndExpr"></a>[22] </td><td>AndExpr</td><td> ::= </td><td><a href="#NT-EqualityExpr">EqualityExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-AndExpr">AndExpr</a> 'and' <a href="#NT-EqualityExpr">EqualityExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-EqualityExpr"></a>[23] </td><td>EqualityExpr</td><td> ::= </td><td><a href="#NT-RelationalExpr">RelationalExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-EqualityExpr">EqualityExpr</a> '=' <a href="#NT-RelationalExpr">RelationalExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-EqualityExpr">EqualityExpr</a> '!=' <a href="#NT-RelationalExpr">RelationalExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-RelationalExpr"></a>[24] </td><td>RelationalExpr</td><td> ::= </td><td><a href="#NT-AdditiveExpr">AdditiveExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-RelationalExpr">RelationalExpr</a> '<' <a href="#NT-AdditiveExpr">AdditiveExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-RelationalExpr">RelationalExpr</a> '>' <a href="#NT-AdditiveExpr">AdditiveExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-RelationalExpr">RelationalExpr</a> '<=' <a href="#NT-AdditiveExpr">AdditiveExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-RelationalExpr">RelationalExpr</a> '>=' <a href="#NT-AdditiveExpr">AdditiveExpr</a></td><td></td>
</tr>
</tbody>
</table>
<blockquote>
<b>NOTE: </b>The effect of the above grammar is that the order of
precedence is (lowest precedence first):
<ul>
<li>
<p>
<code>or</code>
</p>
</li>
<li>
<p>
<code>and</code>
</p>
</li>
<li>
<p>
<code>=</code>, <code>!=</code>
</p>
</li>
<li>
<p>
<code><=</code>, <code><</code>, <code>>=</code>,
<code>></code>
</p>
</li>
</ul>
and the operators are all left associative.
For example, <code>3 > 2 > 1</code> is equivalent to <code>(3
> 2) > 1</code>, which evaluates to false.
</blockquote>
<h3>
<a name="numbers"></a>3.5 Numbers</h3>
<p>A number represents a floating-point number. A number can have any
double-precision 64-bit format IEEE 754 value <a href="#IEEE754">[IEEE 754]</a>.
These include a special "Not-a-Number" (NaN) value,
positive and negative infinity, and positive and negative zero. See
<a href="http://java.sun.com/docs/books/jls/html/4.doc.html#9208">Section 4.2.3</a> of <a href="#JLS">[JLS]</a> for a summary of the key
rules of the IEEE 754 standard.</p>
<p>The numeric operators convert their operands to numbers as if by
calling the <b><a href="#function-number">number</a></b> function.</p>
<p>The <code>+</code> operator performs addition.</p>
<p>The <code>-</code> operator performs subtraction.</p>
<blockquote>
<b>NOTE: </b>Since XML allows <code>-</code> in names, the <code>-</code>
operator typically needs to be preceded by whitespace. For example,
<code>foo-bar</code> evaluates to a node-set containing the child
elements named <code>foo-bar</code>; <code>foo - bar</code> evaluates
to the difference of the result of converting the <a href="#dt-string-value">string-value</a> of the first
<code>foo</code> child element to a number and the result of
converting the <a href="#dt-string-value">string-value</a>
of the first <code>bar</code> child to a number.</blockquote>
<p>The <code>div</code> operator performs floating-point division
according to IEEE 754.</p>
<p>The <code>mod</code> operator returns the remainder from a
truncating division. For example,</p>
<ul>
<li>
<p>
<code>5 mod 2</code> returns <code>1</code>
</p>
</li>
<li>
<p>
<code>5 mod -2</code> returns <code>1</code>
</p>
</li>
<li>
<p>
<code>-5 mod 2</code> returns <code>-1</code>
</p>
</li>
<li>
<p>
<code>-5 mod -2</code> returns <code>-1</code>
</p>
</li>
</ul>
<blockquote>
<b>NOTE: </b>This is the same as the <code>%</code> operator in Java and
ECMAScript.</blockquote>
<blockquote>
<b>NOTE: </b>This is not the same as the IEEE 754 remainder operation, which
returns the remainder from a rounding division.</blockquote>
<h5>Numeric Expressions</h5>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-AdditiveExpr"></a>[25] </td><td>AdditiveExpr</td><td> ::= </td><td><a href="#NT-MultiplicativeExpr">MultiplicativeExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-AdditiveExpr">AdditiveExpr</a> '+' <a href="#NT-MultiplicativeExpr">MultiplicativeExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-AdditiveExpr">AdditiveExpr</a> '-' <a href="#NT-MultiplicativeExpr">MultiplicativeExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-MultiplicativeExpr"></a>[26] </td><td>MultiplicativeExpr</td><td> ::= </td><td><a href="#NT-UnaryExpr">UnaryExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-MultiplicativeExpr">MultiplicativeExpr</a> <a href="#NT-MultiplyOperator">MultiplyOperator</a> <a href="#NT-UnaryExpr">UnaryExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-MultiplicativeExpr">MultiplicativeExpr</a> 'div' <a href="#NT-UnaryExpr">UnaryExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-MultiplicativeExpr">MultiplicativeExpr</a> 'mod' <a href="#NT-UnaryExpr">UnaryExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-UnaryExpr"></a>[27] </td><td>UnaryExpr</td><td> ::= </td><td><a href="#NT-UnionExpr">UnionExpr</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| '-' <a href="#NT-UnaryExpr">UnaryExpr</a></td><td></td>
</tr>
</tbody>
</table>
<h3>
<a name="strings"></a>3.6 Strings</h3>
<p>Strings consist of a sequence of zero or more characters, where a
character is defined as in the XML Recommendation <a href="#XML">[XML]</a>.
A single character in XPath thus corresponds to a single Unicode
abstract character with a single corresponding Unicode scalar value
(see <a href="#UNICODE">[Unicode]</a>); this is not the same thing as a 16-bit
Unicode code value: the Unicode coded character representation for an
abstract character with Unicode scalar value greater that U+FFFF is a
pair of 16-bit Unicode code values (a surrogate pair). In many
programming languages, a string is represented by a sequence of 16-bit
Unicode code values; implementations of XPath in such languages must
take care to ensure that a surrogate pair is correctly treated as a
single XPath character.</p>
<blockquote>
<b>NOTE: </b>It is possible in Unicode for there to be two strings that
should be treated as identical even though they consist of the
distinct sequences of Unicode abstract characters. For example, some
accented characters may be represented in either a precomposed or
decomposed form. Therefore, XPath expressions may return unexpected
results unless both the characters in the XPath expression and in the
XML document have been normalized into a canonical form. See <a href="#CHARMOD">[Character Model]</a>.</blockquote>
<h3>
<a name="exprlex"></a>3.7 Lexical Structure</h3>
<p>When tokenizing, the longest possible token is always returned.</p>
<p>For readability, whitespace may be used in expressions even though not
explicitly allowed by the grammar: <a href="#NT-ExprWhitespace">ExprWhitespace</a> may be freely added within
patterns before or after any <a href="#NT-ExprToken">ExprToken</a>.</p>
<p>The following special tokenization rules must be applied in the
order specified to disambiguate the <a href="#NT-ExprToken">ExprToken</a> grammar:</p>
<ul>
<li>
<p>If there is a preceding token and the preceding token is not
one of <code>@</code>, <code>::</code>, <code>(</code>,
<code>[</code>, <code>,</code> or an <a href="#NT-Operator">Operator</a>, then a <code>*</code> must be
recognized as a <a href="#NT-MultiplyOperator">MultiplyOperator</a>
and an <a href="http://www.w3.org/TR/REC-xml-names#NT-NCName">NCName</a> must be
recognized as an <a href="#NT-OperatorName">OperatorName</a>.</p>
</li>
<li>
<p>If the character following an <a href="http://www.w3.org/TR/REC-xml-names#NT-NCName">NCName</a> (possibly after intervening
<a href="#NT-ExprWhitespace">ExprWhitespace</a>) is <code>(</code>,
then the token must be recognized as a <a href="#NT-NodeType">NodeType</a> or a <a href="#NT-FunctionName">FunctionName</a>.</p>
</li>
<li>
<p>If the two characters following an <a href="http://www.w3.org/TR/REC-xml-names#NT-NCName">NCName</a> (possibly after intervening
<a href="#NT-ExprWhitespace">ExprWhitespace</a>) are <code>::</code>,
then the token must be recognized as an <a href="#NT-AxisName">AxisName</a>.</p>
</li>
<li>
<p>Otherwise, the token must not be recognized as a <a href="#NT-MultiplyOperator">MultiplyOperator</a>, an <a href="#NT-OperatorName">OperatorName</a>, a <a href="#NT-NodeType">NodeType</a>, a <a href="#NT-FunctionName">FunctionName</a>, or an <a href="#NT-AxisName">AxisName</a>.</p>
</li>
</ul>
<h5>Expression Lexical Structure</h5>
<table class="scrap">
<tbody>
<tr valign="baseline">
<td><a name="NT-ExprToken"></a>[28] </td><td>ExprToken</td><td> ::= </td><td>'(' | ')' | '[' | ']' | '.' | '..' | '@' | ',' | '::'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-NameTest">NameTest</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-NodeType">NodeType</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-Operator">Operator</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-FunctionName">FunctionName</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-AxisName">AxisName</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-Literal">Literal</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-Number">Number</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-VariableReference">VariableReference</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-Literal"></a>[29] </td><td>Literal</td><td> ::= </td><td>'"' [^"]* '"'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| "'" [^']* "'"</td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-Number"></a>[30] </td><td>Number</td><td> ::= </td><td><a href="#NT-Digits">Digits</a> ('.' <a href="#NT-Digits">Digits</a>?)?</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| '.' <a href="#NT-Digits">Digits</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-Digits"></a>[31] </td><td>Digits</td><td> ::= </td><td>[0-9]+</td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-Operator"></a>[32] </td><td>Operator</td><td> ::= </td><td><a href="#NT-OperatorName">OperatorName</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="#NT-MultiplyOperator">MultiplyOperator</a></td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| '/' | '//' | '|' | '+' | '-' | '=' | '!=' | '<' | '<=' | '>' | '>='</td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-OperatorName"></a>[33] </td><td>OperatorName</td><td> ::= </td><td>'and' | 'or' | 'mod' | 'div'</td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-MultiplyOperator"></a>[34] </td><td>MultiplyOperator</td><td> ::= </td><td>'*'</td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-FunctionName"></a>[35] </td><td>FunctionName</td><td> ::= </td><td>
<a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>
- <a href="#NT-NodeType">NodeType</a>
</td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-VariableReference"></a>[36] </td><td>VariableReference</td><td> ::= </td><td>'$' <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-NameTest"></a>[37] </td><td>NameTest</td><td> ::= </td><td>'*'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="http://www.w3.org/TR/REC-xml-names#NT-NCName">NCName</a> ':' '*'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a></td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-NodeType"></a>[38] </td><td>NodeType</td><td> ::= </td><td>'comment'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'text'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'processing-instruction'</td><td></td>
</tr>
<tr valign="baseline">
<td></td><td></td><td></td><td>| 'node'</td><td></td>
</tr>
<tr valign="baseline">
<td><a name="NT-ExprWhitespace"></a>[39] </td><td>ExprWhitespace</td><td> ::= </td><td><a href="http://www.w3.org/TR/REC-xml#NT-S">S</a></td><td></td>
</tr>
</tbody>
</table>
<h2>
<a name="corelib"></a>4 Core Function Library</h2>
<p>This section describes functions that XPath implementations must
always include in the function library that is used to evaluate
expressions.</p>
<p>Each function in the function library is specified using a function
prototype, which gives the return type, the name of the function, and
the type of the arguments. If an argument type is followed by a
question mark, then the argument is optional; otherwise, the argument
is required.</p>
<h3>
<a name="section-Node-Set-Functions"></a>4.1 Node Set Functions</h3>
<p>
<a name="function-last"><b>Function: </b><i>number</i> <b>last</b>()</a>
</p>
<p>The <b><a href="#function-last">last</a></b> function returns a number equal to
the <a href="#dt-context-size">context size</a> from the
expression evaluation context.</p>
<p>
<a name="function-position"><b>Function: </b><i>number</i> <b>position</b>()</a>
</p>
<p>The <b><a href="#function-position">position</a></b> function returns a number equal to
the <a href="#dt-context-position">context position</a> from
the expression evaluation context.</p>
<p>
<a name="function-count"><b>Function: </b><i>number</i> <b>count</b>(<i>node-set</i>)</a>
</p>
<p>The <b><a href="#function-count">count</a></b> function returns the number of nodes in the
argument node-set.</p>
<p>
<a name="function-id"><b>Function: </b><i>node-set</i> <b>id</b>(<i>object</i>)</a>
</p>
<p>The <b><a href="#function-id">id</a></b> function selects elements by their
unique ID (see <a href="#unique-id">[<b>5.2.1 Unique IDs</b>]</a>). When the argument to
<b><a href="#function-id">id</a></b> is of type node-set, then the result is the
union of the result of applying <b><a href="#function-id">id</a></b> to the
<a href="#dt-string-value">string-value</a> of each of the
nodes in the argument node-set. When the argument to
<b><a href="#function-id">id</a></b> is of any other type, the argument is
converted to a string as if by a call to the
<b><a href="#function-string">string</a></b> function; the string is split into a
whitespace-separated list of tokens (whitespace is any sequence of
characters matching the production <a href="http://www.w3.org/TR/REC-xml#NT-S">S</a>);
the result is a node-set containing the elements in the same document
as the context node that have a unique ID equal to any of the tokens
in the list.</p>
<ul>
<li>
<p>
<code>id("foo")</code> selects the element with unique ID
<code>foo</code>
</p>
</li>
<li>
<p>
<code>id("foo")/child::para[position()=5]</code> selects
the fifth <code>para</code> child of the element with unique ID
<code>foo</code>
</p>
</li>
</ul>
<p>
<a name="function-local-name"><b>Function: </b><i>string</i> <b>local-name</b>(<i>node-set</i>?)</a>
</p>
<p>The <b><a href="#function-local-name">local-name</a></b> function returns the local part
of the <a href="#dt-expanded-name">expanded-name</a> of the
node in the argument node-set that is first in <a href="#dt-document-order">document order</a>. If the argument
node-set is empty or the first node has no <a href="#dt-expanded-name">expanded-name</a>, an empty string is
returned. If the argument is omitted, it defaults to a node-set with
the context node as its only member.</p>
<p>
<a name="function-namespace-uri"><b>Function: </b><i>string</i> <b>namespace-uri</b>(<i>node-set</i>?)</a>
</p>
<p>The <b><a href="#function-namespace-uri">namespace-uri</a></b> function returns the
namespace URI of the <a href="#dt-expanded-name">expanded-name</a> of the node in the
argument node-set that is first in <a href="#dt-document-order">document order</a>. If the argument
node-set is empty, the first node has no <a href="#dt-expanded-name">expanded-name</a>, or the namespace URI
of the <a href="#dt-expanded-name">expanded-name</a> is
null, an empty string is returned. If the argument is omitted, it
defaults to a node-set with the context node as its only member.</p>
<blockquote>
<b>NOTE: </b>The string returned by the
<b><a href="#function-namespace-uri">namespace-uri</a></b> function will be empty except for
element nodes and attribute nodes.</blockquote>
<p>
<a name="function-name"><b>Function: </b><i>string</i> <b>name</b>(<i>node-set</i>?)</a>
</p>
<p>The <b><a href="#function-name">name</a></b> function returns a string containing
a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> representing the
<a href="#dt-expanded-name">expanded-name</a> of the node in
the argument node-set that is first in <a href="#dt-document-order">document order</a>. The <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> must represent the <a href="#dt-expanded-name">expanded-name</a> with respect to the
namespace declarations in effect on the node whose <a href="#dt-expanded-name">expanded-name</a> is being represented.
Typically, this will be the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> that occurred in the XML
source. This need not be the case if there are namespace declarations
in effect on the node that associate multiple prefixes with the same
namespace. However, an implementation may include information about
the original prefix in its representation of nodes; in this case, an
implementation can ensure that the returned string is always the same
as the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> used in the XML
source. If the argument node-set is empty or the first node has no
<a href="#dt-expanded-name">expanded-name</a>, an empty
string is returned. If the argument it omitted, it defaults to a
node-set with the context node as its only member.</p>
<blockquote>
<b>NOTE: </b>The string returned by the <b><a href="#function-name">name</a></b> function
will be the same as the string returned by the
<b><a href="#function-local-name">local-name</a></b> function except for element nodes and
attribute nodes.</blockquote>
<h3>
<a name="section-String-Functions"></a>4.2 String Functions</h3>
<p>
<a name="function-string"><b>Function: </b><i>string</i> <b>string</b>(<i>object</i>?)</a>
</p>
<p>The <b><a href="#function-string">string</a></b> function converts an object to a string
as follows:</p>
<ul>
<li>
<p>A node-set is converted to a string by returning the <a href="#dt-string-value">string-value</a> of the node in the
node-set that is first in <a href="#dt-document-order">document
order</a>. If the node-set is empty, an empty string is
returned.</p>
</li>
<li>
<p>A number is converted to a string as follows</p>
<ul>
<li>
<p>NaN is converted to the string <code>NaN</code>
</p>
</li>
<li>
<p>positive zero is converted to the string
<code>0</code>
</p>
</li>
<li>
<p>negative zero is converted to the string
<code>0</code>
</p>
</li>
<li>
<p>positive infinity is converted to the string
<code>Infinity</code>
</p>
</li>
<li>
<p>negative infinity is converted to the string
<code>-Infinity</code>
</p>
</li>
<li>
<p>if the number is an integer, the number is represented in
decimal form as a <a href="#NT-Number">Number</a> with no decimal
point and no leading zeros, preceded by a minus sign (<code>-</code>)
if the number is negative</p>
</li>
<li>
<p>otherwise, the number is represented in decimal form as a <a href="#NT-Number">Number</a> including a decimal point with at least
one digit before the decimal point and at least one digit after the
decimal point, preceded by a minus sign (<code>-</code>) if the number
is negative; there must be no leading zeros before the decimal point
apart possibly from the one required digit immediately before the
decimal point; beyond the one required digit after the decimal point
there must be as many, but only as many, more digits as are needed to
uniquely distinguish the number from all other IEEE 754 numeric
values.</p>
</li>
</ul>
</li>
<li>
<p>The boolean false value is converted to the string
<code>false</code>. The boolean true value is converted to the
string <code>true</code>.</p>
</li>
<li>
<p>An object of a type other than the four basic types is
converted to a string in a way that is dependent on that
type.</p>
</li>
</ul>
<p>If the argument is omitted, it defaults to a node-set with the
context node as its only member.</p>
<blockquote>
<b>NOTE: </b>The <code>string</code> function is not intended for
converting numbers into strings for presentation to users. The
<code>format-number</code> function and <code>xsl:number</code>
element in <a href="#XSLT">[XSLT]</a> provide this
functionality.</blockquote>
<p>
<a name="function-concat"><b>Function: </b><i>string</i> <b>concat</b>(<i>string</i>, <i>string</i>, <i>string</i>*)</a>
</p>
<p>The <b><a href="#function-concat">concat</a></b> function returns the concatenation of its
arguments.</p>
<p>
<a name="function-starts-with"><b>Function: </b><i>boolean</i> <b>starts-with</b>(<i>string</i>, <i>string</i>)</a>
</p>
<p>The <b><a href="#function-starts-with">starts-with</a></b> function returns true if the
first argument string starts with the second argument string, and
otherwise returns false.</p>
<p>
<a name="function-contains"><b>Function: </b><i>boolean</i> <b>contains</b>(<i>string</i>, <i>string</i>)</a>
</p>
<p>The <b><a href="#function-contains">contains</a></b> function returns true if the first
argument string contains the second argument string, and otherwise
returns false.</p>
<p>
<a name="function-substring-before"><b>Function: </b><i>string</i> <b>substring-before</b>(<i>string</i>, <i>string</i>)</a>
</p>
<p>The <b><a href="#function-substring-before">substring-before</a></b> function returns the substring
of the first argument string that precedes the first occurrence of the
second argument string in the first argument string, or the empty
string if the first argument string does not contain the second
argument string. For example,
<code>substring-before("1999/04/01","/")</code> returns
<code>1999</code>.</p>
<p>
<a name="function-substring-after"><b>Function: </b><i>string</i> <b>substring-after</b>(<i>string</i>, <i>string</i>)</a>
</p>
<p>The <b><a href="#function-substring-after">substring-after</a></b> function returns the
substring of the first argument string that follows the first
occurrence of the second argument string in the first argument string,
or the empty string if the first argument string does not contain the
second argument string. For example,
<code>substring-after("1999/04/01","/")</code> returns
<code>04/01</code>, and
<code>substring-after("1999/04/01","19")</code> returns
<code>99/04/01</code>.</p>
<p>
<a name="function-substring"><b>Function: </b><i>string</i> <b>substring</b>(<i>string</i>, <i>number</i>, <i>number</i>?)</a>
</p>
<p>The <b><a href="#function-substring">substring</a></b> function returns the substring of the
first argument starting at the position specified in the second
argument with length specified in the third argument. For example,
<code>substring("12345",2,3)</code> returns <code>"234"</code>.
If the third argument is not specified, it returns
the substring starting at the position specified in the second
argument and continuing to the end of the string. For example,
<code>substring("12345",2)</code> returns <code>"2345"</code>.</p>
<p>More precisely, each character in the string (see <a href="#strings">[<b>3.6 Strings</b>]</a>) is considered to have a numeric position: the
position of the first character is 1, the position of the second
character is 2 and so on.</p>
<blockquote>
<b>NOTE: </b>This differs from Java and ECMAScript, in which the
<code>String.substring</code> method treats the position of the first
character as 0.</blockquote>
<p>The returned substring contains those
characters for which the position of the character is greater than or
equal to the rounded value of the second argument and, if the third
argument is specified, less than the sum of the rounded value of the
second argument and the rounded value of the third argument; the
comparisons and addition used for the above follow the standard IEEE
754 rules; rounding is done as if by a call to the
<b><a href="#function-round">round</a></b> function. The following examples illustrate
various unusual cases:</p>
<ul>
<li>
<p>
<code>substring("12345", 1.5, 2.6)</code> returns
<code>"234"</code>
</p>
</li>
<li>
<p>
<code>substring("12345", 0, 3)</code> returns
<code>"12"</code>
</p>
</li>
<li>
<p>
<code>substring("12345", 0 div 0, 3)</code> returns
<code>""</code>
</p>
</li>
<li>
<p>
<code>substring("12345", 1, 0 div 0)</code> returns
<code>""</code>
</p>
</li>
<li>
<p>
<code>substring("12345", -42, 1 div 0)</code> returns
<code>"12345"</code>
</p>
</li>
<li>
<p>
<code>substring("12345", -1 div 0, 1 div 0)</code> returns
<code>""</code>
</p>
</li>
</ul>
<p>
<a name="function-string-length"><b>Function: </b><i>number</i> <b>string-length</b>(<i>string</i>?)</a>
</p>
<p>The <b><a href="#function-string-length">string-length</a></b> returns the number of
characters in the string (see <a href="#strings">[<b>3.6 Strings</b>]</a>). If the
argument is omitted, it defaults to the context node converted to a
string, in other words the <a href="#dt-string-value">string-value</a> of the context node.</p>
<p>
<a name="function-normalize-space"><b>Function: </b><i>string</i> <b>normalize-space</b>(<i>string</i>?)</a>
</p>
<p>The <b><a href="#function-normalize-space">normalize-space</a></b> function returns the argument
string with whitespace normalized by stripping leading and trailing
whitespace and replacing sequences of whitespace characters by a
single space. Whitespace characters are the same as those allowed by the <a href="http://www.w3.org/TR/REC-xml#NT-S">S</a> production in XML. If the argument is
omitted, it defaults to the context node converted to a string, in
other words the <a href="#dt-string-value">string-value</a>
of the context node.</p>
<p>
<a name="function-translate"><b>Function: </b><i>string</i> <b>translate</b>(<i>string</i>, <i>string</i>, <i>string</i>)</a>
</p>
<p>The <b><a href="#function-translate">translate</a></b> function returns the first
argument string with occurrences of characters in the second argument
string replaced by the character at the corresponding position in the
third argument string. For example,
<code>translate("bar","abc","ABC")</code> returns the string
<code>BAr</code>. If there is a character in the second argument
string with no character at a corresponding position in the third
argument string (because the second argument string is longer than the
third argument string), then occurrences of that character in the
first argument string are removed. For example,
<code>translate("--aaa--","abc-","ABC")</code> returns
<code>"AAA"</code>. If a character occurs more than once in the second
argument string, then the first occurrence determines the replacement
character. If the third argument string is longer than the second
argument string, then excess characters are ignored.</p>
<blockquote>
<b>NOTE: </b>The <b><a href="#function-translate">translate</a></b> function is not a sufficient
solution for case conversion in all languages. A future version of
XPath may provide additional functions for case conversion.</blockquote>
<h3>
<a name="section-Boolean-Functions"></a>4.3 Boolean Functions</h3>
<p>
<a name="function-boolean"><b>Function: </b><i>boolean</i> <b>boolean</b>(<i>object</i>)</a>
</p>
<p>The <b><a href="#function-boolean">boolean</a></b> function converts its argument to a
boolean as follows:</p>
<ul>
<li>
<p>a number is true if and only if it is neither positive or
negative zero nor NaN</p>
</li>
<li>
<p>a node-set is true if and only if it is non-empty</p>
</li>
<li>
<p>a string is true if and only if its length is non-zero</p>
</li>
<li>
<p>an object of a type other than the four basic types is
converted to a boolean in a way that is dependent on that
type</p>
</li>
</ul>
<p>
<a name="function-not"><b>Function: </b><i>boolean</i> <b>not</b>(<i>boolean</i>)</a>
</p>
<p>The <b><a href="#function-not">not</a></b> function returns true if its argument is
false, and false otherwise.</p>
<p>
<a name="function-true"><b>Function: </b><i>boolean</i> <b>true</b>()</a>
</p>
<p>The <b><a href="#function-true">true</a></b> function returns true.</p>
<p>
<a name="function-false"><b>Function: </b><i>boolean</i> <b>false</b>()</a>
</p>
<p>The <b><a href="#function-false">false</a></b> function returns false.</p>
<p>
<a name="function-lang"><b>Function: </b><i>boolean</i> <b>lang</b>(<i>string</i>)</a>
</p>
<p>The <b><a href="#function-lang">lang</a></b> function returns true or false depending on
whether the language of the context node as specified by
<code>xml:lang</code> attributes is the same as or is a sublanguage of
the language specified by the argument string. The language of the
context node is determined by the value of the <code>xml:lang</code>
attribute on the context node, or, if the context node has no
<code>xml:lang</code> attribute, by the value of the
<code>xml:lang</code> attribute on the nearest ancestor of the context
node that has an <code>xml:lang</code> attribute. If there is no such
attribute, then <b><a href="#function-lang">lang</a></b> returns false. If there is such an
attribute, then <b><a href="#function-lang">lang</a></b> returns true if the attribute
value is equal to the argument ignoring case, or if there is some
suffix starting with <code>-</code> such that the attribute value is
equal to the argument ignoring that suffix of the attribute value and
ignoring case. For example, <code>lang("en")</code> would return true
if the context node is any of these five elements:</p>
<pre><para xml:lang="en"/>
<div xml:lang="en"><para/></div>
<para xml:lang="EN"/>
<para xml:lang="en-us"/></pre>
<h3>
<a name="section-Number-Functions"></a>4.4 Number Functions</h3>
<p>
<a name="function-number"><b>Function: </b><i>number</i> <b>number</b>(<i>object</i>?)</a>
</p>
<p>The <b><a href="#function-number">number</a></b> function converts its argument to a
number as follows:</p>
<ul>
<li>
<p>a string that consists of optional whitespace followed by an
optional minus sign followed by a <a href="#NT-Number">Number</a>
followed by whitespace is converted to the IEEE 754 number that is
nearest (according to the IEEE 754 round-to-nearest rule)
to the mathematical value represented by the string; any other
string is converted to NaN</p>
</li>
<li>
<p>boolean true is converted to 1; boolean false is converted to
0</p>
</li>
<li>
<p>a node-set is first converted to a string as if by a call to the
<b><a href="#function-string">string</a></b> function and then converted in the same way as a
string argument</p>
</li>
<li>
<p>an object of a type other than the four basic types is
converted to a number in a way that is dependent on that
type</p>
</li>
</ul>
<p>If the argument is omitted, it defaults to a node-set with the
context node as its only member.</p>
<blockquote>
<b>NOTE: </b>The <b><a href="#function-number">number</a></b> function should not be used
for conversion of numeric data occurring in an element in an XML
document unless the element is of a type that represents numeric data
in a language-neutral format (which would typically be transformed
into a language-specific format for presentation to a user). In
addition, the <b><a href="#function-number">number</a></b> function cannot be used
unless the language-neutral format used by the element is consistent
with the XPath syntax for a <a href="#NT-Number">Number</a>.</blockquote>
<p>
<a name="function-sum"><b>Function: </b><i>number</i> <b>sum</b>(<i>node-set</i>)</a>
</p>
<p>The <b><a href="#function-sum">sum</a></b> function returns the sum, for each
node in the argument node-set, of the result of converting the
<a href="#dt-string-value">string-value</a>s of the node to
a number.</p>
<p>
<a name="function-floor"><b>Function: </b><i>number</i> <b>floor</b>(<i>number</i>)</a>
</p>
<p>The <b><a href="#function-floor">floor</a></b> function returns the largest (closest to
positive infinity) number that is not greater than the argument and
that is an integer.</p>
<p>
<a name="function-ceiling"><b>Function: </b><i>number</i> <b>ceiling</b>(<i>number</i>)</a>
</p>
<p>The <b><a href="#function-ceiling">ceiling</a></b> function returns the smallest (closest
to negative infinity) number that is not less than the argument and
that is an integer.</p>
<p>
<a name="function-round"><b>Function: </b><i>number</i> <b>round</b>(<i>number</i>)</a>
</p>
<p>The <b><a href="#function-round">round</a></b> function returns the number that is
closest to the argument and that is an integer. If there are two such
numbers, then the one that is closest to positive infinity is
returned. If the argument is NaN, then NaN is returned. If the
argument is positive infinity, then positive infinity is returned. If
the argument is negative infinity, then negative infinity is
returned. If the argument is positive zero, then positive zero is
returned. If the argument is negative zero, then negative zero is
returned. If the argument is less than zero, but greater than or
equal to -0.5, then negative zero is returned.</p>
<blockquote>
<b>NOTE: </b>For these last two cases, the result of calling the
<b><a href="#function-round">round</a></b> function is not the same as the result of
adding 0.5 and then calling the <b><a href="#function-floor">floor</a></b>
function.</blockquote>
<h2>
<a name="data-model"></a>5 Data Model</h2>
<p>XPath operates on an XML document as a tree. This section describes
how XPath models an XML document as a tree. This model is conceptual
only and does not mandate any particular implementation. The
relationship of this model to the XML Information Set <a href="#XINFO">[XML Infoset]</a> is described in <a href="#infoset">[<b>B XML Information Set Mapping</b>]</a>.</p>
<p>XML documents operated on by XPath must conform to the XML
Namespaces Recommendation <a href="#XMLNAMES">[XML Names]</a>.</p>
<p>The tree contains nodes. There are seven types of node:</p>
<ul>
<li>
<p>root nodes</p>
</li>
<li>
<p>element nodes</p>
</li>
<li>
<p>text nodes</p>
</li>
<li>
<p>attribute nodes</p>
</li>
<li>
<p>namespace nodes</p>
</li>
<li>
<p>processing instruction nodes</p>
</li>
<li>
<p>comment nodes</p>
</li>
</ul>
<p>
<a name="dt-string-value"></a>For every type of
node, there is a way of determining a <b>string-value</b> for a
node of that type. For some types of node, the string-value is part
of the node; for other types of node, the string-value is computed
from the string-value of descendant nodes.</p>
<blockquote>
<b>NOTE: </b>For element nodes and root nodes, the string-value of a node
is not the same as the string returned by the DOM
<code>nodeValue</code> method (see <a href="#DOM">[DOM]</a>).</blockquote>
<p>
<a name="dt-expanded-name"></a>Some types of
node also have an <b>expanded-name</b>, which is a pair
consisting of a local part and a namespace URI. The local part is a
string. The namespace URI is either null or a string. The namespace
URI specified in the XML document can be a URI reference as defined in
<a href="#RFC2396">[RFC2396]</a>; this means it can have a fragment identifier
and can be relative. A relative URI should be resolved into an
absolute URI during namespace processing: the namespace URIs of
<a href="#dt-expanded-name">expanded-name</a>s of nodes in
the data model should be absolute. Two <a href="#dt-expanded-name">expanded-name</a>s are equal if they have
the same local part, and either both have a null namespace URI or both
have non-null namespace URIs that are equal.</p>
<p>
<a name="dt-document-order"></a>There is an
ordering, <b>document order</b>, defined on all the nodes in the
document corresponding to the order in which the first character of
the XML representation of each node occurs in the XML representation
of the document after expansion of general entities. Thus, the root
node will be the first node. Element nodes occur before their
children. Thus, document order orders element nodes in order of the
occurrence of their start-tag in the XML (after expansion of
entities). The attribute nodes and namespace nodes of an element occur
before the children of the element. The namespace nodes are defined
to occur before the attribute nodes. The relative order of namespace
nodes is implementation-dependent. The relative order of attribute
nodes is implementation-dependent. <a name="dt-reverse-document-order"></a><b>Reverse document order</b> is the reverse of <a href="#dt-document-order">document order</a>.</p>
<p>Root nodes and element nodes have an ordered list of child nodes.
Nodes never share children: if one node is not the same node as
another node, then none of the children of the one node will be the
same node as any of the children of another node. <a name="dt-parent"></a>Every node other than the root node has
exactly one <b>parent</b>, which is either an element node or
the root node. A root node or an element node is the parent
of each of its child nodes. <a name="dt-descendants"></a>The <b>descendants</b> of a node are the
children of the node and the descendants of the children of the
node.</p>
<h3>
<a name="root-node"></a>5.1 Root Node</h3>
<p>The root node is the root of the tree. A root node does not occur
except as the root of the tree. The element node for the document
element is a child of the root node. The root node also has as
children processing instruction and comment nodes for processing
instructions and comments that occur in the prolog and after the end
of the document element.</p>
<p>The <a href="#dt-string-value">string-value</a> of the
root node is the concatenation of the <a href="#dt-string-value">string-value</a>s of all text node
<a href="#dt-descendants">descendants</a> of the root
node in document order.</p>
<p>The root node does not have an <a href="#dt-expanded-name">expanded-name</a>.</p>
<h3>
<a name="element-nodes"></a>5.2 Element Nodes</h3>
<p>There is an element node for every element in the document. An
element node has an <a href="#dt-expanded-name">expanded-name</a> computed by expanding
the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> of the element
specified in the tag in accordance with the XML Namespaces
Recommendation <a href="#XMLNAMES">[XML Names]</a>. The namespace URI of the
element's <a href="#dt-expanded-name">expanded-name</a> will
be null if the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> has no
prefix and there is no applicable default namespace.</p>
<blockquote>
<b>NOTE: </b>In the notation of Appendix A.3 of <a href="#XMLNAMES">[XML Names]</a>,
the local part of the expanded-name corresponds to the
<code>type</code> attribute of the <code>ExpEType</code> element; the
namespace URI of the expanded-name corresponds to the <code>ns</code>
attribute of the <code>ExpEType</code> element, and is null if the
<code>ns</code> attribute of the <code>ExpEType</code> element is
omitted.</blockquote>
<p>The children of an element node are the element nodes, comment
nodes, processing instruction nodes and text nodes for its content.
Entity references to both internal and external entities are expanded.
Character references are resolved.</p>
<p>The <a href="#dt-string-value">string-value</a> of an
element node is the concatenation of the <a href="#dt-string-value">string-value</a>s of all text node
<a href="#dt-descendants">descendants</a> of the element
node in document order.</p>
<h4>
<a name="unique-id"></a>5.2.1 Unique IDs</h4>
<p>An element node may have a unique identifier (ID). This is the
value of the attribute that is declared in the DTD as type
<code>ID</code>. No two elements in a document may have the same
unique ID. If an XML processor reports two elements in a document as
having the same unique ID (which is possible only if the document is
invalid) then the second element in document order must be treated as
not having a unique ID.</p>
<blockquote>
<b>NOTE: </b>If a document does not have a DTD, then no element in the
document will have a unique ID.</blockquote>
<h3>
<a name="attribute-nodes"></a>5.3 Attribute Nodes</h3>
<p>Each element node has an associated set of attribute nodes; the
element is the <a href="#dt-parent">parent</a> of each of
these attribute nodes; however, an attribute node is not a child of
its parent element.</p>
<blockquote>
<b>NOTE: </b>This is different from the DOM, which does not treat the
element bearing an attribute as the parent of the attribute (see
<a href="#DOM">[DOM]</a>).</blockquote>
<p>Elements never share attribute nodes: if one element node is not
the same node as another element node, then none of the attribute
nodes of the one element node will be the same node as the attribute
nodes of another element node.</p>
<blockquote>
<b>NOTE: </b>The <code>=</code> operator tests whether two nodes have the
same value, <i>not</i> whether they are the same node. Thus
attributes of two different elements may compare as equal using
<code>=</code>, even though they are not the same node.</blockquote>
<p>A defaulted attribute is treated the same as a specified attribute.
If an attribute was declared for the element type in the DTD, but the
default was declared as <code>#IMPLIED</code>, and the attribute was
not specified on the element, then the element's attribute set does
not contain a node for the attribute.</p>
<p>Some attributes, such as <code>xml:lang</code> and
<code>xml:space</code>, have the semantics that they apply to all
elements that are descendants of the element bearing the attribute,
unless overridden with an instance of the same attribute on another
descendant element. However, this does not affect where attribute
nodes appear in the tree: an element has attribute nodes only for
attributes that were explicitly specified in the start-tag or
empty-element tag of that element or that were explicitly declared in
the DTD with a default value.</p>
<p>An attribute node has an <a href="#dt-expanded-name">expanded-name</a> and a <a href="#dt-string-value">string-value</a>. The <a href="#dt-expanded-name">expanded-name</a> is computed by
expanding the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> specified in
the tag in the XML document in accordance with the XML Namespaces
Recommendation <a href="#XMLNAMES">[XML Names]</a>. The namespace URI of the
attribute's name will be null if the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> of the attribute does not have
a prefix.</p>
<blockquote>
<b>NOTE: </b>In the notation of Appendix A.3 of <a href="#XMLNAMES">[XML Names]</a>,
the local part of the expanded-name corresponds to the
<code>name</code> attribute of the <code>ExpAName</code> element; the
namespace URI of the expanded-name corresponds to the <code>ns</code>
attribute of the <code>ExpAName</code> element, and is null if the
<code>ns</code> attribute of the <code>ExpAName</code> element is
omitted.</blockquote>
<p>An attribute node has a <a href="#dt-string-value">string-value</a>. The <a href="#dt-string-value">string-value</a> is the normalized value
as specified by the XML Recommendation <a href="#XML">[XML]</a>. An
attribute whose normalized value is a zero-length string is not
treated specially: it results in an attribute node whose <a href="#dt-string-value">string-value</a> is a zero-length
string.</p>
<blockquote>
<b>NOTE: </b>It is possible for default attributes to be declared in an
external DTD or an external parameter entity. The XML Recommendation
does not require an XML processor to read an external DTD or an
external parameter unless it is validating. A stylesheet or other facility that assumes
that the XPath tree contains default attribute values declared in an
external DTD or parameter entity may not work with some non-validating
XML processors.</blockquote>
<p>There are no attribute nodes corresponding to attributes that
declare namespaces (see <a href="#XMLNAMES">[XML Names]</a>).</p>
<h3>
<a name="namespace-nodes"></a>5.4 Namespace Nodes</h3>
<p>Each element has an associated set of namespace nodes, one for each
distinct namespace prefix that is in scope for the element (including
the <code>xml</code> prefix, which is implicitly declared by the XML
Namespaces Recommendation <a href="#XMLNAMES">[XML Names]</a>) and one for
the default namespace if one is in scope for the element. The element
is the <a href="#dt-parent">parent</a> of each of these
namespace nodes; however, a namespace node is not a child of
its parent element. Elements never share namespace nodes: if one element
node is not the same node as another element node, then none of the
namespace nodes of the one element node will be the same node as the
namespace nodes of another element node. This means that an element
will have a namespace node:</p>
<ul>
<li>
<p>for every attribute on the element whose name starts with
<code>xmlns:</code>;</p>
</li>
<li>
<p>for every attribute on an ancestor element whose name starts
<code>xmlns:</code> unless the element itself or a nearer ancestor
redeclares the prefix;</p>
</li>
<li>
<p>for an <code>xmlns</code> attribute, if the element or some
ancestor has an <code>xmlns</code> attribute, and the value of the
<code>xmlns</code> attribute for the nearest such element is
non-empty</p>
<blockquote>
<b>NOTE: </b>An attribute <code>xmlns=""</code> "undeclares"
the default namespace (see <a href="#XMLNAMES">[XML Names]</a>).</blockquote>
</li>
</ul>
<p>A namespace node has an <a href="#dt-expanded-name">expanded-name</a>: the local part is
the namespace prefix (this is empty if the namespace node is for the
default namespace); the namespace URI is always null.</p>
<p>The <a href="#dt-string-value">string-value</a> of a
namespace node is the namespace URI that is being bound to the
namespace prefix; if it is relative, it must be resolved just like a
namespace URI in an <a href="#dt-expanded-name">expanded-name</a>.</p>
<h3>
<a name="section-Processing-Instruction-Nodes"></a>5.5 Processing Instruction Nodes</h3>
<p>There is a processing instruction node for every processing
instruction, except for any processing instruction that occurs within
the document type declaration.</p>
<p>A processing instruction has an <a href="#dt-expanded-name">expanded-name</a>: the local part is
the processing instruction's target; the namespace URI is null. The
<a href="#dt-string-value">string-value</a> of a processing
instruction node is the part of the processing instruction following
the target and any whitespace. It does not include the terminating
<code>?></code>.</p>
<blockquote>
<b>NOTE: </b>The XML declaration is not a processing instruction.
Therefore, there is no processing instruction node corresponding to the
XML declaration.</blockquote>
<h3>
<a name="section-Comment-Nodes"></a>5.6 Comment Nodes</h3>
<p>There is a comment node for every comment, except for any comment that
occurs within the document type declaration.</p>
<p>The <a href="#dt-string-value">string-value</a> of
comment is the content of the comment not including the opening
<code><!--</code> or the closing <code>--></code>.</p>
<p>A comment node does not have an <a href="#dt-expanded-name">expanded-name</a>.</p>
<h3>
<a name="section-Text-Nodes"></a>5.7 Text Nodes</h3>
<p>Character data is grouped into text nodes. As much character data
as possible is grouped into each text node: a text node never has an
immediately following or preceding sibling that is a text node. The
<a href="#dt-string-value">string-value</a> of a text node
is the character data. A text node always has at least one character
of data.</p>
<p>Each character within a CDATA section is treated as character data.
Thus, <code><![CDATA[<]]></code> in the source document will
treated the same as <code>&lt;</code>. Both will result in a
single <code><</code> character in a text node in the tree. Thus, a
CDATA section is treated as if the <code><![CDATA[</code> and
<code>]]></code> were removed and every occurrence of
<code><</code> and <code>&</code> were replaced by
<code>&lt;</code> and <code>&amp;</code> respectively.</p>
<blockquote>
<b>NOTE: </b>When a text node that contains a <code><</code> character
is written out as XML, the <code><</code> character must be escaped
by, for example, using <code>&lt;</code>, or including it in a
CDATA section.</blockquote>
<p>Characters inside comments, processing instructions and attribute
values do not produce text nodes. Line-endings in external entities
are normalized to #xA as specified in the XML Recommendation <a href="#XML">[XML]</a>.</p>
<p>A text node does not have an <a href="#dt-expanded-name">expanded-name</a>.</p>
<h2>
<a name="section-Conformance"></a>6 Conformance</h2>
<p>XPath is intended primarily as a component that can be used by
other specifications. Therefore, XPath relies on specifications that
use XPath (such as <a href="#XPTR">[XPointer]</a> and <a href="#XSLT">[XSLT]</a>) to
specify criteria for conformance of implementations of XPath and does
not define any conformance criteria for independent implementations of
XPath.</p>
<hr title="Separator from footer">
<h2>
<a name="section-References"></a>A References</h2>
<h3>
<a name="section-Normative-References"></a>A.1 Normative References</h3>
<dl>
<dt>
<a name="IEEE754">IEEE 754</a>
</dt>
<dd>Institute of Electrical and
Electronics Engineers. <i>IEEE Standard for Binary Floating-Point
Arithmetic</i>. ANSI/IEEE Std 754-1985.</dd>
<dt>
<a name="RFC2396">RFC2396</a>
</dt>
<dd>T. Berners-Lee, R. Fielding, and
L. Masinter. <i>Uniform Resource Identifiers (URI): Generic
Syntax</i>. IETF RFC 2396. See <a href="http://www.ietf.org/rfc/rfc2396.txt">http://www.ietf.org/rfc/rfc2396.txt</a>.</dd>
<dt>
<a name="XML">XML</a>
</dt>
<dd>World Wide Web Consortium. <i>Extensible
Markup Language (XML) 1.0.</i> W3C Recommendation. See <a href="http://www.w3.org/TR/1998/REC-xml-19980210">http://www.w3.org/TR/1998/REC-xml-19980210</a>
</dd>
<dt>
<a name="XMLNAMES">XML Names</a>
</dt>
<dd>World Wide Web
Consortium. <i>Namespaces in XML.</i> W3C Recommendation. See
<a href="http://www.w3.org/TR/REC-xml-names">http://www.w3.org/TR/REC-xml-names</a>
</dd>
</dl>
<h3>
<a name="section-Other-References"></a>A.2 Other References</h3>
<dl>
<dt>
<a name="CHARMOD">Character Model</a>
</dt>
<dd>World Wide Web Consortium.
<i>Character Model for the World Wide Web.</i> W3C Working
Draft. See <a href="http://www.w3.org/TR/WD-charmod">http://www.w3.org/TR/WD-charmod</a>
</dd>
<dt>
<a name="DOM">DOM</a>
</dt>
<dd>World Wide Web Consortium. <i>Document
Object Model (DOM) Level 1 Specification.</i> W3C
Recommendation. See <a href="http://www.w3.org/TR/REC-DOM-Level-1">http://www.w3.org/TR/REC-DOM-Level-1</a>
</dd>
<dt>
<a name="JLS">JLS</a>
</dt>
<dd>J. Gosling, B. Joy, and G. Steele. <i>The
Java Language Specification</i>. See <a href="http://java.sun.com/docs/books/jls/index.html">http://java.sun.com/docs/books/jls/index.html</a>.</dd>
<dt>
<a name="ISO10646">ISO/IEC 10646</a>
</dt>
<dd>ISO (International
Organization for Standardization). <i>ISO/IEC 10646-1:1993,
Information technology -- Universal Multiple-Octet Coded Character Set
(UCS) -- Part 1: Architecture and Basic Multilingual Plane</i>.
International Standard. See <a href="http://www.iso.ch/cate/d18741.html">http://www.iso.ch/cate/d18741.html</a>.</dd>
<dt>
<a name="TEI">TEI</a>
</dt>
<dd>C.M. Sperberg-McQueen, L. Burnard
<i>Guidelines for Electronic Text Encoding and
Interchange</i>. See <a href="http://etext.virginia.edu/TEI.html">http://etext.virginia.edu/TEI.html</a>.</dd>
<dt>
<a name="UNICODE">Unicode</a>
</dt>
<dd>Unicode Consortium. <i>The Unicode
Standard</i>. See <a href="http://www.unicode.org/unicode/standard/standard.html">http://www.unicode.org/unicode/standard/standard.html</a>.</dd>
<dt>
<a name="XINFO">XML Infoset</a>
</dt>
<dd>World Wide Web
Consortium. <i>XML Information Set.</i> W3C Working Draft. See
<a href="http://www.w3.org/TR/xml-infoset">http://www.w3.org/TR/xml-infoset</a>
</dd>
<dt>
<a name="XPTR">XPointer</a>
</dt>
<dd>World Wide Web Consortium. <i>XML
Pointer Language (XPointer).</i> W3C Working Draft. See <a href="http://www.w3.org/TR/WD-xptr">http://www.w3.org/TR/WD-xptr</a>
</dd>
<dt>
<a name="XQL">XQL</a>
</dt>
<dd>J. Robie, J. Lapp, D. Schach.
<i>XML Query Language (XQL)</i>. See
<a href="http://www.w3.org/TandS/QL/QL98/pp/xql.html">http://www.w3.org/TandS/QL/QL98/pp/xql.html</a>
</dd>
<dt>
<a name="XSLT">XSLT</a>
</dt>
<dd>World Wide Web Consortium. <i>XSL
Transformations (XSLT).</i> W3C Recommendation. See <a href="http://www.w3.org/TR/xslt">http://www.w3.org/TR/xslt</a>
</dd>
</dl>
<h2>
<a name="infoset"></a>B XML Information Set Mapping (Non-Normative)</h2>
<p>The nodes in the XPath data model can be derived from the
information items provided by the XML Information Set <a href="#XINFO">[XML Infoset]</a> as follows:</p>
<blockquote>
<b>NOTE: </b>A new version of the XML Information Set Working Draft, which
will replace the May 17 version, was close to completion at the time
when the preparation of this version of XPath was completed and was
expected to be released at the same time or shortly after the release
of this version of XPath. The mapping is given for this new version
of the XML Information Set Working Draft. If the new version of the
XML Information Set Working has not yet been released, W3C members may
consult the internal Working Group version <a href="http://www.w3.org/XML/Group/1999/09/WD-xml-infoset-19990915.html">
http://www.w3.org/XML/Group/1999/09/WD-xml-infoset-19990915.html</a>
(<a href="http://cgi.w3.org/MemberAccess/">members
only</a>).</blockquote>
<ul>
<li>
<p>The root node comes from the document information item. The
children of the root node come from the <i>children</i> and <i>children - comments</i>
properties.</p>
</li>
<li>
<p>An element node comes from an element information item. The
children of an element node come from the <i>children</i> and <i>children - comments</i> properties. The
attributes of an element node come from the <i>attributes</i> property. The namespaces
of an element node come from the <i>in-scope namespaces</i> property. The
local part of the <a href="#dt-expanded-name">expanded-name</a> of the element node
comes from the <i>local name</i>
property. The namespace URI of the <a href="#dt-expanded-name">expanded-name</a> of the element node
comes from the <i>namespace URI</i>
property. The unique ID of the element node comes from the <i>children</i> property of the attribute
information item in the <i>attributes</i> property that has an <i>attribute type</i> property equal to
<code>ID</code>.</p>
</li>
<li>
<p>An attribute node comes from an attribute information item.
The local part of the <a href="#dt-expanded-name">expanded-name</a> of the attribute node
comes from the <i>local name</i>
property. The namespace URI of the <a href="#dt-expanded-name">expanded-name</a> of the attribute node
comes from the <i>namespace URI</i>
property. The <a href="#dt-string-value">string-value</a> of
the node comes from concatenating the <i>character code</i> property of each member
of the <i>children</i>
property.</p>
</li>
<li>
<p>A text node comes from a sequence of one or more consecutive
character information items. The <a href="#dt-string-value">string-value</a> of the node comes from
concatenating the <i>character code</i>
property of each of the character information items.</p>
</li>
<li>
<p>A processing instruction node comes from a processing
instruction information item. The local part of the <a href="#dt-expanded-name">expanded-name</a> of the node comes from
the <i>target</i> property. (The
namespace URI part of the <a href="#dt-expanded-name">expanded-name</a> of the node is null.)
The <a href="#dt-string-value">string-value</a> of the node
comes from the <i>content</i>
property. There are no processing instruction nodes for processing
instruction items that are children of document type declaration
information item.</p>
</li>
<li>
<p>A comment node comes from a comment information item. The
<a href="#dt-string-value">string-value</a> of the node
comes from the <i>content</i> property.
There are no comment nodes for comment information items that are
children of document type declaration information item.</p>
</li>
<li>
<p>A namespace node comes from a namespace declaration
information item. The local part of the <a href="#dt-expanded-name">expanded-name</a> of the node comes from
the <i>prefix</i> property. (The
namespace URI part of the <a href="#dt-expanded-name">expanded-name</a> of the node is null.)
The <a href="#dt-string-value">string-value</a> of the node
comes from the <i>namespace URI</i>
property.</p>
</li>
</ul>
</body>
</html>