index.html 313 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 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="EN"><head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>XSL Transformations (XSLT) Version 1.1</title><style type="text/css">
code           { font-family: monospace; }

div.constraint,
div.issue,
div.note,
div.notice     { margin-left: 2em; font-weight: bold }

dt.label       { display: run-in; }

li p           { margin-top: 0.3em;
                 margin-bottom: 0.3em; }
      
div.exampleInner pre { margin-left: 1em;
                       margin-top: 0em; margin-bottom: 0em}
div.exampleOuter {border: 4px double gray;
                  margin: 0em; padding: 0em}
div.exampleInner { background-color: #d5dee3;
                   border-top-width: 4px;
                   border-top-style: double;
                   border-top-color: #d3d3d3;
                   border-bottom-width: 4px;
                   border-bottom-style: double;
                   border-bottom-color: #d3d3d3;
                   padding: 4px; margin: 0em }
div.exampleWrapper { margin: 4px }
div.exampleHeader { font-weight: bold;
                    margin: 4px}
        </style><link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-WD.css"></head><body>
<div class="head"><p><a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/w3c_home" alt="W3C" height="48" width="72"></a></p>
<h1>XSL Transformations (XSLT) Version 1.1</h1>
<h2>W3C Working Draft 24 August 2001</h2><dl><dt>This version:</dt><dd>
<a href="http://www.w3.org/TR/2001/WD-xslt11-20010824/">http://www.w3.org/TR/2001/WD-xslt11-20010824/</a><br />
(also available as <a href="http://www.w3.org/TR/2001/WD-xslt11-20010824/xslt.xml">XML</a> and 
<a href="http://www.w3.org/TR/2001/WD-xslt11-20010824/Overview.html">HTML</a>)

</dd>
<dt>Latest version:</dt><dd>
<a href="http://www.w3.org/TR/xslt11/">http://www.w3.org/TR/xslt11/</a>
</dd>
<dt>Previous version:</dt><dd>
<a href="http://www.w3.org/TR/2000/WD-xslt11-20001212/">
http://www.w3.org/TR/2000/WD-xslt11-20001212/</a></dd>
<dt>Editor:</dt>
<dd>James Clark <a href="mailto:jjc@jclark.com">&lt;jjc@jclark.com&gt;</a></dd>
</dl><p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice-20000612#Copyright">Copyright</a>&nbsp;©&nbsp;2001&nbsp;<a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.lcs.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.inria.fr/"><abbr lang="fr" title="Institut National de Recherche en Informatique et Automatique">INRIA</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice-20000612#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice-20000612#W3C_Trademarks">trademark</a>, <a href="http://www.w3.org/Consortium/Legal/copyright-documents-19990405">document use</a>, and <a href="http://www.w3.org/Consortium/Legal/copyright-software-19980720">software licensing</a> rules apply.</p></div><hr><div>
<h2><a name="abstract">Abstract</a></h2>

<p>This specification defines the syntax and semantics of XSLT, which
is a language for transforming XML documents into other XML
documents.</p>

<p>XSLT is designed for use as part of XSL, which is a stylesheet
language for XML. In addition to XSLT, XSL includes an XML vocabulary
for specifying formatting.  XSL specifies the styling of an XML
document by using XSLT to describe how the document is transformed
into another XML document that uses the formatting vocabulary.</p>

<p>XSLT is also designed to be used independently of XSL.  However,
XSLT is not intended as a completely general-purpose XML
transformation language.  Rather it is designed primarily for the
kinds of transformations that are needed when XSLT is used as part of
XSL.</p>

</div><div>
<h2><a name="status">Status of this Document</a></h2>

<p>This document is a W3C Working Draft for review by W3C
members and other interested parties.</p>

<div class="notice"><p class="prefix"><b>NOTICE:</b></p>As of 24
August 2001 no further work on this draft is expected. The work on
XSLT 2.0 identified a number of issues with the approaches being
pursued in this document; solutions to the requirements of XSLT 1.1
will be considered in the development of XSLT 2.0 <a
href="#XSLT20REQ">[XSLT20REQ]</a>. Other than this paragraph, the
document is unchanged from the previous version.</div>

<p>It is inappropriate to use W3C Working Drafts as reference material
or to cite them as other than "work in progress".</p>

<p>This document is based on the XSLT 1.0 Recommendation
<a href="#XSLT10">[XSLT10]</a>.  The changes made in this document are
intended to meet the requirements for XSLT 1.1 described in <a href="#XSLT11REQ">[XSLT11REQ]</a> and to incorporate fixes for <a href="http://www.w3.org/1999/11/REC-xslt-19991116-errata/">errors</a>
that have been detected in XSLT 1.0.</p>

<p>Comments on this specification may be sent to <a href="mailto:xsl-editors@w3.org">xsl-editors@w3.org</a>; <a href="http://lists.w3.org/Archives/Public/xsl-editors/">archives</a>
of the comments are available.  Public discussion of XSL, including
XSL Transformations, takes place on the <a href="http://www.mulberrytech.com/xsl/xsl-list/index.html">XSL-List</a>
mailing list.</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 has been produced as part of the <a href="http://www.w3.org/Style/Activity">W3C Style activity</a>.</p>

</div>
<div class="toc">
<h2><a name="contents">Table of Contents</a></h2><p class="toc">1 <a href="#N472">Introduction</a><br>2 <a href="#N602">Stylesheet Structure</a><br>&nbsp;&nbsp;&nbsp;&nbsp;2.1 <a href="#xslt-namespace">XSLT Namespace</a><br>&nbsp;&nbsp;&nbsp;&nbsp;2.2 <a href="#stylesheet-element">Stylesheet Element</a><br>&nbsp;&nbsp;&nbsp;&nbsp;2.3 <a href="#result-element-stylesheet">Literal Result Element as Stylesheet</a><br>&nbsp;&nbsp;&nbsp;&nbsp;2.4 <a href="#qname">Qualified Names</a><br>&nbsp;&nbsp;&nbsp;&nbsp;2.5 <a href="#forwards">Forwards-Compatible Processing</a><br>&nbsp;&nbsp;&nbsp;&nbsp;2.6 <a href="#N1316">Combining Stylesheets</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.6.1 <a href="#include">Stylesheet Inclusion</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.6.2 <a href="#import">Stylesheet Import</a><br>&nbsp;&nbsp;&nbsp;&nbsp;2.7 <a href="#N1715">Embedding Stylesheets</a><br>3 <a href="#data-model">Data Model</a><br>&nbsp;&nbsp;&nbsp;&nbsp;3.1 <a href="#root-node-children">Root Node Children</a><br>&nbsp;&nbsp;&nbsp;&nbsp;3.2 <a href="#base-uri">Base URI</a><br>&nbsp;&nbsp;&nbsp;&nbsp;3.3 <a href="#unparsed-entities">Unparsed Entities</a><br>&nbsp;&nbsp;&nbsp;&nbsp;3.4 <a href="#strip">Whitespace Stripping</a><br>&nbsp;&nbsp;&nbsp;&nbsp;3.5 <a href="#namespace-fixup">Namespace Fixup</a><br>4 <a href="#N2221">Expressions</a><br>5 <a href="#rules">Template Rules</a><br>&nbsp;&nbsp;&nbsp;&nbsp;5.1 <a href="#N2337">Processing Model</a><br>&nbsp;&nbsp;&nbsp;&nbsp;5.2 <a href="#patterns">Patterns</a><br>&nbsp;&nbsp;&nbsp;&nbsp;5.3 <a href="#N2967">Defining Template Rules</a><br>&nbsp;&nbsp;&nbsp;&nbsp;5.4 <a href="#N3115">Applying Template Rules</a><br>&nbsp;&nbsp;&nbsp;&nbsp;5.5 <a href="#conflict">Conflict Resolution for Template Rules</a><br>&nbsp;&nbsp;&nbsp;&nbsp;5.6 <a href="#apply-imports">Overriding Template Rules</a><br>&nbsp;&nbsp;&nbsp;&nbsp;5.7 <a href="#modes">Modes</a><br>&nbsp;&nbsp;&nbsp;&nbsp;5.8 <a href="#built-in-rule">Built-in Template Rules</a><br>6 <a href="#named-templates">Named Templates</a><br>7 <a href="#N3791">Creating the Result Tree</a><br>&nbsp;&nbsp;&nbsp;&nbsp;7.1 <a href="#N3799">Creating Elements and Attributes</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7.1.1 <a href="#literal-result-element">Literal Result Elements</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7.1.2 <a href="#N4021">Creating Elements with xsl:element</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7.1.3 <a href="#creating-attributes">Creating Attributes with xsl:attribute</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7.1.4 <a href="#attribute-sets">Named Attribute Sets</a><br>&nbsp;&nbsp;&nbsp;&nbsp;7.2 <a href="#N4656">Creating Text</a><br>&nbsp;&nbsp;&nbsp;&nbsp;7.3 <a href="#N4760">Creating Processing Instructions</a><br>&nbsp;&nbsp;&nbsp;&nbsp;7.4 <a href="#N4885">Creating Comments</a><br>&nbsp;&nbsp;&nbsp;&nbsp;7.5 <a href="#copying">Copying</a><br>&nbsp;&nbsp;&nbsp;&nbsp;7.6 <a href="#N5075">Computing Generated Text</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7.6.1 <a href="#value-of">Generating Text with xsl:value-of</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7.6.2 <a href="#attribute-value-templates">Attribute Value Templates</a><br>&nbsp;&nbsp;&nbsp;&nbsp;7.7 <a href="#number">Numbering</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7.7.1 <a href="#convert">Number to String Conversion Attributes</a><br>8 <a href="#for-each">Repetition</a><br>9 <a href="#N6058">Conditional Processing</a><br>&nbsp;&nbsp;&nbsp;&nbsp;9.1 <a href="#N6078">Conditional Processing with xsl:if</a><br>&nbsp;&nbsp;&nbsp;&nbsp;9.2 <a href="#N6137">Conditional Processing with xsl:choose</a><br>10 <a href="#sorting">Sorting</a><br>11 <a href="#variables">Variables and Parameters</a><br>&nbsp;&nbsp;&nbsp;&nbsp;11.1 <a href="#N6743">Result Tree Fragments</a><br>&nbsp;&nbsp;&nbsp;&nbsp;11.2 <a href="#variable-values">Values of Variables and Parameters</a><br>&nbsp;&nbsp;&nbsp;&nbsp;11.3 <a href="#copy-of">Using Values of Variables and Parameters with
xsl:copy-of</a><br>&nbsp;&nbsp;&nbsp;&nbsp;11.4 <a href="#top-level-variables">Top-level Variables and Parameters</a><br>&nbsp;&nbsp;&nbsp;&nbsp;11.5 <a href="#local-variables">Variables and Parameters within Templates</a><br>&nbsp;&nbsp;&nbsp;&nbsp;11.6 <a href="#with-param">Passing Parameters to Templates</a><br>12 <a href="#add-func">Additional Functions</a><br>&nbsp;&nbsp;&nbsp;&nbsp;12.1 <a href="#document">Multiple Source Documents</a><br>&nbsp;&nbsp;&nbsp;&nbsp;12.2 <a href="#key">Keys</a><br>&nbsp;&nbsp;&nbsp;&nbsp;12.3 <a href="#format-number">Number Formatting</a><br>&nbsp;&nbsp;&nbsp;&nbsp;12.4 <a href="#misc-func">Miscellaneous Additional Functions</a><br>13 <a href="#message">Messages</a><br>14 <a href="#extension">Extensions</a><br>&nbsp;&nbsp;&nbsp;&nbsp;14.1 <a href="#extension-element">Using Extension Elements</a><br>&nbsp;&nbsp;&nbsp;&nbsp;14.2 <a href="#N8607">Using Extension Functions</a><br>&nbsp;&nbsp;&nbsp;&nbsp;14.3 <a href="#external-objects">External Objects</a><br>&nbsp;&nbsp;&nbsp;&nbsp;14.4 <a href="#define-extension-functions">Defining Extension Functions</a><br>15 <a href="#fallback">Fallback</a><br>16 <a href="#output">Output</a><br>&nbsp;&nbsp;&nbsp;&nbsp;16.1 <a href="#N9628">XML Output Method</a><br>&nbsp;&nbsp;&nbsp;&nbsp;16.2 <a href="#N9978">HTML Output Method</a><br>&nbsp;&nbsp;&nbsp;&nbsp;16.3 <a href="#N10310">Text Output Method</a><br>&nbsp;&nbsp;&nbsp;&nbsp;16.4 <a href="#disable-output-escaping">Disabling Output Escaping</a><br>&nbsp;&nbsp;&nbsp;&nbsp;16.5 <a href="#multiple-output">Multiple Output Documents</a><br>17 <a href="#conformance">Conformance</a><br>18 <a href="#notation">Notation</a><br></p>
<h3>Appendices</h3><p class="toc">A <a href="#N10922">References</a><br>&nbsp;&nbsp;&nbsp;&nbsp;A.1 <a href="#N10927">Normative References</a><br>&nbsp;&nbsp;&nbsp;&nbsp;A.2 <a href="#N11053">Other References</a><br>B <a href="#element-syntax-summary">Element Syntax Summary</a><br>C <a href="#N11359">DOM-Based Language Bindings</a><br>&nbsp;&nbsp;&nbsp;&nbsp;C.1 <a href="#N11368">DOM Issues</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.1.1 <a href="#node-set-to-external-function">Passing an XPath node-set to an Extension Function</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.1.2 <a href="#N11530">Returning a NodeList or Node from an Extension Function</a><br>&nbsp;&nbsp;&nbsp;&nbsp;C.2 <a href="#N11723">IDL/DOM2 Language Binding</a><br>&nbsp;&nbsp;&nbsp;&nbsp;C.3 <a href="#ecmascript-binding">ECMAScript/DOM2 Language Binding</a><br>&nbsp;&nbsp;&nbsp;&nbsp;C.4 <a href="#java-binding">Java/DOM2 Language Binding</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.4.1 <a href="#java-identify-method">Identifying the Java Method</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.4.2 <a href="#java-argument-conversions">Argument Conversions</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.4.3 <a href="#N13111">Return Value Conversions</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.4.4 <a href="#java-expression-context">Accessing XSLT Context Information</a><br>D <a href="#dtd">DTD Fragment for XSLT Stylesheets</a> (Non-Normative)<br>E <a href="#N13295">Examples</a> (Non-Normative)<br>&nbsp;&nbsp;&nbsp;&nbsp;E.1 <a href="#N13300">Document Example</a><br>&nbsp;&nbsp;&nbsp;&nbsp;E.2 <a href="#data-example">Data Example</a><br>F <a href="#N13416">Acknowledgements</a> (Non-Normative)<br>G <a href="#N14079">Changes from XSLT 1.0</a> (Non-Normative)<br></p></div><hr><div class="body">
<div class="div1">

<h2><a name="N472"></a>1 Introduction</h2>

<p>This specification defines the syntax and semantics of the XSLT
language.  A transformation in the XSLT language is expressed as a
well-formed XML document <a href="#XML">[XML]</a> conforming to the
Namespaces in XML Recommendation <a href="#XMLNAMES">[XML Names]</a>, which may
include both elements that are defined by XSLT and elements that are
not defined by XSLT.  [<a name="dt-xslt-namespace" title="XSLT Namespace">Definition</a>: XSLT-defined elements are distinguished by belonging to a
specific XML namespace (see <a href="#xslt-namespace"><b>2.1 XSLT Namespace</b></a>), which is
referred to in this specification as the <b>XSLT
namespace</b>.] Thus this specification is a definition of
the syntax and semantics of the XSLT namespace.</p>

<p>A transformation expressed in XSLT describes rules for transforming
a source tree into a result tree.  The transformation is achieved by
associating patterns with templates.  A pattern is matched against
elements in the source tree.  A template is instantiated to create
part of the result tree.  The result tree is separate from the source
tree.  The structure of the result tree can be completely different
from the structure of the source tree. In constructing the result
tree, elements from the source tree can be filtered and reordered, and
arbitrary structure can be added.</p>

<p>A transformation expressed in XSLT is called a stylesheet.  This is
because, in the case when XSLT is transforming into the XSL formatting
vocabulary, the transformation functions as a stylesheet.</p>

<p>This document does not specify how an XSLT stylesheet is associated
with an XML document.  It is recommended that XSL processors support
the mechanism described in <a href="#XMLSTYLE">[XML Stylesheet]</a>.  When this or any
other mechanism yields a sequence of more than one XSLT stylesheet to
be applied simultaneously to a XML document, then the effect
should be the same as applying a single stylesheet that imports each
member of the sequence in order (see <a href="#import"><b>2.6.2 Stylesheet Import</b></a>).</p>

<p>A stylesheet contains a set of template rules.  A template rule has
two parts: a pattern which is matched against nodes in the source tree
and a template which can be instantiated to form part of the result
tree.  This allows a stylesheet to be applicable to a wide class of
documents that have similar source tree structures.</p>

<p>A template is instantiated for a particular source element
to create part of the result tree. A template can contain elements
that specify literal result element structure.  A template can also
contain elements from the XSLT namespace
that are instructions for creating result tree
fragments.  When a template is instantiated, each instruction is
executed and replaced by the result tree fragment that it creates.
Instructions can select and process descendant source elements.  Processing a
descendant element creates a result tree fragment by finding the
applicable template rule and instantiating its template. Note
that elements are only processed when they have been selected by the
execution of an instruction.  The result tree is constructed by
finding the template rule for the root node and instantiating
its template.</p>

<p>In the process of finding the applicable template rule, more
than one template rule may have a pattern that matches a given
element. However, only one template rule will be applied. The
method for deciding which template rule to apply is described
in <a href="#conflict"><b>5.5 Conflict Resolution for Template Rules</b></a>.</p>

<p>A single template by itself has considerable power: it can create
structures of arbitrary complexity; it can pull string values out of
arbitrary locations in the source tree; it can generate structures
that are repeated according to the occurrence of elements in the
source tree.  For simple transformations where the structure of the
result tree is independent of the structure of the source tree, a
stylesheet can often consist of only a single template, which
functions as a template for the complete result tree.  Transformations
on XML documents that represent data are often of this kind (see
<a href="#data-example"><b>E.2 Data Example</b></a>). XSLT allows a simplified syntax for
such stylesheets (see <a href="#result-element-stylesheet"><b>2.3 Literal Result Element as Stylesheet</b></a>).</p>

<p>When a template is instantiated, it is always instantiated with
respect to a [<a name="dt-current-node" title="Current Node">Definition</a>: <b>current node</b>] and a [<a name="dt-current-node-list" title="Current Node List">Definition</a>: <b>current node
list</b>]. The current node is always a member of the
current node list.  Many operations in XSLT are relative to the
current node. Only a few instructions change the current node list or
the current node (see <a href="#rules"><b>5 Template Rules</b></a> and <a href="#for-each"><b>8 Repetition</b></a>); during the instantiation of one of these
instructions, the current node list changes to a new list of nodes and
each member of this new list becomes the current node in turn; after
the instantiation of the instruction is complete, the current node and
current node list revert to what they were before the instruction was
instantiated.</p>

<p>XSLT makes use of the expression language defined by <a href="#XPATH">[XPath]</a> for selecting elements for processing, for conditional
processing and for generating text.</p>

<p>XSLT provides two "hooks" for extending the language,
one hook for extending the set of instruction elements used in
templates and one hook for extending the set of functions used in
XPath expressions.  These hooks are both based on XML namespaces.
See <a href="#extension"><b>14 Extensions</b></a>.  This version of
XSLT defines a mechanism for providing implementations of extension
functions (see <a href="#define-extension-functions"><b>14.4 Defining Extension Functions</b></a>), but does
not define a mechanism for providing implementations of extension
elements.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>The XSL WG intends to define such a mechanism for extension elements in a future version of
this specification or in a separate specification.</p></div>

<p>The element syntax summary notation used to describe the syntax of
XSLT-defined elements is described in <a href="#notation"><b>18 Notation</b></a>.</p>

<p>The MIME media types <code>text/xml</code> and
<code>application/xml</code> <a href="#RFC2376">[RFC2376]</a> should be used
for XSLT stylesheets.  It is possible that a media type will be
registered specifically for XSLT stylesheets; if and when it is, that
media type may also be used.</p>

</div>

<div class="div1">

<h2><a name="N602"></a>2 Stylesheet Structure</h2>

<div class="div2">

<h3><a name="xslt-namespace"></a>2.1 XSLT Namespace</h3>

<p>The XSLT namespace has the URI <code>http://www.w3.org/1999/XSL/Transform</code>.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>The <code>1999</code> in the URI indicates the year in which
the URI was allocated by the W3C.  It does not indicate the version of
XSLT being used, which is specified by attributes (see <a href="#stylesheet-element"><b>2.2 Stylesheet Element</b></a> and <a href="#result-element-stylesheet"><b>2.3 Literal Result Element as Stylesheet</b></a>).</p></div>

<p>XSLT processors must use the XML namespaces mechanism <a href="#XMLNAMES">[XML Names]</a> to recognize elements and attributes from this
namespace. Elements from the XSLT namespace are recognized only in the
stylesheet and not in the source document. The complete list of
XSLT-defined elements is specified in <a href="#element-syntax-summary"><b>B Element Syntax Summary</b></a>.  Vendors must not extend the XSLT
namespace with additional elements or attributes. Instead, any
extension must be in a separate namespace.  Any namespace that is used
for additional instruction elements must be identified by means of the
extension element mechanism specified in <a href="#extension-element"><b>14.1 Using Extension Elements</b></a>.</p>

<p>This specification uses a prefix of <code>xsl:</code> for referring
to elements in the XSLT namespace. However, XSLT stylesheets are free
to use any prefix, provided that there is a namespace declaration that
binds the prefix to the URI of the XSLT namespace.</p>

<p>An element from the XSLT namespace may have any attribute not from
the XSLT namespace, provided that the <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> of the
attribute has a non-null namespace URI.  The presence of such
attributes must not change the behavior of XSLT elements and functions
defined in this document. Thus, an XSLT processor is always free to
ignore such attributes, and must ignore such attributes without giving
an error if it does not recognize the namespace URI. Such attributes
can provide, for example, unique identifiers, optimization hints, or
documentation.</p>

<p>It is an error for an element from the XSLT namespace to have
attributes with expanded-names that have null namespace URIs
(i.e. attributes with unprefixed names) other than attributes defined
for the element in this document.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>The conventions used for the names of XSLT elements,
attributes and functions are that names are all lower-case, use
hyphens to separate words, and use abbreviations only if they already
appear in the syntax of a related language such as XML or
HTML.</p></div>


</div>

<div class="div2">

<h3><a name="stylesheet-element"></a>2.2 Stylesheet Element</h3>


  
    
  
  
    
  
  
    
  
  
    
  
  
    
    
  



  
    
  
  
    
  
  
    
  
  
    
  
  
    
    
  


<p>A stylesheet is represented by an <code>xsl:stylesheet</code>
element in an XML document.  <code>xsl:transform</code> is allowed as
a synonym for <code>xsl:stylesheet</code>.</p>

<p>An <code>xsl:stylesheet</code> element must have a
<code>version</code> attribute, indicating the version of XSLT that
the stylesheet requires.  For this version of XSLT, the value should
be <code>1.1</code>.  When the value is not equal to
<code>1.0</code> or <code>1.1</code>,
forwards-compatible processing mode is enabled (see <a href="#forwards"><b>2.5 Forwards-Compatible Processing</b></a>).</p>

<p>The <code>xsl:stylesheet</code> element may contain the following types
of elements:</p>
<ul>
<li><p><code>xsl:import</code></p></li>
<li><p><code>xsl:include</code></p></li>
<li><p><code>xsl:strip-space</code></p></li>
<li><p><code>xsl:preserve-space</code></p></li>
<li><p><code>xsl:output</code></p></li>
<li><p><code>xsl:key</code></p></li>
<li><p><code>xsl:decimal-format</code></p></li>
<li><p><code>xsl:namespace-alias</code></p></li>
<li><p><code>xsl:attribute-set</code></p></li>
<li><p><code>xsl:variable</code></p></li>
<li><p><code>xsl:param</code></p></li>
<li><p><code>xsl:template</code></p></li>
<li><p><code>xsl:script</code></p></li>
</ul>

<p>[<a name="dt-top-level" title="Top-level">Definition</a>: An element occurring as
a child of an <code>xsl:stylesheet</code> element is called a
<b>top-level</b> element.]</p>

<p>This example shows the structure of a stylesheet.  Ellipses
(<code>...</code>) indicate where attribute values or content have
been omitted.  Although this example shows one of each type of allowed
element, stylesheets may contain zero or more of each of these
elements.</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:import href="..."/&gt;

  &lt;xsl:include href="..."/&gt;

  &lt;xsl:strip-space elements="..."/&gt;
  
  &lt;xsl:preserve-space elements="..."/&gt;

  &lt;xsl:output method="..."/&gt;

  &lt;xsl:key name="..." match="..." use="..."/&gt;

  &lt;xsl:decimal-format name="..."/&gt;

  &lt;xsl:namespace-alias stylesheet-prefix="..." result-prefix="..."/&gt;

  &lt;xsl:attribute-set name="..."&gt;
    ...
  &lt;/xsl:attribute-set&gt;

  &lt;xsl:variable name="..."&gt;...&lt;/xsl:variable&gt;

  &lt;xsl:param name="..."&gt;...&lt;/xsl:param&gt;

  &lt;xsl:script implements-prefix="..." language="..."&gt;
    ...
  &lt;/xsl:script&gt;

  &lt;xsl:template match="..."&gt;
    ...
  &lt;/xsl:template&gt;

  &lt;xsl:template name="..."&gt;
    ...
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></div>

<p>The order in which the children of the <code>xsl:stylesheet</code>
element occur is not significant except for <code>xsl:import</code>
elements and for error recovery.  Users are free to order the elements
as they prefer, and stylesheet creation tools need not provide control
over the order in which the elements occur.</p>

<p>In addition, the <code>xsl:stylesheet</code> element may contain
any element not from the XSLT namespace, provided that the
expanded-name of the element has a non-null namespace URI.  The presence of
such top-level elements must not change the behavior of XSLT elements
and functions defined in this document; for example, it would not be
permitted for such a top-level element to specify that
<code>xsl:apply-templates</code> was to use different rules to resolve
conflicts. Thus, an XSLT processor is always free to ignore such
top-level elements, and must ignore a top-level element without giving
an error if it does not recognize the namespace URI. Such elements can
provide, for example,</p>

<ul>

<li><p>information used by extension elements or extension functions
(see <a href="#extension"><b>14 Extensions</b></a>),</p></li>

<li><p>information about what to do with the result tree,</p></li>

<li><p>information about how to obtain the source tree,</p></li>

<li><p>metadata about the stylesheet,</p></li>

<li><p>structured documentation for the stylesheet.</p></li>

</ul>

</div>

<div class="div2">

<h3><a name="result-element-stylesheet"></a>2.3 Literal Result Element as Stylesheet</h3>

<p>A simplified syntax is allowed for stylesheets that consist of only
a single template for the root node.  The stylesheet may consist of
just a literal result element (see <a href="#literal-result-element"><b>7.1.1 Literal Result Elements</b></a>).  Such a stylesheet is equivalent to a
stylesheet with an <code>xsl:stylesheet</code> element containing a
template rule containing the literal result element; the template rule
has a match pattern of <code>/</code>. For example</p>

<div class="exampleInner"><pre>&lt;html xsl:version="1.1"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns="http://www.w3.org/TR/xhtml1"&gt;
  &lt;head&gt;
    &lt;title&gt;Expense Report Summary&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;Total Amount: &lt;xsl:value-of select="expense-report/total"/&gt;&lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre></div>

<p>has the same meaning as</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/TR/xhtml1"&gt;
&lt;xsl:template match="/"&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Expense Report Summary&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;Total Amount: &lt;xsl:value-of select="expense-report/total"/&gt;&lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;</pre></div>

<p>A literal result element that is the document element of a
stylesheet must have an <code>xsl:version</code> attribute, which
indicates the version of XSLT that the stylesheet requires.  For this
version of XSLT, the value should be <code>1.1</code>; the
value must be a <a href="http://www.w3.org/TR/xpath#NT-Number">Number</a>.  Other
literal result elements may also have an <code>xsl:version</code>
attribute. When the <code>xsl:version</code> attribute is not equal to
<code>1.0</code> or <code>1.1</code>,
forwards-compatible processing mode is enabled (see <a href="#forwards"><b>2.5 Forwards-Compatible Processing</b></a>).</p>

<p>The allowed content of a literal result element when used as a
stylesheet is no different from when it occurs within a
stylesheet. Thus, a literal result element used as a stylesheet cannot
contain <a title="Top-level" href="#dt-top-level">top-level</a> elements.</p>

<p>In some situations, the only way that a system can recognize that an
XML document needs to be processed by an XSLT processor as an XSLT
stylesheet is by examining the XML document itself.  Using the
simplified syntax makes this harder.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>For example, another XML language (AXL) might also use an
<code>axl:version</code> on the document element to indicate that an
XML document was an AXL document that required processing by an AXL
processor; if a document had both an <code>axl:version</code>
attribute and an <code>xsl:version</code> attribute, it would be
unclear whether the document should be processed by an XSLT processor
or an AXL processor.</p></div>

<p>Therefore, the simplified syntax should not be used for XSLT
stylesheets that may be used in such a situation.  This situation can,
for example, arise when an XSLT stylesheet is transmitted as a message
with a MIME media type of <code>text/xml</code> or
<code>application/xml</code> to a recipient that will use the MIME
media type to determine how the message is processed.</p>

</div>

<div class="div2">

<h3><a name="qname"></a>2.4 Qualified Names</h3>

<p>The name of an internal XSLT object, specifically a named template
(see <a href="#named-templates"><b>6 Named Templates</b></a>), a mode (see <a href="#modes"><b>5.7 Modes</b></a>), an attribute set (see <a href="#attribute-sets"><b>7.1.4 Named Attribute Sets</b></a>), a key (see <a href="#key"><b>12.2 Keys</b></a>), a
decimal-format (see <a href="#format-number"><b>12.3 Number Formatting</b></a>), a variable or a
parameter (see <a href="#variables"><b>11 Variables and Parameters</b></a>) is specified as a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>.  If it has a prefix, then the
prefix is expanded into a URI reference using the namespace
declarations in effect on the attribute in which the name occurs.  The
<a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a>
consisting of the local part of the name and the possibly null URI
reference is used as the name of the object.  The default namespace is
<em>not</em> used for unprefixed names.</p>

</div>

<div class="div2">

<h3><a name="forwards"></a>2.5 Forwards-Compatible Processing</h3>

<p>An element enables forwards-compatible mode for itself, its
attributes, its descendants and their attributes if either it is an
<code>xsl:stylesheet</code> element whose <code>version</code>
attribute is not equal to <code>1.0</code> or
<code>1.1</code>, or it is a literal result element that has
an <code>xsl:version</code> attribute whose value is not equal to
<code>1.0</code> or
<code>1.1</code>.  A literal result element
that has an <code>xsl:version</code> attribute whose value is equal to
<code>1.0</code> or <code>1.1</code>
disables forwards-compatible mode for itself, its attributes, its
descendants and their attributes.</p>

<p>If an element is processed in forwards-compatible mode, then:</p>

<ul>

<li><p>if it is a <a title="Top-level" href="#dt-top-level">top-level</a>
element and XSLT 1.1 does not allow such
elements as top-level elements, then the element must be ignored along
with its content;</p></li>

<li><p>if it is an element in a template and XSLT 1.1 does not allow such elements to occur in
templates, then if the element is not instantiated, an error must not
be signaled, and if the element is instantiated, the XSLT must perform
fallback for the element as specified in <a href="#fallback"><b>15 Fallback</b></a>;</p></li>

<li><p>if the element has an attribute that XSLT 1.1 does not allow the element to have or if the
element has an optional attribute with a value that the XSLT 1.1 does not allow the attribute to have, then the
attribute must be ignored.</p></li>

</ul>

<p>Thus, any XSLT 1.1 processor must be
able to process the following stylesheet without error, although the
stylesheet includes elements from the XSLT namespace that are not
defined in this specification:</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet version="17.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:template match="/"&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test="system-property('xsl:version') &gt;= 17.0"&gt;
        &lt;xsl:exciting-new-17.0-feature/&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;html&gt;
        &lt;head&gt;
          &lt;title&gt;XSLT 17.0 required&lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;
          &lt;p&gt;Sorry, this stylesheet requires XSLT 17.0.&lt;/p&gt;
        &lt;/body&gt;
        &lt;/html&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;</pre></div>

<div class="note"><p class="prefix"><b>Note:</b></p><p>If a stylesheet depends crucially on a top-level element
introduced by a version of XSLT after 1.1, then
the stylesheet can use an <code>xsl:message</code> element with
<code>terminate="yes"</code> (see <a href="#message"><b>13 Messages</b></a>) to ensure
that XSLT processors implementing earlier versions of XSLT will not silently ignore the
top-level element. For example,</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet version="18.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:important-new-17.0-declaration/&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test="system-property('xsl:version') &lt; 17.0"&gt;
        &lt;xsl:message terminate="yes"&gt;
          &lt;xsl:text&gt;Sorry, this stylesheet requires XSLT 17.0.&lt;/xsl:text&gt;
        &lt;/xsl:message&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        ...
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
  ...
&lt;/xsl:stylesheet&gt;</pre></div>
</div>

<p>If an <a title="Expression" href="#dt-expression">expression</a> occurs in
an attribute that is processed in forwards-compatible mode, then an
XSLT processor must recover from errors in the expression as
follows:</p>

<ul>

<li><p>if the expression does not match the syntax allowed by the
XPath grammar, then an error must not be signaled unless the
expression is actually evaluated;</p></li>

<li><p>if the expression calls a function with an unprefixed name
that is not part of the XSLT library, then an error must not be
signaled unless the function is actually called;</p></li>

<li><p>if the expression calls a function with a number of arguments
that XSLT does not allow or with arguments of types that XSLT does not
allow, then an error must not be signaled unless the function is
actually called.</p></li>

</ul>


</div>

<div class="div2">

<h3><a name="N1316"></a>2.6 Combining Stylesheets</h3>

<p>XSLT provides two mechanisms to combine stylesheets:</p>

<blockquote><p>

an inclusion mechanism that allows stylesheets to be combined
without changing the semantics of the stylesheets being combined,
and

<br>an import mechanism that allows stylesheets to override each
other.

</p></blockquote>

<div class="div3">

<h4><a name="include"></a>2.6.1 Stylesheet Inclusion</h4>


  
  
    
  
  


<p>An XSLT stylesheet may include another XSLT stylesheet using an
<code>xsl:include</code> element. The <code>xsl:include</code> element
has an <code>href</code> attribute whose value is a URI reference
identifying the stylesheet to be included.  A relative URI is resolved
relative to the base URI of the <code>xsl:include</code> element (see
<a href="#base-uri"><b>3.2 Base URI</b></a>).</p>

<p>The <code>xsl:include</code> element is only allowed as a <a title="Top-level" href="#dt-top-level">top-level</a> element.</p>

<p>The inclusion works at the XML tree level.  The resource located by
the <code>href</code> attribute value is parsed as an XML document,
and the children of the <code>xsl:stylesheet</code> element in this
document replace the <code>xsl:include</code> element in the including
document.  The fact that template rules or definitions are included
does not affect the way they are processed.</p>

<p>The included stylesheet may use the simplified syntax described in
<a href="#result-element-stylesheet"><b>2.3 Literal Result Element as Stylesheet</b></a>.  The included stylesheet
is treated the same as the equivalent <code>xsl:stylesheet</code>
element.</p>

<p>It is an error if a stylesheet directly or indirectly includes
itself.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Including a stylesheet multiple times can cause errors
because of duplicate definitions.  Such multiple inclusions are less
obvious when they are indirect. For example, if stylesheet
<var>B</var> includes stylesheet <var>A</var>, stylesheet <var>C</var>
includes stylesheet <var>A</var>, and stylesheet <var>D</var> includes
both stylesheet <var>B</var> and stylesheet <var>C</var>, then
<var>A</var> will be included indirectly by <var>D</var> twice.  If
all of <var>B</var>, <var>C</var> and <var>D</var> are used as
independent stylesheets, then the error can be avoided by separating
everything in <var>B</var> other than the inclusion of <var>A</var>
into a separate stylesheet <var>B'</var> and changing <var>B</var> to
contain just inclusions of <var>B'</var> and <var>A</var>, similarly
for <var>C</var>, and then changing <var>D</var> to include
<var>A</var>, <var>B'</var>, <var>C'</var>.</p></div>

</div>

<div class="div3">

<h4><a name="import"></a>2.6.2 Stylesheet Import</h4>


  
    
  
  


<p>An XSLT stylesheet may import another XSLT stylesheet using an
<code>xsl:import</code> element.  Importing a stylesheet is the same
as including it (see <a href="#include"><b>2.6.1 Stylesheet Inclusion</b></a>) except that definitions
and template rules in the importing stylesheet take precedence over
template rules and definitions in the imported stylesheet; this is
described in more detail below.  The <code>xsl:import</code> element
has an <code>href</code> attribute whose value is a URI reference
identifying the stylesheet to be imported.  A relative URI is resolved
relative to the base URI of the <code>xsl:import</code> element (see
<a href="#base-uri"><b>3.2 Base URI</b></a>).</p>

<p>The <code>xsl:import</code> element is only allowed as a <a title="Top-level" href="#dt-top-level">top-level</a> element.  The
<code>xsl:import</code> element children must precede all other
element children of an <code>xsl:stylesheet</code> element, including
any <code>xsl:include</code> element children.  When
<code>xsl:include</code> is used to include a stylesheet, any
<code>xsl:import</code> elements in the included document are moved up
in the including document to after any existing
<code>xsl:import</code> elements in the including document.</p>

<p>For example,</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:import href="article.xsl"/&gt;
  &lt;xsl:import href="bigfont.xsl"/&gt;
  &lt;xsl:attribute-set name="note-style"&gt;
    &lt;xsl:attribute name="font-style"&gt;italic&lt;/xsl:attribute&gt;
  &lt;/xsl:attribute-set&gt;
&lt;/xsl:stylesheet&gt;</pre></div>

<p>[<a name="dt-import-tree" title="Import Tree">Definition</a>: The
<code>xsl:stylesheet</code> elements encountered during processing of
a stylesheet that contains <code>xsl:import</code> elements are
treated as forming an <b>import tree</b>.  In the import tree,
each <code>xsl:stylesheet</code> element has one import child for each
<code>xsl:import</code> element that it contains. Any
<code>xsl:include</code> elements are resolved before constructing the
import tree.] [<a name="dt-import-precedence" title="Import Precedence">Definition</a>: An <code>xsl:stylesheet</code> element in the import tree
is defined to have lower <b>import precedence</b> than another
<code>xsl:stylesheet</code> element in the import tree if it would be
visited before that <code>xsl:stylesheet</code> element in a
post-order traversal of the import tree (i.e. a traversal of the
import tree in which an <code>xsl:stylesheet</code> element is visited
after its import children).] Each definition and template
rule has import precedence determined by the
<code>xsl:stylesheet</code> element that contains it.</p>

<p>For example, suppose</p>

<ul>

<li><p>stylesheet <var>A</var> imports stylesheets <var>B</var>
and <var>C</var> in that order;</p></li>

<li><p>stylesheet <var>B</var> imports stylesheet
<var>D</var>;</p></li>

<li><p>stylesheet <var>C</var> imports stylesheet
<var>E</var>.</p></li>

</ul>

<p>Then the order of import precedence (lowest first) is
<var>D</var>, <var>B</var>, <var>E</var>, <var>C</var>,
<var>A</var>.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Since <code>xsl:import</code> elements are required to occur
before any definitions or template rules, an implementation that
processes imported stylesheets at the point at which it encounters the
<code>xsl:import</code> element will encounter definitions and
template rules in increasing order of import precedence.</p></div>

<p>In general, a definition or template rule with higher import
precedence takes precedence over a definition or template rule with
lower import precedence.  This is defined in detail for each kind of
definition and for template rules.</p>

<p>It is an error if a stylesheet directly or indirectly imports
itself. Apart from this, the case where a stylesheet with a particular
URI is imported in multiple places is not treated specially. The
<a title="Import Tree" href="#dt-import-tree">import tree</a> will have a
separate <code>xsl:stylesheet</code> for each place that it is
imported.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>If <code>xsl:apply-imports</code> is used (see <a href="#apply-imports"><b>5.6 Overriding Template Rules</b></a>), the behavior may be different from the
behavior if the stylesheet had been imported only at the place with
the highest <a title="Import Precedence" href="#dt-import-precedence">import
precedence</a>.</p></div>

</div>

</div>

<div class="div2">

<h3><a name="N1715"></a>2.7 Embedding Stylesheets</h3>

<p>Normally an XSLT stylesheet is a complete XML document with the
<code>xsl:stylesheet</code> element as the document element. However,
an XSLT stylesheet may also be embedded in another resource. Two forms
of embedding are possible:</p>

<blockquote><p>

the XSLT stylesheet may be textually embedded in a non-XML
resource, or

<br>the <code>xsl:stylesheet</code> element may occur in an XML
document other than as the document element.

</p></blockquote>

<p>To facilitate the second form of embedding, the
<code>xsl:stylesheet</code> element is allowed to have an ID attribute
that specifies a unique identifier.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>In order for such an attribute to be used with the XPath
id function, it must actually be declared in
the DTD as being an ID.</p></div>

<p>The following example shows how the <code>xml-stylesheet</code>
processing instruction <a href="#XMLSTYLE">[XML Stylesheet]</a> can be used to allow a
document to contain its own stylesheet.  The URI reference uses a
relative URI with a fragment identifier to locate the
<code>xsl:stylesheet</code> element:</p>

<div class="exampleInner"><pre>&lt;?xml-stylesheet type="text/xml" href="#style1"?&gt;
&lt;!DOCTYPE doc SYSTEM "doc.dtd"&gt;
&lt;doc&gt;
&lt;head&gt;
&lt;xsl:stylesheet id="style1"
                version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
&lt;xsl:import href="doc.xsl"/&gt;
&lt;xsl:template match="id('foo')"&gt;
  &lt;fo:block font-weight="bold"&gt;&lt;xsl:apply-templates/&gt;&lt;/fo:block&gt;
&lt;/xsl:template&gt;
&lt;xsl:template match="xsl:stylesheet"&gt;
  &lt;!-- ignore --&gt;
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;para id="foo"&gt;
...
&lt;/para&gt;
&lt;/body&gt;
&lt;/doc&gt;
</pre></div>

<div class="note"><p class="prefix"><b>Note:</b></p><p>A stylesheet that is embedded in the document to which it is
to be applied or that may be included or imported into a stylesheet that is so embedded typically needs
to contain a template rule that specifies that
<code>xsl:stylesheet</code> elements are to be ignored.</p></div>

</div>

</div>

<div class="div1">

<h2><a name="data-model"></a>3 Data Model</h2>

<p>The data model used by XSLT is the same as that used by <a href="http://www.w3.org/TR/xpath#data-model">XPath</a> with the additions
described in this section.  XSLT operates on source, result and
stylesheet documents using the same data model.  Any two XML documents
that have the same tree will be treated the same by XSLT.</p>

<p>Processing instructions and comments in the stylesheet are ignored:
the stylesheet is treated as if neither processing instruction nodes
nor comment nodes were included in the tree that represents the
stylesheet.</p>

<div class="div2">

<h3><a name="root-node-children"></a>3.1 Root Node Children</h3>

<p>The normal restrictions on the children of the root node are
relaxed for the result tree.  The result tree may have any sequence of
nodes as children that would be possible for an element node. In
particular, it may have text node children, and any number of element
node children. When written out using the XML output method (see
<a href="#output"><b>16 Output</b></a>), it is possible that a result tree will not
be a well-formed XML document; however, it will always be a
well-formed external general parsed entity.</p>

<p>When the source tree is created by parsing a well-formed XML
document, the root node of the source tree will automatically satisfy
the normal restrictions of having no text node children and exactly
one element child.  When the source tree is created in some other way,
for example by using the DOM, the usual restrictions are relaxed for
the source tree as for the result tree.</p>

</div>

<div class="div2">

<h3><a name="base-uri"></a>3.2 Base URI</h3>

<p>Every node also has an associated URI called its base URI, which is
used for resolving attribute values that represent relative URIs into
absolute URIs. The base URI is determined as follows:</p>

<ul>

<li><p>The base URI for a root node is the URI of the document
entity.</p></li>

<li><p>The base URI for an element node is as specified in Section
4.2 of <a href="#XMLBASE">[XMLBASE]</a>.</p></li>

<li><p>The base URI for a processing instruction node is the base
URI that Section 4.3 of <a href="#XMLBASE">[XMLBASE]</a> specifies would be
applicable to a URI reference occurring in the content of the
processing instruction.</p></li>

<li><p>The base URI for a text node, a comment node or an attribute
node is the base URI of the parent of the node.</p></li>

<li><p>The base URI for a namespace node is
implementation-dependent.</p></li>

</ul>

</div>

<div class="div2">

<h3><a name="unparsed-entities"></a>3.3 Unparsed Entities</h3>

<p>The root node has a mapping that gives the URI for each unparsed
entity declared in the document's DTD.  The URI is generated from the
system identifier and public identifier specified in the entity
declaration. The XSLT processor may use the public identifier to
generate a URI for the entity instead of the URI specified in the
system identifier.  If the XSLT processor does not use the public
identifier to generate the URI, it must use the system identifier; if
the system identifier is a relative URI, it must be resolved into an
absolute URI using the URI of the resource containing the entity
declaration as the base URI <a href="#RFC2396">[RFC2396]</a>.</p>

</div>

<div class="div2">

<h3><a name="strip"></a>3.4 Whitespace Stripping</h3>

<p>After the tree for a source document or stylesheet document has
been constructed, but before it is otherwise processed by XSLT,
some text nodes are stripped.  A text node is never stripped
unless it contains only whitespace characters.  Stripping the text
node removes the text node from the tree.  The stripping process takes
as input a set of element names for which whitespace must be
preserved.  The stripping process is applied to both stylesheets and
source documents, but the set of whitespace-preserving element names
is determined differently for stylesheets and for source
documents.</p>

<p>A text node is preserved if any of the following apply:</p>

<ul>

<li><p>The element name of the parent of the text node is in the set
of whitespace-preserving element names.</p></li>

<li><p>The text node contains at least one non-whitespace character.
As in XML, a whitespace character is #x20, #x9, #xD or #xA.</p></li>

<li><p>An ancestor element of the text node has an
<code>xml:space</code> attribute with a value of
<code>preserve</code>, and no closer ancestor element has
<code>xml:space</code> with a value of
<code>default</code>.</p></li>

</ul>

<p>Otherwise, the text node is stripped.</p>

<p>The <code>xml:space</code> attributes are not stripped from the
tree.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>This implies that if an <code>xml:space</code> attribute is
specified on a literal result element, it will be included in the
result.</p></div>

<p>For stylesheets, the set of whitespace-preserving element names
consists of just <code>xsl:text</code>.</p>


  
  
    
  
  



  
  
    
  
  


<p id="diff-4">For source documents, the set of
whitespace-preserving element names is specified by
<code>xsl:strip-space</code> and <code>xsl:preserve-space</code>
<a title="Top-level" href="#dt-top-level">top-level</a> elements.  Whether an
element name is included in the set of whitespace-preserving names is
determined by the best match amongst <code>xsl:strip-space</code> or
<code>xsl:preserve-space</code> elements: it is included if and only
if there is no match or the best match is an
<code>xsl:preserve-space</code> element.  The
<code>xsl:strip-space</code> and <code>xsl:preserve-space</code>
elements each have an <code>elements</code> attribute whose value is a
whitespace-separated list of <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a>s; an element name matches an
<code>xsl:strip-space</code> or <code>xsl:preserve-space</code>
element if it matches one of the <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a>s. An element matches a <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a> if and only if the <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a> would be true for the
element as an <a href="http://www.w3.org/TR/xpath#node-tests">XPath node
test</a>.  When more than one <code>xsl:strip-space</code> and
<code>xsl:preserve-space</code> element matches, the best matching
element is determined by the best matching <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a>.  This is determined in the
same way as with template rules:</p>

<ul>

<li><p>First, any match with lower <a title="Import Precedence" href="#dt-import-precedence">import precedence</a> than another
match is ignored.</p></li>

<li><p id="diff-5">Next, any match that has a lower
<a title="Default Priority" href="#dt-default-priority">default priority</a> than the
<a title="Default Priority" href="#dt-default-priority">default priority</a> of
another match is ignored.</p></li>

</ul>

<p>It is an error if this leaves more than one match.  An XSLT
processor may signal the error; if it does not signal the error, it
must recover by choosing, from amongst the matches that are left, the
one that occurs last in the stylesheet.</p>

</div>

<div class="div2">

<h3><a name="namespace-fixup"></a>3.5 Namespace Fixup</h3>

<p>In a tree constructed by parsing an XML document, the following
constraints relating to namespace nodes will be satisfied:</p>

<ul>

<li><p>If an element node has an expanded-name with a non-null
namespace URI, then that element node will have at least one namespace
node whose string-value is the same as that namespace URI.</p></li>

<li><p>If an attribute node has an expanded-name with a non-null
namespace URI, then the parent element of that attribute will have at
least one namespace node whose string-value is the same as that
namespace URI and whose expanded-name has a non-empty local
part.</p></li>

<li><p>If an element node has a namespace node with an expanded-name
with a non-empty local part, then every child element of that element
will also have a namespace node with that expanded-name (possibly with
a different string-value).</p></li>

<li><p>Every element has a namespace node whose expanded-name has
local-part <code>xml</code> and whose string-value is
<code>http://www.w3.org/XML/1998/namespace</code>.</p></li>

</ul>

<p>However, when a tree is being constructed as the result of an XSLT
transformation, these constraints may not be satisfied. In particular,
since <code>xsl:element</code> and <code>xsl:attribute</code>
instructions do not create namespace nodes, they will often cause
these constraints not to be satisfied. [<a name="dt-namespace-fixup" title="Namespace Fixup">Definition</a>: The process of
<b>namespace fixup</b> transforms a result tree by adding
namespace nodes so that it satisfies these constraints.]
What namespace nodes are added and where they are added by
namespace fixup is implementation-dependent, provided that the
resulting tree satisfies the constraints and provided that all
namespaces nodes in the resulting tree are <b>allowable</b>,
where a namespace node is allowable if any of the following conditions
applies:</p>

<ul>

<li><p>The namespace node was in the tree before namespace
fixup.</p></li>

<li><p>The local-part of the expanded-name of the namespace node is
<code>xml</code>.</p></li>

<li><p>The namespace node has a string-value equal to the namespace
URI of the expanded-name of the element that is the parent of the
namespace node.</p></li>

<li><p>The namespace node has a string-value equal to the namespace
URI of the expanded-name of an attribute of the element that is the
parent of the namespace node; this applies only if the local part of
the expanded-name of the namespace node is non-empty.</p></li>

<li><p>The element that is the parent of the namespace node has a
parent element with a namespace node that is allowable and that has
the same expanded-name and same string-value as the other namespace
node; this applies only if the local part of the expanded-name of the
namespace node is non-empty.</p></li>

</ul>

<p>Namespace fixup must not result in an element having multiple
namespace nodes with the same expanded-name.</p>

<p>Namespace fixup is performed in two situations:</p>

<ul>

<li><p>It is applied before a result tree is output (see <a href="#output"><b>16 Output</b></a>).</p></li>

<li><p>It is applied when a tree is constructed and bound to a
variable by a variable-binding element with content (see <a href="#variable-values"><b>11.2 Values of Variables and Parameters</b></a>).</p></li>

</ul>

<table border="1" summary="Editorial note"><tr><td align="left" valign="top" width="50%"><b>Editorial note</b></td><td align="right" valign="top" width="50%">&nbsp;</td></tr><tr><td colspan="2" align="left" valign="top">What about stylesheet parameters that are
node-sets?</td></tr></table>

<table border="1" summary="Editorial note"><tr><td align="left" valign="top" width="50%"><b>Editorial note</b></td><td align="right" valign="top" width="50%">&nbsp;</td></tr><tr><td colspan="2" align="left" valign="top">What about extension functions returning
node-sets?</td></tr></table>

</div>

</div>

<div class="div1">

<h2><a name="N2221"></a>4 Expressions</h2>

<p>XSLT uses the expression language defined by XPath <a href="#XPATH">[XPath]</a>.  Expressions are used in XSLT for a variety of purposes
including:</p>

<blockquote><p>
selecting nodes for processing;
<br>specifying conditions for different ways of processing a node;
<br>generating text to be inserted in the result tree.
</p></blockquote>

<p>[<a name="dt-expression" title="Expression">Definition</a>: An
<b>expression</b> must match the XPath production <a href="http://www.w3.org/TR/xpath#NT-Expr">Expr</a>.]</p>

<p>Expressions occur as the value of certain attributes on
XSLT-defined elements and within curly braces in <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute value
template</a>s.</p>

<p>In XSLT, an outermost expression (i.e. an expression that is not
part of another expression) gets its context as follows:</p>

<ul>

<li><p>the context node comes from the <a title="Current Node" href="#dt-current-node">current node</a></p></li>

<li><p>the context position comes from the position of the <a title="Current Node" href="#dt-current-node">current node</a> in the <a title="Current Node List" href="#dt-current-node-list">current node list</a>; the first
position is 1</p></li>

<li><p>the context size comes from the size of the <a title="Current Node List" href="#dt-current-node-list">current node list</a></p></li>

<li><p>the variable bindings are the bindings in scope on the
element which has the attribute in which the expression occurs (see
<a href="#variables"><b>11 Variables and Parameters</b></a>)</p></li>

<li><p>the set of namespace declarations are those in scope on the
element which has the attribute in which the expression occurs;
this includes the implicit declaration of the prefix <code>xml</code>
required by the the XML Namespaces Recommendation <a href="#XMLNAMES">[XML Names]</a>;
the default
namespace (as declared by <code>xmlns</code>) is not part of this
set</p></li>

<li><p>the function library consists of the core function library
together with the additional functions defined in <a href="#add-func"><b>12 Additional Functions</b></a> and extension functions as described in <a href="#extension"><b>14 Extensions</b></a>; it is an error for an expression to include a call
to any other function</p></li>

</ul>

</div>

<div class="div1">

<h2><a name="rules"></a>5 Template Rules</h2>

<div class="div2">

<h3><a name="N2337"></a>5.1 Processing Model</h3>

<p>A list of source nodes is processed to create a result tree
fragment.  The result tree is constructed by processing a list
containing just the root node.  A list of source nodes is processed by
appending the result tree structure created by processing each of the
members of the list in order.  A node is processed by finding all the
template rules with patterns that match the node, and choosing the
best amongst them; the chosen rule's template is then instantiated
with the node as the <a title="Current Node" href="#dt-current-node">current
node</a> and with the list of source nodes as the <a title="Current Node List" href="#dt-current-node-list">current node list</a>.  A template
typically contains instructions that select an additional list of
source nodes for processing.  The process of matching, instantiation
and selection is continued recursively until no new source nodes are
selected for processing.</p>

<p>Implementations are free to process the source document in any way
that produces the same result as if it were processed using this
processing model.</p>

</div>

<div class="div2">

<h3><a name="patterns"></a>5.2 Patterns</h3>

<p>[<a name="dt-pattern" title="Pattern">Definition</a>: Template rules identify the
nodes to which they apply by using a <b>pattern</b>.  As well as
being used in template rules, patterns are used for numbering (see
<a href="#number"><b>7.7 Numbering</b></a>) and for declaring keys (see <a href="#key"><b>12.2 Keys</b></a>).  A pattern specifies a set of conditions on a node.  A
node that satisfies the conditions matches the pattern; a node that
does not satisfy the conditions does not match the pattern.  The
syntax for patterns is a subset of the syntax for expressions. In
particular, location paths that meet certain restrictions can be used
as patterns.  An expression that is also a pattern always evaluates to
an object of type node-set.  A node matches a pattern if the node is a
member of the result of evaluating the pattern as an expression with
respect to some possible context; the possible contexts are those
whose context node is the node being matched or one of its
ancestors.]</p>

<p>Here are some examples of patterns:</p>

<ul>

<li><p><code>para</code> matches any <code>para</code> element</p></li>

<li><p><code>*</code> matches any element</p></li>

<li><p><code>chapter|appendix</code> matches any
<code>chapter</code> element and any <code>appendix</code>
element</p></li>

<li><p><code>olist/item</code> matches any <code>item</code> element with
an <code>olist</code> parent</p></li>

<li><p><code>appendix//para</code> matches any <code>para</code> element with
an <code>appendix</code> ancestor element</p></li>

<li><p><code>/</code> matches the root node</p></li>

<li><p><code>text()</code> matches any text node</p></li>

<li><p><code>processing-instruction()</code> matches any processing
instruction</p></li>

<li><p><code>node()</code> matches any node other than an attribute
node and the root node</p></li>

<li><p><code>id("W11")</code> matches the element with unique ID
<code>W11</code></p></li>

<li><p><code>para[1]</code> matches any <code>para</code> element
that is the first <code>para</code> child element of its
parent</p></li>

<li><p><code>*[position()=1 and self::para]</code> matches any
<code>para</code> element that is the first child element of its
parent</p></li>

<li><p><code>para[last()=1]</code> matches any <code>para</code>
element that is the only <code>para</code> child element of its
parent</p></li>

<li><p><code>items/item[position()&gt;1]</code> matches any
<code>item</code> element that has an <code>items</code> parent and that is not the
first <code>item</code> child of its parent</p></li>

<li><p><code>item[position() mod 2 = 1]</code> would be true for any
<code>item</code> element that is an odd-numbered <code>item</code>
child of its parent.</p></li>

<li><p><code>div[@class="appendix"]//p</code> matches any
<code>p</code> element with a <code>div</code> ancestor element that
has a <code>class</code> attribute with value
<code>appendix</code></p></li>

<li><p><code>@class</code> matches any <code>class</code> attribute
(<em>not</em> any element that has a <code>class</code>
attribute)</p></li>

<li><p><code>@*</code> matches any attribute</p></li>

</ul>

<p>A pattern must match the grammar for <a href="#NT-Pattern">Pattern</a>.  A <a href="#NT-Pattern">Pattern</a> is
a set of location path patterns separated by <code>|</code>.  A
location path pattern is a location path whose steps all use only the
<code>child</code> or <code>attribute</code> axes.  Although patterns
must not use the <code>descendant-or-self</code> axis, patterns may
use the <code>//</code> operator as well as the <code>/</code>
operator.  Location path patterns can also start with an
id or <code>key</code> function call
with a literal argument.  Predicates in a pattern can use arbitrary
expressions just like predicates in a location path.</p>


<h5>Patterns</h5><table class="scrap" summary="Scrap"><tbody>
<tr valign="baseline"><td><a name="NT-Pattern"></a>[1]&nbsp;&nbsp;&nbsp;</td><td><code>Pattern</code></td><td>&nbsp;&nbsp;&nbsp;::=&nbsp;&nbsp;&nbsp;</td><td><code><a href="#NT-LocationPathPattern">LocationPathPattern</a></code></td></tr><tr valign="baseline"><td></td><td></td><td></td><td><code>| <a href="#NT-Pattern">Pattern</a> '|' <a href="#NT-LocationPathPattern">LocationPathPattern</a></code></td></tr>
<tr valign="baseline"><td><a name="NT-LocationPathPattern"></a>[2]&nbsp;&nbsp;&nbsp;</td><td><code>LocationPathPattern</code></td><td>&nbsp;&nbsp;&nbsp;::=&nbsp;&nbsp;&nbsp;</td><td><code>'/' <a href="#NT-RelativePathPattern">RelativePathPattern</a>?</code></td></tr><tr valign="baseline"><td></td><td></td><td></td><td><code>| <a href="#NT-IdKeyPattern">IdKeyPattern</a> (('/' | '//') <a href="#NT-RelativePathPattern">RelativePathPattern</a>)?</code></td></tr><tr valign="baseline"><td></td><td></td><td></td><td><code>| '//'? <a href="#NT-RelativePathPattern">RelativePathPattern</a></code></td></tr>
<tr valign="baseline"><td><a name="NT-IdKeyPattern"></a>[3]&nbsp;&nbsp;&nbsp;</td><td><code>IdKeyPattern</code></td><td>&nbsp;&nbsp;&nbsp;::=&nbsp;&nbsp;&nbsp;</td><td><code>'id' '(' <a href="http://www.w3.org/TR/xpath#NT-Literal">Literal</a> ')'</code></td></tr><tr valign="baseline"><td></td><td></td><td></td><td><code>| 'key' '(' <a href="http://www.w3.org/TR/xpath#NT-Literal">Literal</a> ',' <a href="http://www.w3.org/TR/xpath#NT-Literal">Literal</a> ')'</code></td></tr>
<tr valign="baseline"><td><a name="NT-RelativePathPattern"></a>[4]&nbsp;&nbsp;&nbsp;</td><td><code>RelativePathPattern</code></td><td>&nbsp;&nbsp;&nbsp;::=&nbsp;&nbsp;&nbsp;</td><td><code><a href="#NT-StepPattern">StepPattern</a></code></td></tr><tr valign="baseline"><td></td><td></td><td></td><td><code>| <a href="#NT-RelativePathPattern">RelativePathPattern</a> '/' <a href="#NT-StepPattern">StepPattern</a></code></td></tr><tr valign="baseline"><td></td><td></td><td></td><td><code>| <a href="#NT-RelativePathPattern">RelativePathPattern</a> '//' <a href="#NT-StepPattern">StepPattern</a></code></td></tr>
<tr valign="baseline"><td><a name="NT-StepPattern"></a>[5]&nbsp;&nbsp;&nbsp;</td><td><code>StepPattern</code></td><td>&nbsp;&nbsp;&nbsp;::=&nbsp;&nbsp;&nbsp;</td><td><code>
<a href="#NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</a>
<a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a>
<a href="http://www.w3.org/TR/xpath#NT-Predicate">Predicate</a>*
</code></td></tr>
<tr valign="baseline"><td><a name="NT-ChildOrAttributeAxisSpecifier"></a>[6]&nbsp;&nbsp;&nbsp;</td><td><code>ChildOrAttributeAxisSpecifier</code></td><td>&nbsp;&nbsp;&nbsp;::=&nbsp;&nbsp;&nbsp;</td><td><code><a href="http://www.w3.org/TR/xpath#NT-AbbreviatedAxisSpecifier">AbbreviatedAxisSpecifier</a></code></td></tr><tr valign="baseline"><td></td><td></td><td></td><td><code>| ('child' | 'attribute') '::'</code></td></tr>
</tbody></table>

<p>A pattern is defined to match a node if and only if there is
possible context such that when the pattern is evaluated as an
expression with that context, the node is a member of the resulting
node-set.  When a node is being matched, the possible contexts have a
context node that is the node being matched or any ancestor of that
node, and a context node list containing just the context node.</p>

<p>For example, <code>p</code> matches any <code>p</code> element,
because for any <code>p</code> if the expression <code>p</code> is
evaluated with the parent of the <code>p</code> element as context the
resulting node-set will contain that <code>p</code> element as one of
its members.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>This matches even a <code>p</code> element that is the
document element, since the document root is the parent of the
document element.</p></div>

<p>Although the semantics of patterns are specified indirectly in
terms of expression evaluation, it is easy to understand the meaning
of a pattern directly without thinking in terms of expression
evaluation.  In a pattern, <code>|</code> indicates alternatives; a
pattern with one or more <code>|</code> separated alternatives matches
if any one of the alternative matches.  A pattern that consists of a
sequence of <a href="#NT-StepPattern">StepPattern</a>s separated by
<code>/</code> or <code>//</code> is matched from right to left.  The
pattern only matches if the rightmost <a href="#NT-StepPattern">StepPattern</a> matches and a suitable element
matches the rest of the pattern; if the separator is <code>/</code>
then only the parent is a suitable element; if the separator is
<code>//</code>, then any ancestor is a suitable element.  A <a href="#NT-StepPattern">StepPattern</a> that uses the child axis matches
if the <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a> is true for the
node and the node is not an attribute node.  A <a href="#NT-StepPattern">StepPattern</a> that uses the attribute axis
matches if the <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a> is true
for the node and the node is an attribute node.  When <code>[]</code>
is present, then the first <a href="http://www.w3.org/TR/xpath#NT-PredicateExpr">PredicateExpr</a> in a <a href="#NT-StepPattern">StepPattern</a> is evaluated with the node being
matched as the context node and the siblings of the context node that
match the <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a> as the
context node list, unless the node being matched is an attribute node,
in which case the context node list is all the attributes that have
the same parent as the attribute being matched and that match the <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a>.</p>

<p>For example</p>

<div class="exampleInner"><pre>appendix//ulist/item[position()=1]</pre></div>

<p>matches a node if and only if all of the following are true:</p>

<ul>

<li><p>the <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a> <code>item</code> is
true for the node and the node is not an attribute; in other words the
node is an <code>item</code> element</p></li>

<li><p>evaluating the <a href="http://www.w3.org/TR/xpath#NT-PredicateExpr">PredicateExpr</a>
<code>position()=1</code> with the node as context node and the
siblings of the node that are <code>item</code> elements as the
context node list yields true</p></li>

<li><p>the node has a parent that matches
<code>appendix//ulist</code>; this will be true if the parent is a
<code>ulist</code> element that has an <code>appendix</code> ancestor
element.</p></li>

</ul>

</div>

<div class="div2">

<h3><a name="N2967"></a>5.3 Defining Template Rules</h3>


  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
    
  


<p>A template rule is specified with the <code>xsl:template</code>
element. The <code>match</code> attribute is a <a href="#NT-Pattern">Pattern</a> that identifies the source node or nodes
to which the rule applies.  The <code>match</code> attribute is
required unless the <code>xsl:template</code> element has a
<code>name</code> attribute (see <a href="#named-templates"><b>6 Named Templates</b></a>).
It is an error for the value of the <code>match</code> attribute to
contain a <a href="http://www.w3.org/TR/xpath#NT-VariableReference">VariableReference</a>. The
content of the <code>xsl:template</code> element is the template that
is instantiated when the template rule is applied.</p>

<p>For example, an XML document might contain:</p>

<div class="exampleInner"><pre>This is an &lt;emph&gt;important&lt;/emph&gt; point.</pre></div>

<p>The following template rule matches <code>emph</code> elements and
produces a <code>fo:inline-sequence</code> formatting object with a
<code>font-weight</code> property of <code>bold</code>.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="emph"&gt;
  &lt;fo:inline-sequence font-weight="bold"&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/fo:inline-sequence&gt;
&lt;/xsl:template&gt;
</pre></div>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Examples in this document use the <code>fo:</code> prefix for
the namespace <code>http://www.w3.org/1999/XSL/Format</code>, which is
the namespace of the formatting objects defined in <a href="#XSL">[XSL]</a>.</p></div>

<p>As described next, the <code>xsl:apply-templates</code> element
recursively processes the children of the source element.</p>

</div>

<div class="div2">

<h3><a name="N3115"></a>5.4 Applying Template Rules</h3>


  
  
    
  
  
    
  
  
    
    
  


<p>This example creates a block for a <code>chapter</code> element and
then processes its immediate children.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="chapter"&gt;
  &lt;fo:block&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;</pre></div>

<p>In the absence of a <code>select</code> attribute, the
<code>xsl:apply-templates</code> instruction processes all of the
children of the current node, including text nodes.  However, text
nodes that have been stripped as specified in <a href="#strip"><b>3.4 Whitespace Stripping</b></a>
will not be processed.  If stripping of whitespace nodes has not been
enabled for an element, then all whitespace in the content of the
element will be processed as text, and thus whitespace
between child elements will count in determining the position of a
child element as returned by the position
function.</p>

<p>A <code>select</code> attribute can be used to process nodes
selected by an expression instead of processing all children.  The
value of the <code>select</code> attribute is an <a title="Expression" href="#dt-expression">expression</a>.  The expression must
evaluate to a node-set.  The selected set of nodes is processed in
document order, unless a sorting specification is present (see
<a href="#sorting"><b>10 Sorting</b></a>).  The following example processes all of the
<code>author</code> children of the <code>author-group</code>:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="author-group"&gt;
  &lt;fo:inline-sequence&gt;
    &lt;xsl:apply-templates select="author"/&gt;
  &lt;/fo:inline-sequence&gt;
&lt;/xsl:template&gt;</pre></div>

<p>The following example processes all of the <code>given-name</code>s
of the <code>author</code>s that are children of
<code>author-group</code>:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="author-group"&gt;
  &lt;fo:inline-sequence&gt;
    &lt;xsl:apply-templates select="author/given-name"/&gt;
  &lt;/fo:inline-sequence&gt;
&lt;/xsl:template&gt;</pre></div>

<p>This example processes all of the <code>heading</code> descendant
elements of the <code>book</code> element.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="book"&gt;
  &lt;fo:block&gt;
    &lt;xsl:apply-templates select=".//heading"/&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;</pre></div>

<p>It is also possible to process elements that are not descendants of
the current node.  This example assumes that a <code>department</code>
element has <code>group</code> children and <code>employee</code>
descendants. It finds an employee's department and then processes
the <code>group</code> children of the <code>department</code>.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="employee"&gt;
  &lt;fo:block&gt;
    Employee &lt;xsl:apply-templates select="name"/&gt; belongs to group
    &lt;xsl:apply-templates select="ancestor::department/group"/&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;</pre></div>

<p>Multiple <code>xsl:apply-templates</code> elements can be used within a
single template to do simple reordering.  The following example
creates two HTML tables. The first table is filled with domestic sales
while the second table is filled with foreign sales.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="product"&gt;
  &lt;table&gt;
    &lt;xsl:apply-templates select="sales/domestic"/&gt;
  &lt;/table&gt;
  &lt;table&gt;
    &lt;xsl:apply-templates select="sales/foreign"/&gt;
  &lt;/table&gt;
&lt;/xsl:template&gt;</pre></div>

<div class="note"><p class="prefix"><b>Note:</b></p>

<p>It is possible for there to be two matching descendants where one
is a descendant of the other.  This case is not treated specially:
both descendants will be processed as usual. For example, given a
source document</p>

<div class="exampleInner"><pre>&lt;doc&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/doc&gt;</pre></div>

<p>the rule</p>

<div class="exampleInner"><pre>&lt;xsl:template match="doc"&gt;
  &lt;xsl:apply-templates select=".//div"/&gt;
&lt;/xsl:template&gt;</pre></div>

<p>will process both the outer <code>div</code> and inner <code>div</code>
elements.</p>

</div>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Typically, <code>xsl:apply-templates</code> is used to
process only nodes that are descendants of the current node.  Such use
of <code>xsl:apply-templates</code> cannot result in non-terminating
processing loops.  However, when <code>xsl:apply-templates</code> is
used to process elements that are not descendants of the current node,
the possibility arises of non-terminating loops. For example,</p>

<div class="exampleInner"><pre>&lt;xsl:template match="foo"&gt;
  &lt;xsl:apply-templates select="."/&gt;
&lt;/xsl:template&gt;</pre></div>

<p>Implementations may be able to detect such loops in some cases, but
the possibility exists that a stylesheet may enter a non-terminating
loop that an implementation is unable to detect. This may present a
denial of service security risk.</p></div>

</div>

<div class="div2">

<h3><a name="conflict"></a>5.5 Conflict Resolution for Template Rules</h3>

<p>It is possible for a source node to match more than one template
rule. The template rule to be used is determined as follows:</p>

<ol>

<li><p>First, all matching template rules that have lower <a title="Import Precedence" href="#dt-import-precedence">import precedence</a> than the
matching template rule or rules with the highest import precedence are
eliminated from consideration.</p></li>

<li><p>Next, all matching template rules that have lower priority
than the matching template rule or rules with the highest priority are
eliminated from consideration.  The priority of a template rule is
specified by the <code>priority</code> attribute on the template rule.
The value of this must be a real number (positive or negative),
matching the production <a href="http://www.w3.org/TR/xpath#NT-Number">Number</a>
with an optional leading minus sign (<code>-</code>).  [<a name="dt-default-priority" title="Default Priority">Definition</a>: The <b>default
priority</b> is computed as follows:]</p>

<ul>

<li><p>If the pattern contains multiple alternatives separated by
<code>|</code>, then it is treated equivalently to a set of template
rules, one for each alternative.</p></li>

<li><p>If the pattern has the form of a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> preceded by a <a href="#NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</a>
or has the form
<code>processing-instruction(</code><a href="http://www.w3.org/TR/xpath#NT-Literal">Literal</a><code>)</code> preceded by a <a href="#NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</a>,
then the priority is 0.</p></li>

<li><p>If the pattern has the form <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCName</a><code>:*</code> preceded by a
<a href="#NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</a>,
then the priority is -0.25.</p></li>

<li><p>Otherwise, if the pattern consists of just a <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a> preceded by a <a href="#NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</a>,
then the priority is -0.5.</p></li>

<li><p>Otherwise, the priority is 0.5.</p></li>

</ul>

<p>Thus, the most common kind of pattern (a pattern that tests for a
node with a particular type and a particular expanded-name) has
priority 0. The next less specific kind of pattern (a pattern that
tests for a node with a particular type and an expanded-name with a
particular namespace URI) has priority -0.25.  Patterns less specific
than this (patterns that just tests for nodes with particular types)
have priority -0.5.  Patterns more specific than the most common kind
of pattern have priority 0.5.</p>

</li>

</ol>

<p>It is an error if this leaves more than one matching template
rule.  An XSLT processor may signal the error; if it does not signal
the error, it must recover by choosing, from amongst the matching
template rules that are left, the one that occurs last in the
stylesheet.</p>

</div>

<div class="div2">

<h3><a name="apply-imports"></a>5.6 Overriding Template Rules</h3>


  
  


<p>A template rule that is being used to override a template rule in
an imported stylesheet (see <a href="#conflict"><b>5.5 Conflict Resolution for Template Rules</b></a>) can use the
<code>xsl:apply-imports</code> element to invoke the overridden
template rule.</p>

<p>[<a name="dt-current-template-rule" title="Current Template Rule">Definition</a>: At any point in the processing of a stylesheet, there is a
<b>current template rule</b>.  Whenever a template rule is
chosen by matching a pattern, the template rule becomes the current
template rule for the instantiation of the rule's template. When an
<code>xsl:for-each</code> element is instantiated, the current
template rule becomes null for the instantiation of the content of the
<code>xsl:for-each</code> element.]</p>

<p><code>xsl:apply-imports</code> processes the current node using
only template rules that were imported into the stylesheet element
containing the current template rule; the node is processed in the
current template rule's mode.
An <code>xsl:apply-imports</code> element may use
<code>xsl:with-param</code> child elements to pass
parameters to the matching template rule's template
(see <a href="#with-param"><b>11.6 Passing Parameters to Templates</b></a>). It is an error if
<code>xsl:apply-imports</code> is instantiated when the current
template rule is null.</p>

<p>For example, suppose the stylesheet <code>doc.xsl</code> contains a
template rule for <code>example</code> elements:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="example"&gt;
  &lt;pre&gt;&lt;xsl:apply-templates/&gt;&lt;/pre&gt;
&lt;/xsl:template&gt;</pre></div>

<p>Another stylesheet could import <code>doc.xsl</code> and modify the
treatment of <code>example</code> elements as follows:</p>

<div class="exampleInner"><pre>&lt;xsl:import href="doc.xsl"/&gt;

&lt;xsl:template match="example"&gt;
  &lt;div style="border: solid red"&gt;
     &lt;xsl:apply-imports/&gt;
  &lt;/div&gt;
&lt;/xsl:template&gt;</pre></div>

<p>The combined effect would be to transform an <code>example</code>
into an element of the form:</p>

<div class="exampleInner"><pre>&lt;div style="border: solid red"&gt;&lt;pre&gt;...&lt;/pre&gt;&lt;/div&gt;</pre></div>

</div>

<div class="div2">

<h3><a name="modes"></a>5.7 Modes</h3>

<p>Modes allow an element to be processed multiple times, each time
producing a different result.</p>

<p>Both <code>xsl:template</code> and <code>xsl:apply-templates</code>
have an optional <code>mode</code> attribute.  The value of the
<code>mode</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>, which is expanded as described
in <a href="#qname"><b>2.4 Qualified Names</b></a>. If <code>xsl:template</code> does not have
a <code>match</code> attribute, it must not have a <code>mode</code>
attribute.  If an <code>xsl:apply-templates</code> element has a
<code>mode</code> attribute, then it applies only to those template
rules from <code>xsl:template</code> elements that have a
<code>mode</code> attribute with the same value; if an
<code>xsl:apply-templates</code> element does not have a
<code>mode</code> attribute, then it applies only to those template
rules from <code>xsl:template</code> elements that do not have a
<code>mode</code> attribute.</p>

</div>

<div class="div2">

<h3><a name="built-in-rule"></a>5.8 Built-in Template Rules</h3>

<p>There is a built-in template rule to allow recursive processing to
continue in the absence of a successful pattern match by an explicit
template rule in the stylesheet.  This template rule applies to both
element nodes and the root node.  The following shows the equivalent
of the built-in template rule:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="*|/"&gt;
  &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;</pre></div>

<p>There is also a built-in template rule for each mode, which allows
recursive processing to continue in the same mode in the absence of a
successful pattern match by an explicit template rule in the
stylesheet.  This template rule applies to both element nodes and the
root node.  The following shows the equivalent of the built-in
template rule for mode <code><var>m</var></code>.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="*|/" mode="<var>m</var>"&gt;
  &lt;xsl:apply-templates mode="<var>m</var>"/&gt;
&lt;/xsl:template&gt;</pre></div>

<p>There is also a built-in template rule for text and attribute nodes
that copies text through:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="text()|@*"&gt;
  &lt;xsl:value-of select="."/&gt;
&lt;/xsl:template&gt;</pre></div>

<p>The built-in template rule for processing instructions and comments
is to do nothing.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="processing-instruction()|comment()"/&gt;</pre></div>

<p>The built-in template rule for namespace nodes is also to do
nothing. There is no pattern that can match a namespace node; so, the
built-in template rule is the only template rule that is applied for
namespace nodes.</p>

<p>The built-in template rules are treated as if they were imported
implicitly before the stylesheet and so have lower <a title="Import Precedence" href="#dt-import-precedence">import precedence</a> than all other
template rules.  Thus, the author can override a built-in template
rule by including an explicit template rule.</p>

</div>


</div>

<div class="div1">

<h2><a name="named-templates"></a>6 Named Templates</h2>


  
  
    
  
  


<p>Templates can be invoked by name.  An <code>xsl:template</code>
element with a <code>name</code> attribute specifies a named template.
The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>, which is expanded as described
in <a href="#qname"><b>2.4 Qualified Names</b></a>. If an <code>xsl:template</code> element has
a <code>name</code> attribute, it may, but need not, also have a
<code>match</code> attribute.  An <code>xsl:call-template</code>
element invokes a template by name; it has a required
<code>name</code> attribute that identifies the template to be
invoked.  Unlike <code>xsl:apply-templates</code>,
<code>xsl:call-template</code> does not change the current node or the
current node list.</p>

<p>The <code>match</code>, <code>mode</code> and <code>priority</code> attributes on an
<code>xsl:template</code> element do not affect whether the template
is invoked by an <code>xsl:call-template</code> element.  Similarly,
the <code>name</code> attribute on an <code>xsl:template</code>
element does not affect whether the template is invoked by an
<code>xsl:apply-templates</code> element.</p>

<p>It is an error if a stylesheet contains more than one template with
the same name and same <a title="Import Precedence" href="#dt-import-precedence">import
precedence</a>.</p>

</div>


<div class="div1">

<h2><a name="N3791"></a>7 Creating the Result Tree</h2>

<p>This section describes instructions that directly create nodes in
the result tree.</p>

<div class="div2">

<h3><a name="N3799"></a>7.1 Creating Elements and Attributes</h3>

<div class="div3">

<h4><a name="literal-result-element"></a>7.1.1 Literal Result Elements</h4>

<p>In a template, an element in the stylesheet that does not belong to
the XSLT namespace and that is not an extension element (see <a href="#extension-element"><b>14.1 Using Extension Elements</b></a>) is instantiated to create an element node
with the same <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a>.  The content
of the element is a template, which is instantiated to give the
content of the created element node. The created element node will
have the attribute nodes that were present on the element node in the
stylesheet tree, other than attributes with names in the XSLT
namespace.</p>

<p>The created element node will also have a copy of the namespace
nodes that were present on the element node in the stylesheet tree
with the exception of any namespace node whose string-value is the
XSLT namespace URI (<code>http://www.w3.org/1999/XSL/Transform</code>), a
namespace URI declared as an extension namespace (see <a href="#extension-element"><b>14.1 Using Extension Elements</b></a>), or a namespace URI designated as an
excluded namespace.  A namespace URI is designated as an excluded
namespace by using an <code>exclude-result-prefixes</code> attribute
on an <code>xsl:stylesheet</code> element or an
<code>xsl:exclude-result-prefixes</code> attribute on a literal result
element.  The value of both these attributes is a whitespace-separated
list of namespace prefixes. The namespace bound to each of the
prefixes is designated as an excluded namespace.  It is an error if
there is no namespace bound to the prefix on the element bearing the
<code>exclude-result-prefixes</code> or
<code>xsl:exclude-result-prefixes</code> attribute.  The default
namespace (as declared by <code>xmlns</code>) may be designated as an
excluded namespace by including <code>#default</code> in the list of
namespace prefixes.  The designation of a namespace as an excluded
namespace is effective within the subtree of the stylesheet rooted at
the element bearing the <code>exclude-result-prefixes</code> or
<code>xsl:exclude-result-prefixes</code> attribute;
a subtree rooted at an <code>xsl:stylesheet</code> element
does not include any stylesheets imported or included by children
of that <code>xsl:stylesheet</code> element.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>When a stylesheet uses a namespace declaration only for the
purposes of addressing the source tree, specifying the prefix in the
<code>exclude-result-prefixes</code> attribute will avoid superfluous
namespace declarations in the result tree.</p></div>

<p>The value of an attribute of a literal result element is
interpreted as an <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute
value template</a>: it can contain expressions contained
in curly braces (<code>{}</code>).</p>

<table border="1" summary="Editorial note"><tr><td align="left" valign="top" width="50%"><b>Editorial note</b></td><td align="right" valign="top" width="50%">&nbsp;</td></tr><tr><td colspan="2" align="left" valign="top">Add note warning against using AVTs with
<code>xml:base</code>.</td></tr></table>

<p>[<a name="dt-literal-namespace-uri" title="Literal Namespace URI">Definition</a>: A namespace URI in the stylesheet tree that is being used to
specify a namespace URI in the result tree is called a <b>literal
namespace URI</b>.] This applies to:</p>

<ul>

<li><p>the namespace URI in the expanded-name of a literal
result element in the stylesheet</p></li>

<li><p>the namespace URI in the expanded-name of an attribute
specified on a literal result element in the stylesheet</p></li>

<li><p>the string-value of a namespace node on a literal result
element in the stylesheet</p></li>

</ul>


  
  
    
    
  
  
    
    
  
  


<p>[<a name="dt-alias" title="Alias">Definition</a>: A stylesheet can use the
<code>xsl:namespace-alias</code> element to declare that one namespace
URI is an <b>alias</b> for another namespace URI.] When
a <a title="Literal Namespace URI" href="#dt-literal-namespace-uri">literal namespace
URI</a> has been declared to be an alias for another namespace
URI, then the namespace URI in the result tree will be the namespace
URI that the literal namespace URI is an alias for, instead of the
literal namespace URI itself.  The <code>xsl:namespace-alias</code>
element declares that the namespace URI bound to the prefix specified
by the <code>stylesheet-prefix</code> attribute is an alias for the
namespace URI bound to the prefix specified by the
<code>result-prefix</code> attribute.  Thus, the
<code>stylesheet-prefix</code> attribute specifies the namespace URI
that will appear in the stylesheet, and the
<code>result-prefix</code> attribute specifies the corresponding
namespace URI that will appear in the result tree.  The default
namespace (as declared by <code>xmlns</code>) may be specified by
using <code>#default</code> instead of a prefix.  If a namespace URI
is declared to be an alias for multiple different namespace URIs, then
the declaration with the highest <a title="Import Precedence" href="#dt-import-precedence">import precedence</a> is used. It is
an error if there is more than one such declaration.  An XSLT
processor may signal the error; if it does not signal the error, it
must recover by choosing, from amongst the declarations with the
highest import precedence, the one that occurs last in the
stylesheet.</p>

<p>When literal result elements are being used to create element,
attribute, or namespace nodes that use the XSLT namespace URI, the
stylesheet must use an alias.  For example, the stylesheet</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet
  version="1.1"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"&gt;

&lt;xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/&gt;

&lt;xsl:template match="/"&gt;
  &lt;axsl:stylesheet&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/axsl:stylesheet&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="block"&gt;
  &lt;axsl:template match="{.}"&gt;
     &lt;fo:block&gt;&lt;axsl:apply-templates/&gt;&lt;/fo:block&gt;
  &lt;/axsl:template&gt;
&lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></div>

<p>will generate an XSLT stylesheet from a document of the form:</p>

<div class="exampleInner"><pre>&lt;elements&gt;
&lt;block&gt;p&lt;/block&gt;
&lt;block&gt;h1&lt;/block&gt;
&lt;block&gt;h2&lt;/block&gt;
&lt;block&gt;h3&lt;/block&gt;
&lt;block&gt;h4&lt;/block&gt;
&lt;/elements&gt;</pre></div>

<div class="note"><p class="prefix"><b>Note:</b></p><p>It may be necessary also to use aliases for namespaces other
than the XSLT namespace URI.  For example, literal result elements
belonging to a namespace dealing with digital signatures might cause
XSLT stylesheets to be mishandled by general-purpose security
software; using an alias for the namespace would avoid the possibility
of such mishandling.</p></div>

</div>

<div class="div3">

<h4><a name="N4021"></a>7.1.2 Creating Elements with <code>xsl:element</code></h4>


  
  
    
      
    
  
  
    
      
    
  
  
    
  
  


<p>The <code>xsl:element</code> element allows an element to be
created with a computed name.  The <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> of the
element to be created is specified by a required <code>name</code>
attribute and an optional <code>namespace</code> attribute.  The
content of the <code>xsl:element</code> element is a template for the
attributes and children of the created element.</p>

<p>The <code>name</code> attribute is interpreted as an <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute value template</a>.
It is an error if the string that results from instantiating the
attribute value template is not a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>.  An XSLT processor may signal
the error; if it does not signal the error, then it must recover
by making the result of instantiating the <code>xsl:element</code>
element be the sequence of nodes created by instantiating
the content of the  <code>xsl:element</code> element, excluding
any initial attribute nodes. If the <code>namespace</code> attribute is
not present then the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> is
expanded into an expanded-name using the namespace declarations in
effect for the <code>xsl:element</code> element, including any default
namespace declaration.</p>

<p>If the <code>namespace</code> attribute is present, then it also is
interpreted as an <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute
value template</a>. The string that results from instantiating
the attribute value template should be a URI reference.  It is not an
error if the string is not a syntactically legal URI reference.  If
the string is empty, then the expanded-name of the element has a null
namespace URI.  Otherwise, the string is used as the namespace URI of
the expanded-name of the element to be created. The local part of the
<a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> specified by the
<code>name</code> attribute is used as the local part of the
expanded-name of the element to be created.</p>

<p>XSLT processors may make use of the prefix of the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> specified in the
<code>name</code> attribute when selecting the prefix used for
outputting the created element as XML; however, they are not required
to do so.</p>

</div>

<div class="div3">

<h4><a name="creating-attributes"></a>7.1.3 Creating Attributes with <code>xsl:attribute</code></h4>


  
  
    
      
    
  
  
    
      
    
  
  


<p>The <code>xsl:attribute</code> element can be used to add
attributes to result elements whether created by literal result
elements in the stylesheet or by instructions such as
<code>xsl:element</code>. The <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> of the
attribute to be created is specified by a required <code>name</code>
attribute and an optional <code>namespace</code> attribute.
Instantiating an <code>xsl:attribute</code> element adds an attribute
node to the containing result element node. The content of the
<code>xsl:attribute</code> element is a template for the value of the
created attribute.</p>

<p>The <code>name</code> attribute is interpreted as an <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute value template</a>.
It is an error if the string that results from instantiating the
attribute value template is not a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> or is the string
<code>xmlns</code>.  An XSLT processor may signal the error; if it
does not signal the error, it must recover by not adding the attribute
to the result tree. If the <code>namespace</code> attribute is not
present, then the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> is
expanded into an expanded-name using the namespace declarations in
effect for the <code>xsl:attribute</code> element, <em>not</em>
including any default namespace declaration.</p>

<p>If the <code>namespace</code> attribute is present, then it also is
interpreted as an <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute
value template</a>. The string that results from instantiating
it should be a URI reference.  It is not an error if the string is not
a syntactically legal URI reference.  If the string is empty, then the
expanded-name of the attribute has a null namespace URI.  Otherwise,
the string is used as the namespace URI of the expanded-name of the
attribute to be created. The local part of the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> specified by the
<code>name</code> attribute is used as the local part of the
expanded-name of the attribute to be created.</p>

<p>XSLT processors may make use of the prefix of the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> specified in the
<code>name</code> attribute when selecting the prefix used for
outputting the created attribute as XML; however, they are not
required to do so and, if the prefix is <code>xmlns</code>, they must
not do so. Thus, although it is not an error to do:</p>

<div class="exampleInner"><pre>&lt;xsl:attribute name="xmlns:xsl" namespace="whatever"&gt;http://www.w3.org/1999/XSL/Transform&lt;/xsl:attribute&gt;</pre></div>

<p>it will not result in a namespace declaration being output.</p>

<p>Adding an attribute to an element replaces any existing attribute
of that element with the same expanded-name.</p>

<p>The following are all errors:</p>

<ul>

<li><p>Adding an attribute to an element after children have been
added to it; implementations may either signal the error or ignore the
attribute.</p></li>

<li><p>Adding an attribute to a node that is not an element;
implementations may either signal the error or ignore the
attribute.</p></li>

<li><p>Creating nodes other than text nodes during the instantiation
of the content of the <code>xsl:attribute</code> element;
implementations may either signal the error or ignore the offending
nodes together with their
content.</p></li>

</ul>

<div class="note"><p class="prefix"><b>Note:</b></p><p>When an <code>xsl:attribute</code> contains a text node with
a newline, then the XML output must contain a character reference.
For example,</p>

<div class="exampleInner"><pre>&lt;xsl:attribute name="a"&gt;x
y&lt;/xsl:attribute&gt;</pre></div>

<p>will result in the output</p>

<div class="exampleInner"><pre>a="x&amp;#xA;y"</pre></div>

<p>(or with any equivalent character reference). The XML output cannot
be</p>

<div class="exampleInner"><pre>a="x
y"</pre></div>

<p>This is because XML 1.0 requires newline characters in attribute
values to be normalized into spaces but requires character references
to newline characters not to be normalized.  The attribute values in
the data model represent the attribute value after normalization.  If
a newline occurring in an attribute value in the tree were output as a
newline character rather than as character reference, then the
attribute value in the tree created by reparsing the XML would contain
a space not a newline, which would mean that the tree had not been
output correctly.</p></div>

</div>

<div class="div3">


<h4><a name="attribute-sets"></a>7.1.4 Named Attribute Sets</h4>


  
  
    
  
  
    
  
  


<p>The <code>xsl:attribute-set</code> element defines a named set of
attributes.  The <code>name</code> attribute specifies the name of the
attribute set.  The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>, which is expanded as described
in <a href="#qname"><b>2.4 Qualified Names</b></a>. The content of the <code>xsl:attribute-set</code>
element consists of zero or more <code>xsl:attribute</code> elements
that specify the attributes in the set.</p>

<p>Attribute sets are used by specifying a
<code>use-attribute-sets</code> attribute on <code>xsl:element</code>,
<code>xsl:copy</code> (see <a href="#copying"><b>7.5 Copying</b></a>) or
<code>xsl:attribute-set</code> elements.  The value of the
<code>use-attribute-sets</code> attribute is a whitespace-separated
list of names of attribute sets.  Each name is specified as a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>, which is expanded as described
in <a href="#qname"><b>2.4 Qualified Names</b></a>.  Specifying a
<code>use-attribute-sets</code> attribute is equivalent to adding
<code>xsl:attribute</code> elements for each of the attributes in each
of the named attribute sets to the beginning of the content of the
element with the <code>use-attribute-sets</code> attribute, in the
same order in which the names of the attribute sets are specified in
the <code>use-attribute-sets</code> attribute.  It is an error if use
of <code>use-attribute-sets</code> attributes on
<code>xsl:attribute-set</code> elements causes an attribute set to
directly or indirectly use itself.</p>

<p>Attribute sets can also be used by specifying an
<code>xsl:use-attribute-sets</code> attribute on a literal result
element.  The value of the <code>xsl:use-attribute-sets</code>
attribute is a whitespace-separated list of names of attribute sets.
The <code>xsl:use-attribute-sets</code> attribute has the same effect
as the <code>use-attribute-sets</code> attribute on
<code>xsl:element</code> with the additional rule that attributes
specified on the literal result element itself are treated as if they
were specified by <code>xsl:attribute</code> elements before any
actual <code>xsl:attribute</code> elements but after any
<code>xsl:attribute</code> elements implied by the
<code>xsl:use-attribute-sets</code> attribute.  Thus, for a literal
result element, attributes from attribute sets named in an
<code>xsl:use-attribute-sets</code> attribute will be added first, in
the order listed in the attribute; next, attributes specified on the
literal result element will be added; finally, any attributes
specified by <code>xsl:attribute</code> elements will be added.  Since
adding an attribute to an element replaces any existing attribute of
that element with the same name, this means that attributes specified
in attribute sets can be overridden by attributes specified on the
literal result element itself.</p>

<p>The template within each <code>xsl:attribute</code> element in an
<code>xsl:attribute-set</code> element is instantiated each time the
attribute set is used; it is instantiated using the same current node
and current node list as is used for instantiating the element bearing
the <code>use-attribute-sets</code> or
<code>xsl:use-attribute-sets</code> attribute. However, it is the
position in the stylesheet of the <code>xsl:attribute</code> element
rather than of the element bearing the <code>use-attribute-sets</code>
or <code>xsl:use-attribute-sets</code> attribute that determines which
variable bindings are visible (see <a href="#variables"><b>11 Variables and Parameters</b></a>); thus,
only variables and parameters declared by <a title="Top-level" href="#dt-top-level">top-level</a> <code>xsl:variable</code> and
<code>xsl:param</code> elements are visible.</p>

<p>The following example creates a named attribute set
<code>title-style</code> and uses it in a template rule.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="chapter/heading"&gt;
  &lt;fo:block quadding="start" xsl:use-attribute-sets="title-style"&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;

&lt;xsl:attribute-set name="title-style"&gt;
  &lt;xsl:attribute name="font-size"&gt;12pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="font-weight"&gt;bold&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;</pre></div>

<p>Multiple definitions of an attribute set with the same
expanded-name are merged.  An attribute from a definition that has
higher <a title="Import Precedence" href="#dt-import-precedence">import precedence</a>
takes precedence over an attribute from a definition that has lower
<a title="Import Precedence" href="#dt-import-precedence">import precedence</a>.  It
is an error if there are two attribute sets that have the same
expanded-name and equal import precedence and that both contain
the same attribute, unless there is a definition of the attribute set
with higher <a title="Import Precedence" href="#dt-import-precedence">import
precedence</a> that also contains the attribute.  An XSLT
processor may signal the error; if it does not signal the error, it
must recover by choosing from amongst the definitions that specify the
attribute that have the highest import precedence the one that was
specified last in the stylesheet.  Where the attributes in an
attribute set were specified is relevant only in merging the
attributes into the attribute set; it makes no difference when the
attribute set is used. For each
attribute set name occurring in a <code>use-attribute-sets</code> attribute on
an <code>xsl:attribute-set</code> element, all definitions of an
attribute set with that name must be merged <em>before</em> the
<code>use-attribute-sets</code> attribute is replaced by the
equivalent sequence of <code>xsl:attribute</code> child elements.  Any
<code>use-attribute-sets</code> attribute on an
<code>xsl:attribute-set</code> element must be replaced by the
equivalent sequence of <code>xsl:attribute</code> child elements
<em>before</em> that <code>xsl:attribute-set</code> element is
merged with other <code>xsl:attribute-set</code> elements with the
same expanded-name. When <code>xsl:attribute-set</code> elements with
the same expanded-name are merged, any <code>xsl:attribute</code>
child elements added to replace a <code>use-attribute-sets</code>
attribute are treated exactly as if they had originally been specified
in the stylesheet as child elements.</p>

</div>

</div>

<div class="div2">


<h3><a name="N4656"></a>7.2 Creating Text</h3>

<p>A template can also contain text nodes.  Each text node in a
template remaining after whitespace has been stripped as specified in
<a href="#strip"><b>3.4 Whitespace Stripping</b></a> will create a text node with the same
string-value in the result tree.  Adjacent text nodes in the result
tree are automatically merged.</p>

<p>Note that text is processed at the tree level. Thus, markup of
<code>&amp;lt;</code> in a template will be represented in the
stylesheet tree by a text node that includes the character
<code>&lt;</code>. This will create a text node in the result tree
that contains a <code>&lt;</code> character, which will be represented
by the markup <code>&amp;lt;</code> (or an equivalent character
reference) when the result tree is externalized as an XML document
(unless output escaping is disabled as described in <a href="#disable-output-escaping"><b>16.4 Disabling Output Escaping</b></a>).</p>


  
  
    
    
  
    


<p>Literal data characters may also be wrapped in an
<code>xsl:text</code> element.  This wrapping may change what
whitespace characters are stripped (see <a href="#strip"><b>3.4 Whitespace Stripping</b></a>) but
does not affect how the characters are handled by the XSLT processor
thereafter.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>The <code>xml:lang</code> and <code>xml:space</code>
attributes are not treated specially by XSLT. In particular,</p>

<ul>
<li><p>it is the responsibility of the stylesheet author explicitly
to generate any <code>xml:lang</code> or <code>xml:space</code>
attributes that are needed in the result;</p></li>

<li><p>specifying an <code>xml:lang</code> or <code>xml:space</code>
attribute on an element in the XSLT namespace will not cause any
<code>xml:lang</code> or <code>xml:space</code> attributes to appear
in the result.</p></li>
</ul>
</div>

</div>


<div class="div2">

<h3><a name="N4760"></a>7.3 Creating Processing Instructions</h3>



  
  
    
      
    
  
  


<p>The <code>xsl:processing-instruction</code> element is instantiated
to create a processing instruction node.  The content of the
<code>xsl:processing-instruction</code> element is a template for the
string-value of the processing instruction node.  The
<code>xsl:processing-instruction</code> element has a required
<code>name</code> attribute that specifies the name of the processing
instruction node.  The value of the <code>name</code> attribute is
interpreted as an <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute
value template</a>.</p>

<p>For example, this</p>

<div class="exampleInner"><pre>&lt;xsl:processing-instruction name="xml-stylesheet"&gt;href="book.css" type="text/css"&lt;/xsl:processing-instruction&gt;</pre></div>

<p>would create the processing instruction</p>

<div class="exampleInner"><pre>&lt;?xml-stylesheet href="book.css" type="text/css"?&gt;</pre></div>

<p>It is an error if the string that results from instantiating the
<code>name</code> attribute is not both an <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCName</a> and a <a href="http://www.w3.org/TR/REC-xml#NT-PITarget">PITarget</a>.  An XSLT processor may signal
the error; if it does not signal the error, it must recover by not
adding the processing instruction to the result tree.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>This means that <code>xsl:processing-instruction</code>
cannot be used to output an XML declaration.  The
<code>xsl:output</code> element should be used instead (see <a href="#output"><b>16 Output</b></a>).</p></div>

<p>It is an error if instantiating the content of
<code>xsl:processing-instruction</code> creates nodes other than
text nodes.  An XSLT processor may signal the error; if it does not
signal the error, it must recover by ignoring the offending nodes
together with their content.</p>

<p>It is an error if the result of instantiating the content of the
<code>xsl:processing-instruction</code> contains the string
<code>?&gt;</code>.  An XSLT processor may signal the error; if it does
not signal the error, it must recover by inserting a space after any
occurrence of <code>?</code> that is followed by a <code>&gt;</code>.</p>

</div>

<div class="div2">

<h3><a name="N4885"></a>7.4 Creating Comments</h3>


  
  


<p>The <code>xsl:comment</code> element is instantiated to create a
comment node in the result tree.  The content of the
<code>xsl:comment</code> element is a template for the string-value of
the comment node.</p>

<p>For example, this</p>

<div class="exampleInner"><pre>&lt;xsl:comment&gt;This file is automatically generated. Do not edit!&lt;/xsl:comment&gt;</pre></div>

<p>would create the comment</p>

<div class="exampleInner"><pre>&lt;!--This file is automatically generated. Do not edit!--&gt;</pre></div>

<p>It is an error if instantiating the content of
<code>xsl:comment</code> creates nodes other than text nodes.  An
XSLT processor may signal the error; if it does not signal the error,
it must recover by ignoring the offending nodes together with their
content.</p>

<p>It is an error if the result of instantiating the content of the
<code>xsl:comment</code> contains the string <code>--</code> or ends
with <code>-</code>.  An XSLT processor may signal the error; if it
does not signal the error, it must recover by inserting a space after
any occurrence of <code>-</code> that is followed by another
<code>-</code> or that ends the comment.</p>

</div>

<div class="div2">

<h3><a name="copying"></a>7.5 Copying</h3>


  
  
    
  
  


<p>The <code>xsl:copy</code> element provides an easy way of copying
the current node. Instantiating the <code>xsl:copy</code> element
creates a copy of the current node.  The namespace nodes of the
current node are automatically copied as well, but the attributes and
children of the node are not automatically copied.  The content of the
<code>xsl:copy</code> element is a template for the attributes and
children of the created node; the content is instantiated only for
nodes of types that can have attributes or children (i.e. root
nodes and element nodes).</p>

<p>The <code>xsl:copy</code> element may have a
<code>use-attribute-sets</code> attribute (see <a href="#attribute-sets"><b>7.1.4 Named Attribute Sets</b></a>). This is used only when copying element
nodes.</p>

<p>The root node is treated specially because the root node of the
result tree is created implicitly.  When the current node is the root
node, <code>xsl:copy</code> will not create a root node, but will just
use the content template.</p>

<p>For example, the identity transformation can be written using
<code>xsl:copy</code> as follows:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="@*|node()"&gt;
  &lt;xsl:copy&gt;
    &lt;xsl:apply-templates select="@*|node()"/&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt;</pre></div>

<p>When the current node is an attribute, then if it would be an error
to use <code>xsl:attribute</code> to create an attribute with the same
name as the current node, then it is also an error to use
<code>xsl:copy</code> (see <a href="#creating-attributes"><b>7.1.3 Creating Attributes with xsl:attribute</b></a>).</p>

<p id="diff-9">When the current node is a namespace node,
then copying it adds a namespace node to the containing node in the
result tree. It is an error if this containing node is not an element;
implementations may either signal the error or ignore the namespace
node.  It is an error to add a namespace node to an element after
children have been added to it or after attributes have been added to
it; implementations may either signal an error or ignore the namespace
node.  It is an error to add a namespace node to an element if the
element already has a namespace node with the same name, unless both
namespace nodes have the same <a href="http://www.w3.org/TR/xpath#dt-string-value">string-value</a>, in which case
the duplicate is ignored. It is an error to add a namespace node to an
element if the namespace node has a null name and the element has a
null namespace URI.</p>

<p>The following example shows how <code>xml:lang</code> attributes
can be easily copied through from source to result. If a stylesheet
defines the following named template:</p>

<div class="exampleInner"><pre>&lt;xsl:template name="apply-templates-copy-lang"&gt;
 &lt;xsl:for-each select="@xml:lang"&gt;
   &lt;xsl:copy/&gt;
 &lt;/xsl:for-each&gt;
 &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;</pre></div>

<p>then it can simply do</p>

<div class="exampleInner"><pre>&lt;xsl:call-template name="apply-templates-copy-lang"/&gt;</pre></div>

<p>instead of</p>

<div class="exampleInner"><pre>&lt;xsl:apply-templates/&gt;</pre></div>

<p>when it wants to copy the <code>xml:lang</code> attribute.</p>

</div>

<div class="div2">

<h3><a name="N5075"></a>7.6 Computing Generated Text</h3>

<p>Within a template, the <code>xsl:value-of</code> element can be
used to compute generated text, for example by extracting text from
the source tree or by inserting the value of a variable.  The
<code>xsl:value-of</code> element does this with an <a title="Expression" href="#dt-expression">expression</a> that is specified as the
value of the <code>select</code> attribute.  Expressions can
also be used inside attribute values of literal result elements by
enclosing the expression in curly braces (<code>{}</code>).</p>

<div class="div3">

<h4><a name="value-of"></a>7.6.1 Generating Text with <code>xsl:value-of</code></h4>


  
  
    
  
  
    
    
  
  


<p>The <code>xsl:value-of</code> element is instantiated to create a
text node in the result tree.  The required <code>select</code>
attribute is an <a title="Expression" href="#dt-expression">expression</a>;
this expression is evaluated and the resulting object is converted to
a string as if by a call to the string
function. The string specifies the string-value of the created text
node.  If the string is empty, no text node will be created.  The
created text node will be merged with any adjacent text nodes.</p>

<p>The <code>xsl:copy-of</code> element can be used to copy a node-set
over to the result tree without converting it to a string. See <a href="#copy-of"><b>11.3 Using Values of Variables and Parameters with
xsl:copy-of</b></a>.</p>

<p>For example, the following creates an HTML paragraph from a
<code>person</code> element with <code>given-name</code> and
<code>family-name</code> attributes.  The paragraph will contain the value
of the <code>given-name</code> attribute of the current node followed
by a space and the value of the <code>family-name</code> attribute of the
current node.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="person"&gt;
  &lt;p&gt;
   &lt;xsl:value-of select="@given-name"/&gt;
   &lt;xsl:text&gt; &lt;/xsl:text&gt;
   &lt;xsl:value-of select="@family-name"/&gt;
  &lt;/p&gt;
&lt;/xsl:template&gt;</pre></div>

<p>For another example, the following creates an HTML paragraph from a
<code>person</code> element with <code>given-name</code> and
<code>family-name</code> children elements.  The paragraph will
contain the string-value of the first <code>given-name</code> child
element of the current node followed by a space and the string-value
of the first <code>family-name</code> child element of the current
node.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="person"&gt;
  &lt;p&gt;
   &lt;xsl:value-of select="given-name"/&gt;
   &lt;xsl:text&gt; &lt;/xsl:text&gt;
   &lt;xsl:value-of select="family-name"/&gt;
  &lt;/p&gt;
&lt;/xsl:template&gt;</pre></div>

<p>The following precedes each <code>procedure</code> element with a
paragraph containing the security level of the procedure.  It assumes
that the security level that applies to a procedure is determined by a
<code>security</code> attribute on the procedure element or on an
ancestor element of the procedure. It also assumes that if more than
one such element has a <code>security</code> attribute then the
security level is determined by the element that is closest to the
procedure.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="procedure"&gt;
  &lt;fo:block&gt;
    &lt;xsl:value-of select="ancestor-or-self::*[@security][1]/@security"/&gt;
  &lt;/fo:block&gt;
  &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;</pre></div>

</div>

<div class="div3">

<h4><a name="attribute-value-templates"></a>7.6.2 Attribute Value Templates</h4>

<p>[<a name="dt-attribute-value-template" title="Attribute Value Template">Definition</a>: In an attribute value that is interpreted as an
<b>attribute value template</b>, such as an attribute of a
literal result element, an <a title="Expression" href="#dt-expression">expression</a> can be used by surrounding
the expression with curly braces (<code>{}</code>)].  The
attribute value template is instantiated by replacing the expression
together with surrounding curly braces by the result of evaluating the
expression and converting the resulting object to a string as if by a
call to the string function.  Curly braces are
not recognized in an attribute value in an XSLT stylesheet unless the
attribute is specifically stated to be one that is interpreted as an
attribute value template; in an element syntax summary, the value
of such attributes is surrounded by curly braces.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Not all attributes are interpreted as attribute value
templates.  Attributes whose value is an expression or pattern,
attributes of <a title="Top-level" href="#dt-top-level">top-level</a> elements
and attributes that refer to named XSLT objects are not interpreted as
attribute value templates. In addition, <code>xmlns</code> attributes
are not interpreted as attribute value templates; it would not be
conformant with the XML Namespaces Recommendation to do
this. The <code>xsl:output</code> element is an
exception: although it is a top-level element, its attributes are all
interpreted as attribute value templates for consistency with
<code>xsl:document</code>.</p></div>

<p>The following example creates an <code>img</code> result element
from a <code>photograph</code> element in the source; the value of the
<code>src</code> attribute of the <code>img</code> element is computed
from the value of the <code>image-dir</code> variable and the
string-value of the <code>href</code> child of the
<code>photograph</code> element; the value of the <code>width</code>
attribute of the <code>img</code> element is computed from the value
of the <code>width</code> attribute of the <code>size</code> child of
the <code>photograph</code> element:</p>

<div class="exampleInner"><pre>&lt;xsl:variable name="image-dir"&gt;/images&lt;/xsl:variable&gt;

&lt;xsl:template match="photograph"&gt;
&lt;img src="{$image-dir}/{href}" width="{size/@width}"/&gt;
&lt;/xsl:template&gt;</pre></div>

<p>With this source</p>

<div class="exampleInner"><pre>&lt;photograph&gt;
  &lt;href&gt;headquarters.jpg&lt;/href&gt;
  &lt;size width="300"/&gt;
&lt;/photograph&gt;</pre></div>

<p>the result would be</p>

<div class="exampleInner"><pre>&lt;img src="/images/headquarters.jpg" width="300"/&gt;</pre></div>

<p>When an attribute value template is instantiated, a double left or
right curly brace outside an expression will be replaced by a single
curly brace.  It is an error if a right curly brace occurs in an
attribute value template outside an expression without being followed
by a second right curly brace.  A right curly brace inside a <a href="http://www.w3.org/TR/xpath#NT-Literal">Literal</a> in an expression is not
recognized as terminating the expression.</p>

<p>Curly braces are <em>not</em> recognized recursively inside
expressions.  For example:</p>

<div class="exampleInner"><pre>&lt;a href="#{id({@ref})/title}"&gt;</pre></div>

<p>is <em>not</em> allowed.  Instead, use simply:</p>

<div class="exampleInner"><pre>&lt;a href="#{id(@ref)/title}"&gt;</pre></div>

</div>

</div>

<div class="div2">

<h3><a name="number"></a>7.7 Numbering</h3>


  
  
    
    
    
  
  
    
  
  
    
  
  
    
  
  
    
      
    
  
  
    
      
    
  
  
    
      
      
    
  
  
    
      
    
  
  
    
      
    
  
  


<p>The <code>xsl:number</code> element is used to insert a formatted
number into the result tree.  The number to be inserted may be
specified by an expression. The <code>value</code> attribute contains
an <a title="Expression" href="#dt-expression">expression</a>.  The expression
is evaluated and the resulting object is converted to a number as if
by a call to the number function.  It is an error if the number is NaN, infinite
or less than 0.5; an XSLT processor may signal the error; if it does
not signal the error, it must recover by converting the number to a
string as if by a call to the string function
and inserting the resulting string into the result tree.
Otherwise, the number is
rounded to an integer and then converted to a string using the
attributes specified in <a href="#convert"><b>7.7.1 Number to String Conversion Attributes</b></a>; in this
context, the value of each of these attributes is
interpreted as an <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute
value template</a>.  After conversion, the resulting string is
inserted in the result tree. For example, the following example
numbers a sorted list:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="items"&gt;
  &lt;xsl:for-each select="item"&gt;
    &lt;xsl:sort select="."/&gt;
    &lt;p&gt;
      &lt;xsl:number value="position()" format="1. "/&gt;
      &lt;xsl:value-of select="."/&gt;
    &lt;/p&gt;
  &lt;/xsl:for-each&gt;
&lt;/xsl:template&gt;</pre></div>

<p>If no <code>value</code> attribute is specified, then the
<code>xsl:number</code> element inserts a number based on the position
of the current node in the source tree. The following attributes
control how the current node is to be numbered:</p>

<ul>

<li><p>The <code>level</code> attribute specifies what levels of the
source tree should be considered; it has the values
<code>single</code>, <code>multiple</code> or <code>any</code>. The
default is <code>single</code>.</p></li>

<li><p>The <code>count</code> attribute is a pattern that specifies
what nodes should be counted at those levels.  If <code>count</code>
attribute is not specified, then it defaults to the pattern that
matches any node with the same node type as the current node and, if
the current node has an expanded-name, with the same expanded-name as
the current node.</p></li>

<li><p>The <code>from</code> attribute is a pattern that specifies
where counting starts.</p></li>

</ul>

<p>In addition, the attributes specified in <a href="#convert"><b>7.7.1 Number to String Conversion Attributes</b></a>
are used for number to string conversion, as in the case when the
<code>value</code> attribute is specified.</p>

<p>The <code>xsl:number</code> element first constructs a list of
positive integers using the <code>level</code>, <code>count</code> and
<code>from</code> attributes:</p>

<ul>

<li><p>When <code>level="single"</code>, it goes up to the first
node in the ancestor-or-self axis that matches
the <code>count</code> pattern, and constructs a list of length one
containing one plus the number of preceding siblings of that ancestor
that match the <code>count</code> pattern. If there is no such
ancestor, it constructs an empty list.  If the <code>from</code>
attribute is specified, then the only ancestors that are searched are
those that are descendants of the nearest ancestor that matches the
<code>from</code> pattern. Preceding siblings has the same meaning
here as with the <code>preceding-sibling</code> axis.</p></li>

<li><p>When <code>level="multiple"</code>, it constructs a list of all
ancestors of the current node in document order followed by the
element itself; it then selects from the list those nodes that match
the <code>count</code> pattern; it then maps each node in the list to
one plus the number of preceding siblings of that node that match the
<code>count</code> pattern.  If the <code>from</code> attribute is
specified, then the only ancestors that are searched are those that
are descendants of the nearest ancestor that matches the
<code>from</code> pattern. Preceding siblings has the same meaning
here as with the <code>preceding-sibling</code> axis.</p></li>

<li><p>When <code>level="any"</code>, it constructs a list of length
one containing the number of nodes that match the <code>count</code>
pattern and belong to the set containing the current node and all
nodes at any level of the document that are before the current node in
document order, excluding any namespace and attribute nodes (in other
words the union of the members of the <code>preceding</code> and
<code>ancestor-or-self</code> axes).
If there are no matching nodes, it constructs an empty list.
If the <code>from</code> attribute is specified, then only nodes after
the first node before the current node that match the
<code>from</code> pattern are considered.</p></li>

</ul>

<p>The list of numbers is then converted into a string using the
attributes specified in <a href="#convert"><b>7.7.1 Number to String Conversion Attributes</b></a>; in this
context, the value of each of these attributes is
interpreted as an <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute
value template</a>.  After conversion, the resulting string is
inserted in the result tree.</p>

<p>The following would number the items in an ordered list:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="ol/item"&gt;
  &lt;fo:block&gt;
    &lt;xsl:number/&gt;&lt;xsl:text&gt;. &lt;/xsl:text&gt;&lt;xsl:apply-templates/&gt;
  &lt;/fo:block&gt;
&lt;xsl:template&gt;</pre></div>

<p>The following two rules would number <code>title</code> elements.
This is intended for a document that contains a sequence of chapters
followed by a sequence of appendices, where both chapters and
appendices contain sections, which in turn contain subsections.
Chapters are numbered 1, 2, 3; appendices are numbered A, B, C;
sections in chapters are numbered 1.1, 1.2, 1.3; sections in
appendices are numbered A.1, A.2, A.3.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="title"&gt;
  &lt;fo:block&gt;
     &lt;xsl:number level="multiple"
                 count="chapter|section|subsection"
                 format="1.1 "/&gt;
     &lt;xsl:apply-templates/&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="appendix//title" priority="1"&gt;
  &lt;fo:block&gt;
     &lt;xsl:number level="multiple"
                 count="appendix|section|subsection"
                 format="A.1 "/&gt;
     &lt;xsl:apply-templates/&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;</pre></div>

<p>The following example numbers notes sequentially within a
chapter:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="note"&gt;
  &lt;fo:block&gt;
     &lt;xsl:number level="any" from="chapter" format="(1) "/&gt;
     &lt;xsl:apply-templates/&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;</pre></div>

<p>The following example would number <code>H4</code> elements in HTML
with a three-part label:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="H4"&gt;
 &lt;fo:block&gt;
   &lt;xsl:number level="any" from="H1" count="H2"/&gt;
   &lt;xsl:text&gt;.&lt;/xsl:text&gt;
   &lt;xsl:number level="any" from="H2" count="H3"/&gt;
   &lt;xsl:text&gt;.&lt;/xsl:text&gt;
   &lt;xsl:number level="any" from="H3" count="H4"/&gt;
   &lt;xsl:text&gt; &lt;/xsl:text&gt;
   &lt;xsl:apply-templates/&gt;
 &lt;/fo:block&gt;
&lt;/xsl:template&gt;</pre></div>

<div class="div3">

<h4><a name="convert"></a>7.7.1 Number to String Conversion Attributes</h4>

<p>The following attributes are used to control conversion of a list
of numbers into a string. The numbers are integers greater than
0. The attributes are all optional.</p>

<p>The main attribute is <code>format</code>.  The default value for
the <code>format</code> attribute is <code>1</code>.  The
<code>format</code> attribute is split into a sequence of tokens where
each token is a maximal sequence of alphanumeric characters or a
maximal sequence of non-alphanumeric characters.  Alphanumeric means
any character that has a Unicode category of Nd, Nl, No, Lu, Ll, Lt,
Lm or Lo.  The alphanumeric tokens (format tokens) specify the format
to be used for each number in the list.  If the first token is a
non-alphanumeric token, then the constructed string will start with
that token; if the last token is non-alphanumeric token, then the
constructed string will end with that token.  Non-alphanumeric tokens
that occur between two format tokens are separator tokens that are
used to join numbers in the list.  The <var>n</var>th format token
will be used to format the <var>n</var>th number in the list.  If
there are more numbers than format tokens, then the last format token
will be used to format remaining numbers.  If there are no format
tokens, then a format token of <code>1</code> is used to format all
numbers.  The format token specifies the string to be used to
represent the number 1.  Each number after the first will be separated
from the preceding number by the separator token preceding the format
token used to format that number, or, if there are no separator
tokens, then by <code>.</code> (a period character).</p>

<p>Format tokens are a superset of the allowed values for the
<code>type</code> attribute for the <code>OL</code> element in HTML
4.0 and are interpreted as follows:</p>

<ul>

<li><p>Any token where the last character has a decimal digit value
of 1 (as specified in the Unicode character property database),
and the Unicode value of preceding characters is one less than the
Unicode value of the last character generates a decimal
representation of the number where each number is at least as long as
the format token.  Thus, a format token <code>1</code> generates the
sequence <code>1 2 ... 10 11 12 ...</code>, and a format token
<code>01</code> generates the sequence <code>01 02 ... 09 10 11 12
... 99 100 101</code>.</p></li>

<li><p>A format token <code>A</code> generates the sequence <code>A
B C ... Z AA AB AC...</code>.</p></li>

<li><p>A format token <code>a</code> generates the sequence <code>a
b c ... z aa ab ac...</code>.</p></li>

<li><p>A format token <code>i</code> generates the sequence <code>i
ii iii iv v vi vii viii ix x ...</code>.</p></li>

<li><p>A format token <code>I</code> generates the sequence <code>I
II III IV V VI VII VIII IX X ...</code>.</p></li>

<li><p>Any other format token indicates a numbering sequence that
starts with that token.  If an implementation does not support a
numbering sequence that starts with that token, it must use a format
token of <code>1</code>.</p></li>

</ul>

<p>When numbering with an alphabetic sequence, the <code>lang</code>
attribute specifies which language's alphabet is to be used; it has
the same range of values as <code>xml:lang</code> <a href="#XML">[XML]</a>;
if no <code>lang</code> value is specified, the language should be
determined from the system environment.  Implementers should document
for which languages they support numbering.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Implementers should not make any assumptions about how
numbering works in particular languages and should properly research
the languages that they wish to support.  The numbering conventions of
many languages are very different from English.</p></div>

<p>The <code>letter-value</code> attribute disambiguates between
numbering sequences that use letters.  In many languages there are two
commonly used numbering sequences that use letters.  One numbering
sequence assigns numeric values to letters in alphabetic sequence, and
the other assigns numeric values to each letter in some other manner
traditional in that language.  In English, these would correspond to
the numbering sequences specified by the format tokens <code>a</code>
and <code>i</code>.  In some languages, the first member of each
sequence is the same, and so the format token alone would be
ambiguous.  A value of <code>alphabetic</code> specifies the
alphabetic sequence; a value of <code>traditional</code> specifies the
other sequence.  If the <code>letter-value</code> attribute is not
specified, then it is implementation-dependent how any ambiguity is
resolved.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>It is possible for two conforming XSLT processors not to
convert a number to exactly the same string.  Some XSLT processors may not
support some languages.  Furthermore, there may be variations possible
in the way conversions are performed for any particular language that
are not specifiable by the attributes on <code>xsl:number</code>.
Future versions of XSLT may provide additional attributes to provide
control over these variations.  Implementations may also use
implementation-specific namespaced attributes on
<code>xsl:number</code> for this.</p></div>

<p>The <code>grouping-separator</code> attribute gives the separator
used as a grouping (e.g. thousands) separator in decimal numbering
sequences, and the optional <code>grouping-size</code> specifies the
size (normally 3) of the grouping.  For example,
<code>grouping-separator=","</code> and <code>grouping-size="3"</code>
would produce numbers of the form <code>1,000,000</code>.  If only one
of the <code>grouping-separator</code> and <code>grouping-size</code>
attributes is specified, then it is ignored.</p>

<p>Here are some examples of conversion specifications:</p>

<ul>

<li><p><code>format="&amp;#x30A2;"</code> specifies Katakana
numbering</p></li>

<li><p><code>format="&amp;#x30A4;"</code> specifies Katakana
numbering in the "iroha" order</p></li>

<li><p><code>format="&amp;#x0E51;"</code> specifies numbering with
Thai digits</p></li>

<li><p><code>format="&amp;#x05D0;" letter-value="traditional"</code>
specifies "traditional" Hebrew numbering</p></li>

<li><p><code>format="&amp;#x10D0;" letter-value="traditional"</code>
specifies Georgian numbering</p></li>

<li><p><code>format="&amp;#x03B1;" letter-value="traditional"</code>
specifies "classical" Greek numbering</p></li>

<li><p><code>format="&amp;#x0430;" letter-value="traditional"</code>
specifies Old Slavic numbering</p></li>

</ul>

</div>
</div>
</div>

<div class="div1">


<h2><a name="for-each"></a>8 Repetition</h2>


  
  
    
  
  
    
    
  


<p>When the result has a known regular structure, it is useful to be
able to specify directly the template for selected nodes.  The
<code>xsl:for-each</code> instruction contains a template, which is
instantiated for each node selected by the <a title="Expression" href="#dt-expression">expression</a> specified by the
<code>select</code> attribute. The <code>select</code> attribute is
required.  The expression must evaluate to a node-set.  The template
is instantiated with the selected node as the <a title="Current Node" href="#dt-current-node">current node</a>, and with a list of all
of the selected nodes as the <a title="Current Node List" href="#dt-current-node-list">current node list</a>.  The nodes are
processed in document order, unless a sorting specification is present
(see <a href="#sorting"><b>10 Sorting</b></a>).</p>

<p>For example, given an XML document with this structure</p>

<div class="exampleInner"><pre>&lt;customers&gt;
  &lt;customer&gt;
    &lt;name&gt;...&lt;/name&gt;
    &lt;order&gt;...&lt;/order&gt;
    &lt;order&gt;...&lt;/order&gt;
  &lt;/customer&gt;
  &lt;customer&gt;
    &lt;name&gt;...&lt;/name&gt;
    &lt;order&gt;...&lt;/order&gt;
    &lt;order&gt;...&lt;/order&gt;
  &lt;/customer&gt;
&lt;/customers&gt;</pre></div>

<p>the following would create an HTML document containing a table with
a row for each <code>customer</code> element</p>

<div class="exampleInner"><pre>&lt;xsl:template match="/"&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Customers&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;table&gt;
	&lt;tbody&gt;
	  &lt;xsl:for-each select="customers/customer"&gt;
	    &lt;tr&gt;
	      &lt;th&gt;
		&lt;xsl:apply-templates select="name"/&gt;
	      &lt;/th&gt;
	      &lt;xsl:for-each select="order"&gt;
		&lt;td&gt;
		  &lt;xsl:apply-templates/&gt;
		&lt;/td&gt;
	      &lt;/xsl:for-each&gt;
	    &lt;/tr&gt;
	  &lt;/xsl:for-each&gt;
	&lt;/tbody&gt;
      &lt;/table&gt;
    &lt;/body&gt;
  &lt;/html&gt;
&lt;/xsl:template&gt;</pre></div>

</div>

<div class="div1">

<h2><a name="N6058"></a>9 Conditional Processing</h2>

<p>There are two instructions in XSLT that support conditional
processing in a template: <code>xsl:if</code> and
<code>xsl:choose</code>. The <code>xsl:if</code> instruction provides
simple if-then conditionality; the <code>xsl:choose</code> instruction
supports selection of one choice when there are several
possibilities.</p>

<div class="div2">

<h3><a name="N6078"></a>9.1 Conditional Processing with <code>xsl:if</code></h3>


  
  
    
  
  


<p>The <code>xsl:if</code> element has a <code>test</code> attribute,
which specifies an <a title="Expression" href="#dt-expression">expression</a>.
The content is a template.  The expression is evaluated and the
resulting object is converted to a boolean as if by a call to the
boolean function.  If the result is true, then
the content template is instantiated; otherwise, nothing is created.
In the following example, the names in a group of names are formatted
as a comma separated list:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="namelist/name"&gt;
  &lt;xsl:apply-templates/&gt;
  &lt;xsl:if test="not(position()=last())"&gt;, &lt;/xsl:if&gt;
&lt;/xsl:template&gt;</pre></div>

<p>The following colors every other table row yellow:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="item"&gt;
  &lt;tr&gt;
    &lt;xsl:if test="position() mod 2 = 0"&gt;
       &lt;xsl:attribute name="bgcolor"&gt;yellow&lt;/xsl:attribute&gt;
    &lt;/xsl:if&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/tr&gt;
&lt;/xsl:template&gt;</pre></div>

</div>


<div class="div2">

<h3><a name="N6137"></a>9.2 Conditional Processing with <code>xsl:choose</code></h3>


  
  
    
    
  



  
    
  
  



  


<p>The <code>xsl:choose</code> element selects one among a number of
possible alternatives. It consists of a sequence of
<code>xsl:when</code> elements followed by an optional
<code>xsl:otherwise</code> element.  Each <code>xsl:when</code>
element has a single attribute, <code>test</code>, which specifies an
<a title="Expression" href="#dt-expression">expression</a>. The content of the
<code>xsl:when</code> and <code>xsl:otherwise</code> elements is a
template.  When an <code>xsl:choose</code> element is processed, each
of the <code>xsl:when</code> elements is tested in turn, by evaluating
the expression and converting the resulting object to a boolean as if
by a call to the boolean function.  The content
of the first, and only the first, <code>xsl:when</code> element whose
test is true is instantiated.  If no <code>xsl:when</code> is true,
the content of the <code>xsl:otherwise</code> element is
instantiated. If no <code>xsl:when</code> element is true, and no
<code>xsl:otherwise</code> element is present, nothing is created.</p>

<p>The following example enumerates items in an ordered list using
arabic numerals, letters, or roman numerals depending on the depth to
which the ordered lists are nested.</p>

<div class="exampleInner"><pre>&lt;xsl:template match="orderedlist/listitem"&gt;
  &lt;fo:list-item indent-start='2pi'&gt;
    &lt;fo:list-item-label&gt;
      &lt;xsl:variable name="level"
                    select="count(ancestor::orderedlist) mod 3"/&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test='$level=1'&gt;
          &lt;xsl:number format="i"/&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:when test='$level=2'&gt;
          &lt;xsl:number format="a"/&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;xsl:number format="1"/&gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
      &lt;xsl:text&gt;. &lt;/xsl:text&gt;
    &lt;/fo:list-item-label&gt;
    &lt;fo:list-item-body&gt;
      &lt;xsl:apply-templates/&gt;
    &lt;/fo:list-item-body&gt;
  &lt;/fo:list-item&gt;
&lt;/xsl:template&gt;</pre></div>

</div>
</div>

<div class="div1">

<h2><a name="sorting"></a>10 Sorting</h2>


  
    
  
  
    
      
    
  
  
    
       
       
       
    
  
  
    
       
       
    
  
  
    
       
       
    
  
  


<p>Sorting is specified by adding <code>xsl:sort</code> elements as
children of an <code>xsl:apply-templates</code> or
<code>xsl:for-each</code> element.  The first <code>xsl:sort</code>
child specifies the primary sort key, the second <code>xsl:sort</code>
child specifies the secondary sort key and so on.  When an
<code>xsl:apply-templates</code> or <code>xsl:for-each</code> element
has one or more <code>xsl:sort</code> children, then instead of
processing the selected nodes in document order, it sorts the nodes
according to the specified sort keys and then processes them in sorted
order.  When used in <code>xsl:for-each</code>, <code>xsl:sort</code>
elements must occur first.  When a template is instantiated by
<code>xsl:apply-templates</code> and <code>xsl:for-each</code>, the
<a title="Current Node List" href="#dt-current-node-list">current node list</a>
consists of the complete list of nodes being processed in sorted
order.</p>

<p><code>xsl:sort</code> has a <code>select</code> attribute whose
value is an <a title="Expression" href="#dt-expression">expression</a>. For
each node to be processed, the expression is evaluated with that node
as the current node and with the complete list of nodes being
processed in document
order as the current node list.
The resulting object is converted to a string as
if by a call to the string function; this string
is used as the sort key for that node. The default value of the
<code>select</code> attribute is <code>.</code>, which will cause the
string-value of the current node to be used as the sort key.</p>

<p>This string serves as a sort key for the node.  The following
optional attributes on <code>xsl:sort</code> control how the list of
sort keys are sorted; the values of all of these attributes are
interpreted as <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute
value templates</a>.</p>

<ul>

<li><p><code>order</code> specifies whether the strings should be
sorted in ascending or descending order; <code>ascending</code>
specifies ascending order; <code>descending</code> specifies
descending order; the default is <code>ascending</code></p></li>

<li><p><code>lang</code> specifies the language of the sort keys; it
has the same range of values as <code>xml:lang</code> <a href="#XML">[XML]</a>; if no <code>lang</code> value is specified, the language
should be determined from the system environment</p></li>

<li><p><code>data-type</code> specifies the data type of the
strings; the following values are allowed:</p>

<ul>

<li><p><code>text</code> specifies that the sort keys should be
sorted lexicographically in the culturally correct manner for the
language specified by <code>lang</code></p></li>

<li><p><code>number</code> specifies that the sort keys should be
converted to numbers and then sorted according to the numeric value;
the sort key is converted to a number as if by a call to the
number function; the <code>lang</code>
attribute is ignored; in ascending order
a NaN precedes all other numeric values and in descending
order it follows them</p></li>

<li><p>a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> with a prefix
is expanded into an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> as described
in <a href="#qname"><b>2.4 Qualified Names</b></a>; the expanded-name identifies the data-type;
the behavior in this case is not specified by this document</p></li>

</ul>

<p>The default value is <code>text</code>.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>The XSL Working Group plans that future versions of XSLT will
leverage XML Schemas to define further values for this
attribute.</p></div>

</li>

<li><p><code>case-order</code> has the value
<code>upper-first</code> or <code>lower-first</code>; this applies
when <code>data-type="text"</code>, and specifies that in ascending order upper-case
letters should sort before lower-case letters or vice-versa
respectively. For example, if <code>lang="en"</code>, then <code>A a B
b</code> are sorted in ascending
order with <code>case-order="upper-first"</code> and <code>a
A b B</code> are sorted  in ascending
order with <code>case-order="lower-first"</code>. In descending order, the effect is
reversed. For example, if <code>lang="en"</code>, then <code>b B a
A</code> are sorted in descending order with
<code>case-order="upper-first"</code>. The default value is
language dependent.</p></li>

</ul>

<div class="note"><p class="prefix"><b>Note:</b></p><p>It is possible for two conforming XSLT processors not to sort
exactly the same.  Some XSLT processors may not support some
languages.  Furthermore, there may be variations possible in the
sorting of any particular language that are not specified by the
attributes on <code>xsl:sort</code>, for example, whether Hiragana or
Katakana is sorted first in Japanese.  Future versions of XSLT may
provide additional attributes to provide control over these
variations.  Implementations may also use implementation-specific
namespaced attributes on <code>xsl:sort</code> for this.</p></div>

<div class="note"><p class="prefix"><b>Note:</b></p><p>It is recommended that implementers consult <a href="#UNICODE-TR10">[UNICODE TR10]</a> for information on internationalized
sorting.</p></div>

<p>The sort must be stable: in the sorted list of nodes, any sub list
that has sort keys that all compare equal must be in document
order.</p>

<p>For example, suppose an employee database has the form</p>

<div class="exampleInner"><pre>&lt;employees&gt;
  &lt;employee&gt;
    &lt;name&gt;
      &lt;given&gt;James&lt;/given&gt;
      &lt;family&gt;Clark&lt;/family&gt;
    &lt;/name&gt;
    ...
  &lt;/employee&gt;
&lt;/employees&gt;
</pre></div>
  
<p>Then a list of employees sorted by name could be generated
using:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="employees"&gt;
  &lt;ul&gt;
    &lt;xsl:apply-templates select="employee"&gt;
      &lt;xsl:sort select="name/family"/&gt;
      &lt;xsl:sort select="name/given"/&gt;
    &lt;/xsl:apply-templates&gt;
  &lt;/ul&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="employee"&gt;
  &lt;li&gt;
    &lt;xsl:value-of select="name/given"/&gt;
    &lt;xsl:text&gt; &lt;/xsl:text&gt;
    &lt;xsl:value-of select="name/family"/&gt;
  &lt;/li&gt;
&lt;/xsl:template&gt;</pre></div>

</div>

<div class="div1">

<h2><a name="variables"></a>11 Variables and Parameters</h2>


  
  
  
    
  
  
    
  
  



  
  
    
  
  
    
  
  


<p>A variable is a name that may be bound to a value.  The value to
which a variable is bound (the <b>value</b> of the variable) can
be an object of any of the types that can be returned by expressions.
There are two elements that can be used to bind variables:
<code>xsl:variable</code> and <code>xsl:param</code>. The difference
is that the value specified on the <code>xsl:param</code> variable is
only a default value for the binding; when the template or stylesheet
within which the <code>xsl:param</code> element occurs is invoked,
parameters may be passed that are used in place of the default
values.</p>

<p>Both <code>xsl:variable</code> and <code>xsl:param</code> have a
required <code>name</code> attribute, which specifies the name of the
variable.  The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>, which is expanded as described
in <a href="#qname"><b>2.4 Qualified Names</b></a>.</p>

<p>For any use of these variable-binding elements, there is a region
of the stylesheet tree within which the binding is visible.  The set
of variable bindings in scope for an expression consists of those
bindings that are visible at the point in the stylesheet where the
expression occurs.</p>

<div class="div2">

<h3><a name="N6743"></a>11.1 Result Tree Fragments</h3>

<div class="note"><p class="prefix"><b>Note:</b></p><p>The result tree fragment data-type has been removed
in XSLT 1.1.</p></div>

</div>
 
<div class="div2">

<h3><a name="variable-values"></a>11.2 Values of Variables and Parameters</h3>

<p>A variable-binding element can specify the value of the variable in
three alternative ways.</p>

<ul>

<li><p>If the variable-binding element has a <code>select</code>
attribute, then the value of the attribute must be an <a title="Expression" href="#dt-expression">expression</a> and the value of the variable
is the object that results from evaluating the expression.  In this
case, the content must be empty.</p></li>

<li>

<p>If the variable-binding element does not have a <code>select</code>
attribute and has non-empty content (i.e. the variable-binding element
has one or more child nodes), then the content of the
variable-binding element specifies the value. The content of the
variable-binding element is a template; a new
document is constructed with a root node having as its children
the sequence of nodes that results from instantiating this template;
<a title="Namespace Fixup" href="#dt-namespace-fixup">namespace fixup</a> is
performed on this document (see <a href="#namespace-fixup"><b>3.5 Namespace Fixup</b></a>); the
value of the variable is a node-set that contains just the root node
of this newly constructed document.</p>

<p>The base URI of a node in this document is determined as
if all the nodes in the document came from a single entity whose URI
was the base URI of the variable-binding element (see <a href="#base-uri"><b>3.2 Base URI</b></a>). Thus, the base URI of the root node will be equal
to the base URI of the variable-binding element; an
<code>xml:base</code> attribute within this document will change the
base URI for its parent element and that element's descendants, just
as it would within a document constructed by parsing.</p>

<p>It is an error if a member of the sequence of nodes created by
instantiating the template is an attribute node or a namespace node,
since a root node cannot have an attribute node or a namespace node as
a child. An XSLT processor may signal the error; if it does not signal
the error, it must recover by not adding the attribute node or
namespace node.</p>

</li>

<li>

<p>If the variable-binding element has empty content and does not have
a <code>select</code> attribute, then the value of the variable is an
empty string. Thus</p>

<div class="exampleInner"><pre>&lt;xsl:variable name="x"/&gt;</pre></div>

<p>is equivalent to</p>

<div class="exampleInner"><pre>&lt;xsl:variable name="x" select="''"/&gt;</pre></div>

</li>

</ul>

<div class="note"><p class="prefix"><b>Note:</b></p><p>When a variable is used to select nodes by position, be careful
not to do:</p>

<div class="exampleInner"><pre>&lt;xsl:variable name="n"&gt;2&lt;/xsl:variable&gt;
...
&lt;xsl:value-of select="item[$n]"/&gt;</pre></div>

<p>This will output the value of the first item element, because the
variable <code>n</code> will be bound to a node-set, not a number. Instead, do either</p>

<div class="exampleInner"><pre>&lt;xsl:variable name="n" select="2"/&gt;
...
&lt;xsl:value-of select="item[$n]"/&gt;</pre></div>

<p>or</p>

<div class="exampleInner"><pre>&lt;xsl:variable name="n"&gt;2&lt;/xsl:variable&gt;
...
&lt;xsl:value-of select="item[position()=$n]"/&gt;</pre></div>
</div>

<div class="note"><p class="prefix"><b>Note:</b></p><p>One convenient way to specify the empty node-set as the default
value of a parameter is:</p>

<div class="exampleInner"><pre>&lt;xsl:param name="x" select="/.."/&gt;</pre></div>
</div>

</div>

<div class="div2">

<h3><a name="copy-of"></a>11.3 Using Values of Variables and Parameters with
<code>xsl:copy-of</code></h3>


  
  
    
  
  


<p>The <code>xsl:copy-of</code> element can be used to insert a
node-set into the result tree, without
first converting it to a string as <code>xsl:value-of</code> does (see
<a href="#value-of"><b>7.6.1 Generating Text with xsl:value-of</b></a>).  The required <code>select</code>
attribute contains an <a title="Expression" href="#dt-expression">expression</a>.  When the
result of evaluating the expression is a node-set, all the
nodes in the set are copied in document order into the result tree;
copying an element node copies the attribute nodes, namespace nodes
and children of the element node as well as the element node itself; a
root node is copied by copying its children. For copying an attribute or namespace node, the same
rules apply as with <code>xsl:copy</code> (see <a href="#copying"><b>7.5 Copying</b></a>). When the result is not a
node-set, the result is converted to a string and then
inserted into the result tree, as with <code>xsl:value-of</code>.</p>

</div>

<div class="div2">

<h3><a name="top-level-variables"></a>11.4 Top-level Variables and Parameters</h3>

<p>Both <code>xsl:variable</code> and <code>xsl:param</code> are
allowed as <a title="Top-level" href="#dt-top-level">top-level</a> elements.
A top-level variable-binding element declares a global variable that
is visible everywhere (except where it
is <a title="Shadows" href="#dt-shadows">shadowed</a> by another
binding).  A top-level <code>xsl:param</code> element
declares a parameter to the stylesheet; XSLT does not define the
mechanism by which parameters are passed to the stylesheet. If a stylesheet contains more than one
binding for a variable of a particular name, then the binding with the
highest <a title="Import Precedence" href="#dt-import-precedence">import
precedence</a> is used. It is an
error if a stylesheet contains more than one binding of a top-level
variable with the same name and same <a title="Import Precedence" href="#dt-import-precedence">import precedence</a>. At the
top-level, the expression or template specifying the variable value is
evaluated with the same context as that used to process the root node
of the source document: the current node is the root node of the
source document and the current node list is a list containing just
the root node of the source document.  If the template or expression
specifying the value of a global variable <var>x</var> references a
global variable <var>y</var>, then the value for <var>y</var> must
be computed before the value of <var>x</var>.  It is an error if it
is impossible to do this for all global variable definitions; in other
words, it is an error if the definitions are circular.</p>

<p>This example declares a global variable <code>para-font-size</code>,
which it references in an attribute value template.</p>

<div class="exampleInner"><pre>&lt;xsl:variable name="para-font-size"&gt;12pt&lt;/xsl:variable&gt;

&lt;xsl:template match="para"&gt;
 &lt;fo:block font-size="{$para-font-size}"&gt;
   &lt;xsl:apply-templates/&gt;
 &lt;/fo:block&gt;
&lt;/xsl:template&gt;
</pre></div>

</div>

<div class="div2">

<h3><a name="local-variables"></a>11.5 Variables and Parameters within Templates</h3>

<p>As well as being allowed at the top-level, both
<code>xsl:variable</code> and <code>xsl:param</code> are also
allowed in templates.  <code>xsl:variable</code> is allowed anywhere
within a template that an instruction is allowed.  In this case, the
binding is visible for all following siblings and their descendants.
Note that the binding is not visible for the <code>xsl:variable</code>
element itself.  <code>xsl:param</code> is allowed as a child
at the beginning of an <code>xsl:template</code> element.  In this
context, the binding is visible for all following siblings and their
descendants.  Note that the binding is not visible for the
<code>xsl:param</code> element itself.</p>

<p>[<a name="dt-shadows" title="Shadows">Definition</a>: A binding
<b>shadows</b> another binding if the binding occurs at a point
where the other binding is visible, and the bindings have the same
name.] It is an error if a binding established by an
<code>xsl:variable</code> or <code>xsl:param</code> element within a
template <a title="Shadows" href="#dt-shadows">shadows</a> another binding
established by an <code>xsl:variable</code> or <code>xsl:param</code>
element also within the template.  It is not an error if a binding
established by an <code>xsl:variable</code> or <code>xsl:param</code>
element in a template <a title="Shadows" href="#dt-shadows">shadows</a>
another binding established by an <code>xsl:variable</code> or
<code>xsl:param</code> <a title="Top-level" href="#dt-top-level">top-level</a>
element. In this case, the top-level
binding will not be visible in the region of the stylesheet where it
is shadowed by the other binding. Thus, the following is an
error:</p>

<div class="exampleInner"><pre>&lt;xsl:template name="foo"&gt;
&lt;xsl:param name="x" select="1"/&gt;
&lt;xsl:variable name="x" select="2"/&gt;
&lt;/xsl:template&gt;</pre></div>

<p>However, the following is allowed:</p>

<div class="exampleInner"><pre>&lt;xsl:param name="x" select="1"/&gt;
&lt;xsl:template name="foo"&gt;
&lt;xsl:variable name="x" select="2"/&gt;
&lt;/xsl:template&gt;</pre></div>

<div class="note"><p class="prefix"><b>Note:</b></p><p>The nearest equivalent in Java to an <code>xsl:variable</code>
element in a template is a final local variable declaration with an
initializer.  For example,</p>

<div class="exampleInner"><pre>&lt;xsl:variable name="x" select="'value'"/&gt;</pre></div>

<p>has similar semantics to</p>

<div class="exampleInner"><pre>final Object x = "value";</pre></div>

<p>XSLT does not provide an equivalent to the Java assignment operator</p>

<div class="exampleInner"><pre>x = "value";</pre></div>

<p>because this would make it harder to create an implementation that
processes a document other than in a batch-like way, starting at the
beginning and continuing through to the end.</p></div>

</div>

<div class="div2">

<h3><a name="with-param"></a>11.6 Passing Parameters to Templates</h3>


  
    
  
  
    
  
  


<p>Parameters are passed to templates using the
<code>xsl:with-param</code> element.  The required <code>name</code>
attribute specifies the name of the parameter (the variable the value
of whose binding is to be replaced).  The value of the
<code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>, which is expanded as described
in <a href="#qname"><b>2.4 Qualified Names</b></a>.  <code>xsl:with-param</code> is allowed
within
<code>xsl:call-template</code>,
<code>xsl:apply-templates</code> and
<code>xsl:apply-imports</code>.
It is an error if a single <code>xsl:call-template</code>,
<code>xsl:apply-templates</code> or <code>xsl:apply-imports</code>
element contains more than one <code>xsl:with-param</code> element
with the same name.
The value of the parameter is
specified in the same way as for <code>xsl:variable</code> and
<code>xsl:param</code>.  The current node and current node list used
for computing the value specified by <code>xsl:with-param</code>
element is the same as that used for the
<code>xsl:apply-templates</code>,
<code>xsl:apply-imports</code>, or
<code>xsl:call-template</code>
element within which it occurs.  It is not an error to pass a
parameter <var>x</var> to a template that does not have an
<code>xsl:param</code> element for <var>x</var>; the parameter is
simply ignored.</p>

<p>This example defines a named template for a
<code>numbered-block</code> with an argument to control the format of
the number.</p>

<div class="exampleInner"><pre>&lt;xsl:template name="numbered-block"&gt;
  &lt;xsl:param name="format"&gt;1. &lt;/xsl:param&gt;
  &lt;fo:block&gt;
    &lt;xsl:number format="{$format}"/&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="ol//ol/li"&gt;
  &lt;xsl:call-template name="numbered-block"&gt;
    &lt;xsl:with-param name="format"&gt;a. &lt;/xsl:with-param&gt;
  &lt;/xsl:call-template&gt;
&lt;/xsl:template&gt;</pre></div>

</div>

</div>

<div class="div1">

<h2><a name="add-func"></a>12 Additional Functions</h2>

<p>This section describes XSLT-specific additions to the core XPath
function library.  Some of these additional functions also make use of
information specified by <a title="Top-level" href="#dt-top-level">top-level</a>
elements in the stylesheet; this section also describes these
elements.</p>

<div class="div2">


<h3><a name="document"></a>12.1 Multiple Source Documents</h3>

<p><em>node-set</em> <b>document</b>(<var>object</var>
, <var>node-set</var>?)</p>

<p>The <code>document</code> function allows
access to XML documents other than the main source document.</p>

<p>When the <code>document</code> function has exactly one
argument and the argument is a node-set, then the result is the union,
for each node in the argument node-set, of the result of calling the
<code>document</code> function with the first argument being
the <a href="http://www.w3.org/TR/xpath#dt-string-value">string-value</a>
of the node, and the second argument being a node-set with the node as
its only member. When the <code>document</code> function has
two arguments and the first argument is a node-set, then the result is
the union, for each node in the argument node-set, of the result of
calling the <code>document</code> function with the first
argument being the <a href="http://www.w3.org/TR/xpath#dt-string-value">string-value</a> of the node,
and with the second argument being the second argument passed to the
<code>document</code> function.</p>

<p>When the first argument to the <code>document</code>
function is not a node-set, the first argument is converted to a
string as if by a call to the string function.
This string is treated as a URI reference; the resource identified by
the URI is retrieved. The data resulting from the retrieval action is
parsed as an XML document and a tree is constructed in accordance with
the data model (see <a href="#data-model"><b>3 Data Model</b></a>).  If there is an
error retrieving the resource, then the XSLT processor may signal an
error; if it does not signal an error, it must recover by returning an
empty node-set.  One possible kind of retrieval error is that the XSLT
processor does not support the URI scheme used by the URI.  An XSLT
processor is not required to support any particular URI schemes.  The
documentation for an XSLT processor should specify which URI schemes
the XSLT processor supports.</p>

<p>If the URI reference does not contain a fragment identifier, then a
node-set containing just the root node of the document is returned.
If the URI reference does contain a fragment identifier, the function
returns a node-set containing the nodes in the tree identified by the
fragment identifier of the URI reference. The semantics of the
fragment identifier are
dependent on the media type of the result of retrieving the URI.  If
there is an error in processing the fragment identifier, the XSLT
processor may signal the error; if it does not signal the error, it
must recover by returning an empty node-set.  Possible errors
include:</p>

<ul>

<li><p>The fragment identifier identifies something that cannot be
represented by an XSLT node-set (such as a range of characters within
a text node).</p></li>

<li><p>The XSLT processor does not support fragment identifiers for
the media-type of the retrieval result.  An XSLT processor is not
required to support any particular media types.  The documentation for
an XSLT processor should specify for which media types the XSLT
processor supports fragment identifiers.</p></li>

</ul>

<p>The data resulting from the retrieval action is parsed as an XML
document regardless of the media type of the retrieval result; if the
top-level media type is <code>text</code>, then it is parsed in the
same way as if the media type were <code>text/xml</code>; otherwise,
it is parsed in the same way as if the media type were
<code>application/xml</code>.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Since there is no top-level <code>xml</code> media type, data
with a media type other than <code>text/xml</code> or
<code>application/xml</code> may in fact be XML.</p></div>

<p>The URI reference may be relative. The base URI (see <a href="#base-uri"><b>3.2 Base URI</b></a>) of the node in the second argument node-set that is
first in document order is used as the base URI for resolving the
relative URI into an absolute URI. It
is an error if the second argument node-set is empty and the URI
reference is relative; the XSLT processor may signal the error; if it
does not signal an error, it must recover by returning an empty
node-set. If the second argument is omitted,
then it defaults to the node in the stylesheet that contains the
expression that includes the call to the <code>document</code>
function.  Note that a zero-length URI reference is a reference to the
document relative to which the URI reference is being resolved; thus
<code>document("")</code> refers to the root node of the stylesheet;
the tree representation of the stylesheet is exactly the same as if
the XML document containing the stylesheet was the initial source
document.</p>

<p>Two documents are treated as the same document if they are
identified by the same URI. The URI used for the comparison is the
absolute URI into which any relative URI was resolved and does not
include any fragment identifier.  One root node is treated as the same
node as another root node if the two nodes are from the same document.
Thus, the following expression will always be true:</p>

<div class="exampleInner"><pre>generate-id(document("foo.xml"))=generate-id(document("foo.xml"))</pre></div>

<p>The <code>document</code> function gives rise to the
possibility that a node-set may contain nodes from more than one
document.  With such a node-set, the relative document order of two
nodes in the same document is the normal <a href="http://www.w3.org/TR/xpath#dt-document-order">document order</a> defined by
XPath <a href="#XPATH">[XPath]</a>.  The relative document order of two nodes
in different documents is determined by an implementation-dependent
ordering of the documents containing the two nodes.  There are no
constraints on how the implementation orders documents other than that
it must do so consistently: an implementation must always use the same
order for the same set of documents.</p>

</div>

<div class="div2">

<h3><a name="key"></a>12.2 Keys</h3>

<p>Keys provide a way to work with documents that contain an implicit
cross-reference structure.  The <code>ID</code>, <code>IDREF</code>
and <code>IDREFS</code> attribute types in XML provide a mechanism to
allow XML documents to make their cross-reference explicit.  XSLT
supports this through the XPath id function.
However, this mechanism has a number of limitations:</p>

<ul>

<li><p>ID attributes must be declared as such in the DTD.  If an ID
attribute is declared as an ID attribute only in the external DTD
subset, then it will be recognized as an ID attribute only if the XML
processor reads the external DTD subset.  However, XML does not require
XML processors to read the external DTD, and they may well choose not
to do so, especially if the document is declared
<code>standalone="yes"</code>.</p></li>

<li><p>A document can contain only a single set of unique IDs.
There cannot be separate independent sets of unique IDs.</p></li>

<li><p>The ID of an element can only be specified in an attribute;
it cannot be specified by the content of the element, or by a child
element.</p></li>

<li><p>An ID is constrained to be an XML name.  For example, it
cannot contain spaces.</p></li>

<li><p>An element can have at most one ID.</p></li>

<li><p>At most one element can have a particular ID.</p></li>

</ul>

<p>Because of these limitations XML documents sometimes contain a
cross-reference structure that is not explicitly declared by
ID/IDREF/IDREFS attributes.</p>

<p>A key is a triple containing:</p>

<ol>

<li><p>the node which has the key</p></li>

<li><p>the name of the key (an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a>)</p></li>

<li><p>the value of the key (a string)</p></li>

</ol>

<p>A stylesheet declares a set of keys for each document using the
<code>xsl:key</code> element.  When this set of keys contains a member
with node <var>x</var>, name <var>y</var> and value
<var>z</var>, we say that node <var>x</var> has a key with name
<var>y</var> and value <var>z</var>.</p>

<p>Thus, a key is a kind of generalized ID, which is not subject to the
same limitations as an XML ID:</p>

<ul>

<li><p>Keys are declared in the stylesheet using
<code>xsl:key</code> elements.</p></li>

<li><p>A key has a name as well as a value; each key name may be
thought of as distinguishing a separate, independent space of
identifiers.</p></li>

<li><p>The value of a named key for an element may be specified in
any convenient place; for example, in an attribute, in a child element
or in content.  An XPath expression is used to specify where to find
the value for a particular named key.</p></li>

<li><p>The value of a key can be an arbitrary string; it is not
constrained to be a name.</p></li>

<li><p>There can be multiple keys in a document with the same node,
same key name, but different key values.</p></li>

<li><p>There can be multiple keys in a document with the same key
name, same key value, but different nodes.</p></li>

</ul>


  
  
    
  
  
    
  
  
    
  
  


<p>The <code>xsl:key</code> element is used to declare keys.  The
<code>name</code> attribute specifies the name of the key.  The value
of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>, which is expanded as described
in <a href="#qname"><b>2.4 Qualified Names</b></a>. The <code>match</code> attribute is a <a href="#NT-Pattern">Pattern</a>; an <code>xsl:key</code> element gives
information about the keys of any node that matches the pattern
specified in the match attribute.  The <code>use</code> attribute is
an <a title="Expression" href="#dt-expression">expression</a> specifying the
values of the key; the expression is evaluated once for each node that
matches the pattern.  If the result is a node-set, then for each node
in the node-set, the node that matches the pattern has a key of the
specified name whose value is the string-value of the node in the
node-set; otherwise, the result is converted to a string, and the node
that matches the pattern has a key of the specified name with value
equal to that string.  Thus, a node <var>x</var> has a key with name
<var>y</var> and value <var>z</var> if and only if there is an
<code>xsl:key</code> element such that:</p>

<ul>

<li><p><var>x</var> matches the pattern specified in the
<code>match</code> attribute of the <code>xsl:key</code> element;</p></li>

<li><p>the value of the <code>name</code> attribute of the
<code>xsl:key</code> element is equal to <var>y</var>;
and</p></li>

<li><p>when the expression specified in the <code>use</code>
attribute of the <code>xsl:key</code> element is evaluated with
<var>x</var> as the current node and with a node list containing
just <var>x</var> as the current node list resulting in an object
<var>u</var>, then either <var>z</var> is equal to the result of
converting <var>u</var> to a string as if by a call to the
string function, or <var>u</var> is a
node-set and <var>z</var> is equal to the string-value of one or
more of the nodes in <var>u</var>.</p></li>

</ul>

<p>Note also that there may be more than one <code>xsl:key</code>
element that matches a given node; all of the matching
<code>xsl:key</code> elements are used, even if they do not have the
same <a title="Import Precedence" href="#dt-import-precedence">import
precedence</a>.</p>

<p>It is an error for the value of either the <code>use</code>
attribute or the <code>match</code> attribute to contain a <a href="http://www.w3.org/TR/xpath#NT-VariableReference">VariableReference</a>, or a call to the
<code>key</code> function.</p>

<p><em>node-set</em> <b>key</b>(<var>string</var>, <var>object</var>)</p>

<p>The <code>key</code> function does for keys what the
id function does for IDs.  The first argument
specifies the name of the key. The value of the argument must be a
<a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>, which is expanded as
described in <a href="#qname"><b>2.4 Qualified Names</b></a>. When the second argument to the
<code>key</code> function is of type node-set, then the result
is the union of the result of applying the <code>key</code>
function to the <a href="http://www.w3.org/TR/xpath#dt-string-value">string-value</a> of
each of the nodes in the argument node-set.  When the second argument
to <code>key</code> is of any other type, the argument is
converted to a string as if by a call to the
string function; it returns a node-set
containing the nodes in the same document as the context node that
have a value for the named key equal to this string.</p>

<p>For example, given a declaration</p>

<div class="exampleInner"><pre>&lt;xsl:key name="idkey" match="div" use="@id"/&gt;</pre></div>

<p>an expression <code>key("idkey",@ref)</code> will return the same
node-set as <code>id(@ref)</code>, assuming that the only ID attribute
declared in the XML source document is:</p>

<div class="exampleInner"><pre>&lt;!ATTLIST div id ID #IMPLIED&gt;</pre></div>

<p>and that the <code>ref</code> attribute of the current node
contains no whitespace.</p>

<p>Suppose a document describing a function library uses a
<code>prototype</code> element to define functions</p>

<div class="exampleInner"><pre>&lt;prototype name="key" return-type="node-set"&gt;
&lt;arg type="string"/&gt;
&lt;arg type="object"/&gt;
&lt;/prototype&gt;</pre></div>

<p>and a <code>function</code> element to refer to function names</p>

<div class="exampleInner"><pre>&lt;function&gt;key&lt;/function&gt;</pre></div>

<p>Then the stylesheet could generate hyperlinks between the
references and definitions as follows:</p>

<div class="exampleInner"><pre>&lt;xsl:key name="func" match="prototype" use="@name"/&gt;

&lt;xsl:template match="function"&gt;
&lt;b&gt;
  &lt;a href="#{generate-id(key('func',.))}"&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/a&gt;
&lt;/b&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="prototype"&gt;
&lt;p&gt;&lt;a name="{generate-id()}"&gt;
&lt;b&gt;Function: &lt;/b&gt;
...
&lt;/a&gt;&lt;/p&gt;
&lt;/xsl:template&gt;</pre></div>

<p>The <code>key</code> always
returns nodes that are in the same document as the current node; to
retrieve a key from any other document, it is necessary first to
change the current node. For
example, suppose a document contains bibliographic references in the
form <code>&lt;bibref&gt;XSLT&lt;/bibref&gt;</code>, and there is a
separate XML document <code>bib.xml</code> containing a bibliographic
database with entries in the form:</p>

<div class="exampleInner"><pre>&lt;entry name="XSLT"&gt;...&lt;/entry&gt;</pre></div>

<p>Then the stylesheet could use the following to transform the
<code>bibref</code> elements:</p>

<div class="exampleInner"><pre>&lt;xsl:key name="bib" match="entry" use="@name"/&gt;

&lt;xsl:template match="bibref"&gt;
  &lt;xsl:variable name="name" select="."/&gt;
  &lt;xsl:for-each select="document('bib.xml')"&gt;
    &lt;xsl:apply-templates select="key('bib',$name)"/&gt;
  &lt;/xsl:for-each&gt;
&lt;/xsl:template&gt;</pre></div>

</div>

<div class="div2">

<h3><a name="format-number"></a>12.3 Number Formatting</h3>

<p><em>string</em> <b>format-number</b>(<var>number</var>, <var>string</var>, <var>string</var>?)</p>

<p>The <code>format-number</code> function converts its first
argument to a string using the format pattern string specified by the
second argument and the decimal-format named by the third argument, or
the default decimal-format, if there is no third argument.  The format
pattern string is in the syntax specified by the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormat.html">DecimalFormat</a> class. The format pattern string is in a
localized notation: the decimal-format determines what characters have
a special meaning in the pattern (with the exception of the quote
character, which is not localized).  The format pattern must not
contain the currency sign (#x00A4); support for this feature was added
after the initial release of JDK 1.1.  The decimal-format name must be
a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>, which is expanded as
described in <a href="#qname"><b>2.4 Qualified Names</b></a>.  It is an error if the stylesheet
does not contain a declaration of the decimal-format with the specified
<a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a>.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Implementations are not required to use the JDK 1.1
implementation, nor are implementations required to be implemented in
Java.</p></div>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Stylesheets can use other facilities in XPath to control
rounding.</p></div>


  
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  


<p>The <code>xsl:decimal-format</code> element declares a
decimal-format, which controls the interpretation of a format pattern
used by the <code>format-number</code> function.  If there is
a <code>name</code> attribute, then the element declares a named
decimal-format; otherwise, it declares the default decimal-format.
The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>, which is expanded as described
in <a href="#qname"><b>2.4 Qualified Names</b></a>.  It is an error to declare either the
default decimal-format or a decimal-format with a given name more than
once (even with different <a title="Import Precedence" href="#dt-import-precedence">import
precedence</a>), unless it is declared every time with the same
value for all attributes (taking into account any default values). If a stylesheet does not contain a declaration of
the default decimal format, a declaration equivalent to
an <code>xsl:decimal-format</code> element with no attributes
is implied.</p>

<p>The other attributes on <code>xsl:decimal-format</code> correspond
to the methods on the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormatSymbols.html">DecimalFormatSymbols</a> class.  For each
<code>get</code>/<code>set</code> method pair there is an attribute
defined for the <code>xsl:decimal-format</code> element.</p>

<p>The following attributes both control the interpretation of
characters in the format pattern and specify characters that may
appear in the result of formatting the number:</p>

<ul>

<li><p><code>decimal-separator</code> specifies the character used
for the decimal sign; the default value is the period character
(<code>.</code>)</p></li>

<li><p><code>grouping-separator</code> specifies the character used
as a grouping (e.g. thousands) separator; the default value is the
comma character (<code>,</code>)</p></li>

<li><p><code>percent</code> specifies the character used as a
percent sign; the default value is the percent character
(<code>%</code>)</p></li>

<li><p><code>per-mille</code> specifies the character used as a per
mille sign; the default value is the Unicode per-mille character
(#x2030)</p></li>

<li><p><code>zero-digit</code> specifies the character used as the
digit zero; the default value is the digit zero
(<code>0</code>)</p></li>

</ul>

<p>The following attributes control the interpretation of characters
in the format pattern:</p>

<ul>

<li><p><code>digit</code> specifies the character used for a digit
in the format pattern; the default value is the number sign character
(<code>#</code>)</p></li>

<li><p><code>pattern-separator</code> specifies the character used
to separate positive and negative sub patterns in a pattern; the
default value is the semi-colon character (<code>;</code>)</p></li>

</ul>

<p>The following attributes specify characters or strings that may
appear in the result of formatting the number:</p>

<ul>

<li><p><code>infinity</code> specifies the string used to represent
infinity; the default value is the string
<code>Infinity</code></p></li>

<li><p><code>NaN</code> specifies the string used to represent the
NaN value; the default value is the string <code>NaN</code></p></li>

<li><p><code>minus-sign</code> specifies the character used as the
default minus sign; the default value is the hyphen-minus character
(<code>-</code>, #x2D)</p></li>

</ul>

</div>

<div class="div2">

<h3><a name="misc-func"></a>12.4 Miscellaneous Additional Functions</h3>

<p><em>node-set</em> <b>current</b>()</p>

<p>The <code>current</code> function returns a node-set that
has the <a title="Current Node" href="#dt-current-node">current node</a> as its
only member.  For an outermost expression (an expression not occurring
within another expression), the current node is always the same as the
context node.  Thus,</p>

<div class="exampleInner"><pre>&lt;xsl:value-of select="current()"/&gt;</pre></div>

<p>means the same as</p>

<div class="exampleInner"><pre>&lt;xsl:value-of select="."/&gt;</pre></div>

<p>However, within square brackets the current node is usually
different from the context node. For example,</p>

<div class="exampleInner"><pre>&lt;xsl:apply-templates select="//glossary/item[@name=current()/@ref]"/&gt;</pre></div>

<p>will process all <code>item</code> elements that have a
<code>glossary</code> parent element and that have a <code>name</code>
attribute with value equal to the value of the current node's
<code>ref</code> attribute. This is different from</p>

<div class="exampleInner"><pre>&lt;xsl:apply-templates select="//glossary/item[@name=./@ref]"/&gt;</pre></div>

<p>which means the same as</p>

<div class="exampleInner"><pre>&lt;xsl:apply-templates select="//glossary/item[@name=@ref]"/&gt;</pre></div>

<p>and so would process all <code>item</code> elements that have a
<code>glossary</code> parent element and that have a <code>name</code>
attribute and a <code>ref</code> attribute with the same value.</p>

<p>It is an error to use the <code>current</code> function in
a <a title="Pattern" href="#dt-pattern">pattern</a>.</p>

<p><em>string</em> <b>unparsed-entity-uri</b>(<var>string</var>)</p>

<p>The <code>unparsed-entity-uri</code> returns the URI of the
unparsed entity with the specified name in the same document as the
context node (see <a href="#unparsed-entities"><b>3.3 Unparsed Entities</b></a>).  It returns the
empty string if there is no such entity.</p>

<p><em>string</em> <b>generate-id</b>(<var>node-set</var>?)</p>

<p>The <code>generate-id</code> function returns a string that
uniquely identifies the node in the argument node-set that is first in
document order.  The unique identifier must consist of ASCII
alphanumeric characters and must start with an alphabetic character.
Thus, the string is syntactically an XML name.  An implementation is
free to generate an identifier in any convenient way provided that it
always generates the same identifier for the same node and that
different identifiers are always generated from different nodes. An
implementation is under no obligation to generate the same identifiers
each time a document is transformed.  There is no guarantee that a
generated unique identifier will be distinct from any unique IDs
specified in the source document.  If the argument node-set is empty,
the empty string is returned. If the argument is omitted, it defaults
to the context node.</p>

<p><em>object</em> <b>system-property</b>(<var>string</var>)</p>

<p>The argument must evaluate to a string that is a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>.  The <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> is expanded into a name using
the namespace declarations in scope for the expression. The
<code>system-property</code> function returns an object
representing the value of the system property identified by the name.
If there is no such system property, the empty string should be
returned.</p>

<p>Implementations must provide the following system properties, which
are all in the XSLT namespace:</p>

<blockquote><p>

<code>xsl:version</code>, a number giving the version of XSLT
implemented by the processor; for XSLT processors implementing the
version of XSLT specified by this document, this is the number
1.0

<br><code>xsl:vendor</code>, a string identifying the vendor of the
XSLT processor

<br><code>xsl:vendor-url</code>, a string containing a URL
identifying the vendor of the XSLT processor; typically this is the
host page (home page) of the vendor's Web site.

</p></blockquote>

<p id="diff-26">Vendors must not define additional system
properties in the XSLT namespace.</p>

</div>

</div>

<div class="div1">

<h2><a name="message"></a>13 Messages</h2>


  
  
    
    
  
  


<p>The <code>xsl:message</code> instruction sends a message in a way
that is dependent on the XSLT processor.  The content of the
<code>xsl:message</code> instruction is a template.  The
<code>xsl:message</code> is instantiated by instantiating the content
to create an XML fragment.  This XML fragment is the content of the
message.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>An XSLT processor might implement <code>xsl:message</code> by
popping up an alert box or by writing to a log file.</p></div>

<p>If the <code>terminate</code> attribute has the value
<code>yes</code>, then the XSLT processor should terminate processing
after sending the message.  The default value is <code>no</code>.</p>

<p>One convenient way to do localization is to put the localized
information (message text, etc.) in an XML document, which becomes an
additional input file to the stylesheet.  For example, suppose
messages for a language <code><var>L</var></code> are stored in an XML
file <code>resources/<var>L</var>.xml</code> in the form:</p>

<div class="exampleInner"><pre>&lt;messages&gt;
  &lt;message name="problem"&gt;A problem was detected.&lt;/message&gt;
  &lt;message name="error"&gt;An error was detected.&lt;/message&gt;
&lt;/messages&gt;
</pre></div>

<p>Then a stylesheet could use the following approach to localize
messages:</p>

<div class="exampleInner"><pre>&lt;xsl:param name="lang" select="'en'"/&gt;
&lt;xsl:variable name="messages"
  select="document(concat('resources/', $lang, '.xml'))/messages"/&gt;

&lt;xsl:template name="localized-message"&gt;
  &lt;xsl:param name="name"/&gt;
  &lt;xsl:message&gt;
    &lt;xsl:value-of select="$messages/message[@name=$name]"/&gt;
  &lt;/xsl:message&gt;
&lt;/xsl:template&gt;

&lt;xsl:template name="problem"&gt;
  &lt;xsl:call-template name="localized-message"/&gt;
    &lt;xsl:with-param name="name"&gt;problem&lt;/xsl:with-param&gt;
  &lt;/xsl:call-template&gt;
&lt;/xsl:template&gt;</pre></div>

</div>

<div class="div1">

<h2><a name="extension"></a>14 Extensions</h2>

<p>XSLT allows two kinds of extension, extension elements and
extension functions.</p>

<p>This version of XSLT does not provide a mechanism for defining
implementations of extension elements. It does
provide a mechanism for defining extension functions; however, XSLT
does not require that XSLT processors support any particular languages
for implementing extensions.
Therefore, an XSLT stylesheet that must
be portable between XSLT implementations cannot rely on particular
extensions being available.  XSLT provides mechanisms that allow an
XSLT stylesheet to determine whether the XSLT processor by which it is
being processed has implementations of particular extensions
available, and to specify what should happen if those extensions are
not available.  If an XSLT stylesheet is careful to make use of these
mechanisms, it is possible for it to take advantage of extensions and
still work with any XSLT implementation.</p>

<div class="div2">

<h3><a name="extension-element"></a>14.1 Using Extension Elements</h3>

<p>[<a name="dt-extension-namespace" title="Extension Namespace">Definition</a>: The
element extension mechanism allows namespaces to be designated as
<b>extension namespace</b>s. When a namespace is designated as
an extension namespace and an element with a name from that namespace
occurs in a template, then the element is treated as an instruction
rather than as a literal result element.] The namespace
determines the semantics of the instruction.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Since an element that is a child of an
<code>xsl:stylesheet</code> element is not occurring <em>in a
template</em>, non-XSLT <a title="Top-level" href="#dt-top-level">top-level</a> elements are not extension
elements as defined here, and nothing in this section applies to
them.</p></div>

<p>A namespace is designated as an extension namespace by using an
<code>extension-element-prefixes</code> attribute on an
<code>xsl:stylesheet</code> element or an
<code>xsl:extension-element-prefixes</code> attribute on a literal
result element or extension element.
The value of both these attributes is a
whitespace-separated list of namespace prefixes. The namespace bound
to each of the prefixes is designated as an extension namespace.  It
is an error if there is no namespace bound to the prefix on the
element bearing the <code>extension-element-prefixes</code> or
<code>xsl:extension-element-prefixes</code> attribute.  The default
namespace (as declared by <code>xmlns</code>) may be designated as an
extension namespace by including <code>#default</code> in the list of
namespace prefixes.  The designation of a namespace as an extension
namespace is effective within the subtree of the stylesheet rooted at
the element bearing the <code>extension-element-prefixes</code> or
<code>xsl:extension-element-prefixes</code> attribute;
a subtree rooted at an <code>xsl:stylesheet</code> element
does not include any stylesheets imported or included by children
of that <code>xsl:stylesheet</code> element.</p>

<p>If the XSLT processor does not have an implementation of a
particular extension element available, then the
<code>element-available</code> function must return false for
the name of the element.  When such an extension element is
instantiated, then the XSLT processor must perform fallback for the
element as specified in <a href="#fallback"><b>15 Fallback</b></a>.  An XSLT processor
must not signal an error merely because a template contains an
extension element for which no implementation is available.</p>

<p>If the XSLT processor has an implementation of a particular
extension element available, then the
<code>element-available</code> function must return true for
the name of the element.</p>

</div>

<div class="div2">

<h3><a name="N8607"></a>14.2 Using Extension Functions</h3>

<p>If a <a href="http://www.w3.org/TR/xpath#NT-FunctionName">FunctionName</a> in a
<a href="http://www.w3.org/TR/xpath#NT-FunctionCall">FunctionCall</a> expression is
not an <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCName</a> (i.e. if it
contains a colon), then it is treated as a call to an extension
function.  The <a href="http://www.w3.org/TR/xpath#NT-FunctionName">FunctionName</a>
is expanded to a name using the namespace declarations from the
evaluation context.</p>

<p>If the XSLT processor does not have an implementation of an
extension function of a particular name available, then the
<code>function-available</code> function must return false for
that name.  If such an extension function occurs in an expression and
the extension function is actually called, the XSLT processor must
signal an error.  An XSLT processor must not signal an error merely
because an expression contains an extension function for which no
implementation is available.</p>

<p>If the XSLT processor has an implementation of an extension
function of a particular name available, then the
<code>function-available</code> function must return
true for that name. If such an extension is called, then the XSLT
processor must call the implementation passing it the function call
arguments; the result returned by the implementation is returned as
the result of the function call.</p>

<table border="1" summary="Editorial note"><tr><td align="left" valign="top" width="50%"><b>Editorial note</b></td><td align="right" valign="top" width="50%">&nbsp;</td></tr><tr><td colspan="2" align="left" valign="top">Say something about automatic argument conversions
here.</td></tr></table>

<p>Typically, implementations of extension functions
represent strings as a sequence of code values (usually 16-bit
integers or bytes).  It is possible for an extension function to
return a sequence of code values that cannot be mapped to a sequence
of legal XML characters.  The behavior of an XSLT processor in this
case is implementation-dependent.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Requiring the XSLT processor to check the contents
of every string returned by an extension function could be a
significant performance burden.</p></div>

</div>

<div class="div2">

<h3><a name="external-objects"></a>14.3 External Objects</h3>

<p>[<a name="dt-external-object" title="external object">Definition</a>: Support for
extension functions introduces an additional data-type into the
expression language. This additional data type is called an
<b>external object</b>. A variable may be bound to an object of
type external object instead of one of the four XPath data-types
(string, number, boolean, node-set). An external object represents an
object that is not convertible to one of the four XPath data types
which is created by an external programming language and returned by
an extension function. Expressions can only return values of type
external object by referencing variables of type external object or
calling extension functions that return an external
object.]</p>

<p>An external object may only be passed as an argument to another
extension function. It may not be copied to the result tree or
converted (implicitly or explicitly) to any of the XPath data types.
So, for example, if the <code>myvar</code> variable is bound an
external object, then the following are <em>not</em> allowed:</p>

<ul>
<li>
<p><code>&lt;xsl:copy-of select="$myvar"/&gt; &lt;!--
Cannot copy to result tree --&gt;</code></p>
</li>
<li>
<p><code>&lt;xsl:value-of select="$myvar"/&gt; &lt;!--
Cannot implicitly convert to String --&gt;</code></p>
</li>
<li>
<p><code>&lt;xsl:value-of select="string($myvar)"/&gt;
&lt;!-- Cannot explicitly convert to String --&gt;</code></p>
</li>
</ul>

<p>If an external object is passed to an extension function with an
<a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a>
whose namespace URI is different from the namespace URI of the
<a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> of
the extension function that returned that external object, the
behavior is implementation-dependent.</p>

<p>An extension function can be used to convert the argument to a
string or return an XML fragment to be copied to the result tree if
desired. For example, assuming the <code>myext:print()</code>
extension function accepts an argument of a compatible data type and
returns a string, the following is allowed:</p> <div class="exampleInner"><pre>&lt;!-- Convert to
string with extension function --&gt; &lt;xsl:value-of
select="myext:print($myvar)"/&gt; </pre></div>

<div class="issue"><p class="prefix"><a name="issue-null-external-object"></a><b>Issue (issue-null-external-object):</b></p><p>Should the spec have the
concept that an external object may be null, and provide a way for
testing this, for example, by conversion to
<code>boolean</code>?</p></div>

<table border="1" summary="Editorial note"><tr><td align="left" valign="top" width="50%"><b>Editorial note</b></td><td align="right" valign="top" width="50%">&nbsp;</td></tr><tr><td colspan="2" align="left" valign="top">Define the idea that an external object
"wraps" an object created by an external programming
language.</td></tr></table>

</div>

<div class="div2">

<h3><a name="define-extension-functions"></a>14.4 Defining Extension Functions</h3>


  
  
    
  
  
    
    
    
    
  
  
    
  
  
    
  
  


<p>The top-level <code>xsl:script</code> element provides an
implementation of extension functions in a particular namespace. The
function implementations may be provided as a separate resource.  Some
language bindings also allow the function implementations to be
provided directly in the content of the <code>xsl:script</code>.</p>

<table border="1" summary="Editorial note"><tr><td align="left" valign="top" width="50%"><b>Editorial note</b></td><td align="right" valign="top" width="50%">&nbsp;</td></tr><tr><td colspan="2" align="left" valign="top">Make sure that it is clear that it is allowed to call
extension functions without using xsl:script to define
them.</td></tr></table>

<p>The <code>implements-prefix</code> attribute specifies a namespace
prefix.  This prefix is expanded into a URI using the namespace
declarations in scope on the <code>xsl:script</code> element.  This
URI is the namespace URI of the expanded-names of the functions of
which an implementation is being provided. The implementation of the
extension functions identifies the local names of the functions that
is is implementing.</p>

<p>The <code>language</code> attribute identifies the language used by
the implementation being provided.  It also identifies the way
arguments are passed by the XSLT processor to the implementation of
the extension function, the way results are returned from the
implementation of the extension function, and the way the XSLT
expression context is made available to the extension function
(collectively known as the language binding).  The value must be a
<a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>.  If the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> does not have a prefix, then it
identifies a language binding specified in this document and must be
<code>ecmascript</code>, <code>javascript</code> or <code>java</code>.
If the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> has a prefix, then
the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> is expanded into an
<a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> as
described in <a href="#qname"><b>2.4 Qualified Names</b></a>; the expanded-name identifies the
language binding; the language binding in this case is not specified
by this document.  XSLT processors are not required to support any
particular language binding. <code>xsl:script</code> elements with
<code>language</code> values not supported by the processor are
ignored.</p>

<p>When the function implementations are provided as a separate
resource, the content of the <code>xsl:script</code> element must be
empty and the <code>src</code> attribute is required.  The
<code>src</code> attribute is a URI reference that identifies the
resource containing the implementation of the extension functions.
For example,</p>

<ul>
<li>
<p>A Java class:
<code>src="java:com.example.datestuff.DateRoutines"</code></p>
</li>
<li>
<p>An ECMAScript library:
<code>src="http://example.org/somecode.js"</code></p>
</li>
</ul>

<p>When a function implementation is provided locally in the content
of the <code>xsl:script</code> element, the <code>src</code>
attribute must not be specified. For example,</p>

<div class="exampleInner"><pre>&lt;xsl:script implements-prefix="<var>pref</var>" language="<var>lang</var>"&gt;
// Function Declarations in Supported Language Syntax
function f(x)   { ... }
function g(y,z) { ... }
&lt;/xsl:script&gt;</pre></div>

<p>The <code>archive</code> attribute is a whitespace-separated list
of URI references, each pointing to an archive to be loaded by the
processor before executing the extension function.  The
<code>archive</code> attribute may be used on an
<code>xsl:script</code> element regardless of whether that
<code>xsl:script</code> element has a <code>src</code> attribute.</p>

<p>The <code>function-available</code> function can be used to
detect the availability of an extension function provided by an
<code>xsl:script</code> element.  The precise details of what it
means for an extension function to be available is specific to the
language-binding.</p>

<p>A stylesheet can contain any number of <code>xsl:script</code>
elements. The order of these elements is not significant in the
stylesheet, except for fallback behavior. In particular, calls to
extension function can occur before <code>xsl:script</code> elements
that provide implementations of those extension functions.</p>

<p>If there are multiple <code>xsl:script</code> elements with the
same namespace URI but different implementation languages, then each
implementation language corresponds to an alternative implementation
of the same extension functions.  If an XSLT processor supports two
or more of the languages in which an extension function implementation
is provided, then it is free to choose any of its supported
languages, provided that it always chooses the same implementation for
the same extension function namespace URI. A processor is under no
obligation to choose the same implementation each time a document is
transformed.</p>

<p>If there are multiple <code>xsl:script</code> elements with the
same namespace URI and the same language but different import
precedences, a processor must reconcile the separate elements using
the import precedence.  The manner in which the elements are
reconciled is determined by the language binding.  For example, some
language bindings may simply use the <code>xsl:script</code> element
with the highest import precedence; others may merge the
<code>xsl:script</code> elements in some way.  It is an error for two
<code>xsl:script</code> elements with the same import precedence to
implement the same namespace URI for the same language.  An XSLT
processor may signal the error; if it does not signal the error, it
must recover by treating the two <code>xsl:script</code> elements as
if the <code>xsl:script</code> element that occurs later in the
stylesheet had a higher import precedence than the other
<code>xsl:script</code> element.</p>

</div>

</div>

<div class="div1">

<h2><a name="fallback"></a>15 Fallback</h2>


  
  


<p>Normally, instantiating an <code>xsl:fallback</code> element does
nothing.  However, when an XSLT processor performs fallback for an
instruction element, if the instruction element has one or more
<code>xsl:fallback</code> children, then the content of each of the
<code>xsl:fallback</code> children must be instantiated in sequence;
otherwise, an error must be signaled. The content of an
<code>xsl:fallback</code> element is a template.</p>

<p>The following functions can be used with the
<code>xsl:choose</code> and <code>xsl:if</code> instructions to
explicitly control how a stylesheet should behave if particular
elements or functions are not available.</p>

<p><em>boolean</em> <b>element-available</b>(<var>string</var>)</p>

<p>The argument must evaluate to a string that is a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>.  The <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> is expanded into an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> using the
namespace declarations in scope for the expression. If there is a default namespace in scope,
then it is used to expand an unprefixed <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>. The
<code>element-available</code> function returns true if and
only if the expanded-name is the name of an instruction.  If the
expanded-name has a namespace URI equal to the XSLT namespace URI,
then it refers to an element defined by XSLT.  Otherwise, it refers to
an extension element. If the expanded-name has a null namespace URI,
the <code>element-available</code> function will return
false.</p>

<p><em>boolean</em> <b>function-available</b>(<var>string</var>)</p>

<p>The argument must evaluate to a string that is a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>.  The <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> is expanded into an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> using the
namespace declarations in scope for the expression. The
<code>function-available</code> function returns true if and
only if the expanded-name is the name of a function in the function
library. If the expanded-name has a non-null namespace URI, then it
refers to an extension function; otherwise, it refers to a function
defined by XPath or XSLT.</p>

</div>

<div class="div1">

<h2><a name="output"></a>16 Output</h2>


  
  
    
      
      
      
      
    
  
  
    
      
    
  
  
    
      
    
  
  
    
      
      
    
  
  
    
      
      
    
  
  
    
      
    
  
  
    
      
    
  
  
    
      
    
  
  
    
      
      
    
  
  
    
      
    
  
  


<p>An XSLT processor may output the result tree as a sequence of
bytes, although it is not required to be able to do so (see <a href="#conformance"><b>17 Conformance</b></a>). The <code>xsl:output</code> element allows
stylesheet authors to specify how they wish the result tree to be
output. If an XSLT processor outputs the result tree, it should do so
as specified by the <code>xsl:output</code> element; however, it is
not required to do so. Before the result tree
is output, <a title="Namespace Fixup" href="#dt-namespace-fixup">namespace fixup</a>
is performed (see <a href="#namespace-fixup"><b>3.5 Namespace Fixup</b></a>).</p>

<p>The <code>xsl:output</code> element is only allowed as a <a title="Top-level" href="#dt-top-level">top-level</a> element.
All attributes on <code>xsl:output</code> are interpreted as <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute value
template</a>s. Expressions recognized in the attributes of
<code>xsl:output</code> are evaluated with the same context as used to
process the root node of the source document: the current node is the
root node of the source document and the current node list is a list
containing just the root node of the source document.</p>

<p>The <code>method</code> attribute on <code>xsl:output</code>
identifies the overall method that should be used for outputting the
result tree.  The value must be a <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>.  If the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> does not have a prefix, then it
identifies a method specified in this document and must be one of
<code>xml</code>, <code>html</code> or <code>text</code>.  If the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> has a prefix, then the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> is expanded into an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> as described
in <a href="#qname"><b>2.4 Qualified Names</b></a>; the expanded-name identifies the output
method; the behavior in this case is not specified by this
document.</p>

<p>The default for the <code>method</code> attribute is chosen as
follows.  If</p>

<ul>

<li><p>the root node of the result tree has an element
child,</p></li>

<li><p>the expanded-name of the first element child of the root node
(i.e. the document element) of the result tree has local part
<code>html</code> (in any combination of upper and lower case) and a
null namespace URI, and</p></li>

<li><p>any text nodes preceding the first element child of the root
node of the result tree contain only whitespace characters,</p></li>

</ul>

<p>then the default output method is <code>html</code>; otherwise, the
default output method is <code>xml</code>.  The default output method
should be used if there are no <code>xsl:output</code> elements or if
none of the <code>xsl:output</code> elements specifies a value for the
<code>method</code> attribute.</p>

<p>The other attributes on <code>xsl:output</code> provide parameters
for the output method.  The following attributes are allowed:</p>

<ul>

<li><p><code>version</code> specifies the version of the output
method</p></li>

<li><p><code>indent</code> specifies whether the XSLT processor may
add additional whitespace when outputting the result tree; the value
must be <code>yes</code> or <code>no</code></p></li>

<li><p><code>encoding</code> specifies the preferred character
encoding that the XSLT processor should use to encode sequences of
characters as sequences of bytes; the value of the attribute should be
treated case-insensitively; the value must contain only characters in
the range #x21 to #x7E (i.e. printable ASCII characters); the value
should either be a <code>charset</code> registered with the Internet
Assigned Numbers Authority <a href="#IANA">[IANA]</a>, <a href="#RFC2278">[RFC2278]</a> or start with <code>X-</code></p></li>

<li><p><code>media-type</code> specifies the media type (MIME
content type) of the data that results from outputting the result
tree; the <code>charset</code> parameter should not be specified
explicitly; instead, when the top-level media type is
<code>text</code>, a <code>charset</code> parameter should be added
according to the character encoding actually used by the output
method</p></li>

<li><p><code>doctype-system</code> specifies the system identifier
to be used in the document type declaration</p></li>

<li><p><code>doctype-public</code> specifies the public identifier
to be used in the document type declaration</p></li>

<li><p><code>omit-xml-declaration</code> specifies whether the XSLT
processor should output an XML declaration; the value must be
<code>yes</code> or <code>no</code></p></li>

<li><p><code>standalone</code> specifies whether the XSLT processor
should output a standalone document declaration; the value must be
<code>yes</code> or <code>no</code></p></li>

<li><p><code>cdata-section-elements</code> specifies a list of the
names of elements whose text node children should be output using
CDATA sections</p></li>

</ul>

<p>The detailed semantics of each attribute will be described
separately for each output method for which it is applicable.  If the
semantics of an attribute are not described for an output method, then
it is not applicable to that output method.</p>

<p>A stylesheet may contain multiple <code>xsl:output</code> elements
and may include or import stylesheets that also contain
<code>xsl:output</code> elements.  All the <code>xsl:output</code>
elements occurring in a stylesheet are merged into a single effective
<code>xsl:output</code> element. For the
<code>cdata-section-elements</code> attribute, the effective value is
the union of the specified values.  For other attributes, the
effective value is the specified value with the highest <a title="Import Precedence" href="#dt-import-precedence">import precedence</a>. It is an error
if there is more than one such value for an attribute.  An XSLT
processor may signal the error; if it does not signal the error, if
should recover by using the value that occurs last in the stylesheet.
The values of attributes are defaulted after the
<code>xsl:output</code> elements have been merged; different output
methods may have different default values for an attribute.</p>

<div class="div2">

<h3><a name="N9628"></a>16.1 XML Output Method</h3>

<p>The <code>xml</code> output method outputs the result tree as a
well-formed XML external general parsed entity. If the root node of
the result tree has a single element node child and no text node
children, then the entity should also be a well-formed XML document
entity. When the entity is referenced within a trivial XML document
wrapper like this</p>

<div class="exampleInner"><pre>
&lt;!DOCTYPE doc [
&lt;!ENTITY e SYSTEM "<var>entity-URI</var>"&gt;
]&gt;
&lt;doc&gt;&amp;e;&lt;/doc&gt;</pre></div>

<p>where <code><var>entity-URI</var></code> is a URI for the entity,
then the wrapper
document as a whole should be a well-formed XML document conforming to
the XML Namespaces Recommendation <a href="#XMLNAMES">[XML Names]</a>.  In
addition, the output should be such that if a new tree was constructed
by parsing the wrapper as an XML document as specified in <a href="#data-model"><b>3 Data Model</b></a>, and then removing the document element, making its
children instead be children of the root node, then the new tree would
be the same as the result tree, with the following possible
exceptions:</p>

<ul>

<li><p>The order of attribute and
namespace nodes in the two trees may be different.</p></li>

<li><p id="diff-29">The base URIs of nodes in the two
trees may be different.</p></li>

</ul>

<p>If the XSLT processor generated a document type declaration because
of the <code>doctype-system</code> attribute or generated a standalone document declaration because
of the <code>standalone</code> attribute, then the output must be a well-formed XML
document, and the above requirements apply to the tree constructed by parsing that document
directly, without any wrapper, using an XML processor that does not
process the DTD.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Processing the DTD might cause
additional attributes to appear in the tree because of attribute
defaulting.</p></div>

<p>The <code>version</code> attribute specifies the version of XML to
be used for outputting the result tree.  If the XSLT processor does
not support this version of XML, it should use a version of XML that
it does support.  The version output in the XML declaration (if an XML
declaration is output) should correspond to the version of XML that
the processor used for outputting the result tree. The value of the
<code>version</code> attribute should match the <a href="http://www.w3.org/TR/REC-xml#NT-VersionNum">VersionNum</a> production of the XML
Recommendation <a href="#XML">[XML]</a>. The default value is
<code>1.0</code>.</p>

<p>The <code>encoding</code> attribute specifies the preferred
encoding to use for outputting the result tree.  XSLT processors are
required to respect values of <code>UTF-8</code> and
<code>UTF-16</code>.  For other values, if the XSLT processor does not
support the specified encoding it may signal an error; if it does not
signal an error it should use <code>UTF-8</code> or
<code>UTF-16</code> instead.  The XSLT processor must not use an
encoding whose name does not match the <a href="http://www.w3.org/TR/REC-xml#NT-EncName">EncName</a> production of the XML
Recommendation <a href="#XML">[XML]</a>.  If no <code>encoding</code>
attribute is specified, then the XSLT processor should use either
<code>UTF-8</code> or <code>UTF-16</code>.  It is possible that the
result tree will contain a character that cannot be represented in the
encoding that the XSLT processor is using for output.  In this case,
if the character occurs in a context where XML recognizes character
references (i.e. in the value of an attribute node or text node), then
the character should be output as a character reference; otherwise
(for example if the character occurs in the name of an element) the
XSLT processor should signal an error.</p>

<p>If the <code>indent</code> attribute has the value
<code>yes</code>, then the <code>xml</code> output method may output
whitespace in addition to the whitespace in the result tree (possibly
based on whitespace stripped from either the source document or the
stylesheet) in order to indent the result nicely; if the
<code>indent</code> attribute has the value <code>no</code>, it should
not output any additional whitespace. The default value is
<code>no</code>.  The <code>xml</code> output method should use an
algorithm to output additional whitespace that ensures that the result
if whitespace were to be stripped from the output using the process
described in <a href="#strip"><b>3.4 Whitespace Stripping</b></a> with the set of
whitespace-preserving elements consisting of just
<code>xsl:text</code> would be the same when additional whitespace is
output as when additional whitespace is not output.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>It is usually not safe to use <code>indent="yes"</code> with
document types that include element types with mixed content.</p></div>

<p>The <code>cdata-section-elements</code> attribute contains a
whitespace-separated list of <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>s.  Each <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> is expanded into an
expanded-name using the namespace declarations in effect on the
<code>xsl:output</code> element in which the <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a> occurs; if there is a default
namespace, it is used for <a href="http://www.w3.org/TR/REC-xml-names/#NT-QName">QName</a>s
that do not have a prefix.  The expansion is performed before the
merging of multiple <code>xsl:output</code> elements into a single
effective <code>xsl:output</code> element. If the expanded-name of the
parent of a text node is a member of the list, then the text node
should be output as a CDATA section. For example,</p>

<div class="exampleInner"><pre>&lt;xsl:output cdata-section-elements="example"/&gt;</pre></div>

<p>would cause a literal result element written in the stylesheet as</p>

<div class="exampleInner"><pre>&lt;example&gt;&amp;lt;foo&gt;&lt;/example&gt;</pre></div>

<p>or as</p>

<div class="exampleInner"><pre>&lt;example&gt;&lt;![CDATA[&lt;foo&gt;]]&gt;&lt;/example&gt;</pre></div>

<p>to be output as</p>

<div class="exampleInner"><pre>&lt;example&gt;&lt;![CDATA[&lt;foo&gt;]]&gt;&lt;/example&gt;</pre></div>

<p>If the text node contains the sequence of characters
<code>]]&gt;</code>, then the currently open CDATA section should be
closed following the <code>]]</code> and a new CDATA section opened
before the <code>&gt;</code>. For example, a literal result element
written in the stylesheet as</p>

<div class="exampleInner"><pre>&lt;example&gt;]]&amp;gt;&lt;/example&gt;</pre></div>

<p>would be output as</p>

<div class="exampleInner"><pre>&lt;example&gt;&lt;![CDATA[]]]]&gt;&lt;![CDATA[&gt;]]&gt;&lt;/example&gt;</pre></div>

<p>If the text node contains a character that is not representable in
the character encoding being used to output the result tree, then the
currently open CDATA section should be closed before the character,
the character should be output using a character reference or entity
reference, and a new CDATA section should be opened for any further
characters in the text node.</p>

<p>CDATA sections should not be used except for text nodes that the
<code>cdata-section-elements</code> attribute explicitly specifies
should be output using CDATA sections.</p>

<p>The <code>xml</code> output method should output an XML declaration
unless the <code>omit-xml-declaration</code> attribute has the value
<code>yes</code>. The XML declaration should include both version
information and an encoding declaration. If the
<code>standalone</code> attribute is specified, it should include a
standalone document declaration with the same value as the value as
the value of the <code>standalone</code> attribute.  Otherwise, it
should not include a standalone document declaration; this ensures
that it is both an XML
declaration (allowed at the beginning of a document entity) and a text
declaration (allowed at the beginning of an external general parsed
entity).</p>

<p>If the <code>doctype-system</code> attribute is specified, the
<code>xml</code> output method should output a document type
declaration immediately before the first element.  The name following
<code>&lt;!DOCTYPE</code> should be the name of the first element.  If
<code>doctype-public</code> attribute is also specified, then the
<code>xml</code> output method should output <code>PUBLIC</code>
followed by the public identifier and then the system identifier;
otherwise, it should output <code>SYSTEM</code> followed by the system
identifier.  The internal subset should be empty.  The
<code>doctype-public</code> attribute should be ignored unless the
<code>doctype-system</code> attribute is specified.</p>

<p>The <code>media-type</code> attribute is applicable for the
<code>xml</code> output method.  The default value for the
<code>media-type</code> attribute is <code>text/xml</code>.</p>

</div>

<div class="div2">

<h3><a name="N9978"></a>16.2 HTML Output Method</h3>

<p>The <code>html</code> output method outputs the result tree as
HTML; for example,</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

&lt;xsl:output method="html"/&gt;

&lt;xsl:template match="/"&gt;
  &lt;html&gt;
   &lt;xsl:apply-templates/&gt;
  &lt;/html&gt;
&lt;/xsl:template&gt;

...

&lt;/xsl:stylesheet&gt;</pre></div>

<p>The <code>version</code> attribute indicates the version of the
HTML.  The default value is <code>4.0</code>, which specifies that the
result should be output as HTML conforming to the HTML 4.0
Recommendation <a href="#HTML">[HTML]</a>.</p>

<p>The <code>html</code> output method should not output an element
differently from the <code>xml</code> output method unless the
expanded-name of the element has a null namespace URI; an element
whose expanded-name has a non-null namespace URI should be output as
XML.  If the expanded-name of the element has a null namespace URI,
but the local part of the expanded-name is not recognized as the name
of an HTML element, the element should output in the same way as a
non-empty, inline element such as <code>span</code>.</p>

<p>The <code>html</code> output method should not output an end-tag
for empty elements.  For HTML 4.0, the empty elements are
<code>area</code>, <code>base</code>, <code>basefont</code>,
<code>br</code>, <code>col</code>, <code>frame</code>,
<code>hr</code>, <code>img</code>, <code>input</code>,
<code>isindex</code>, <code>link</code>, <code>meta</code> and
<code>param</code>. For example, an element written as
<code>&lt;br/&gt;</code> or <code>&lt;br&gt;&lt;/br&gt;</code> in the
stylesheet should be output as <code>&lt;br&gt;</code>.</p>

<p>The <code>html</code> output method should recognize the names of
HTML elements regardless of case.  For example, elements named
<code>br</code>, <code>BR</code> or <code>Br</code> should all be
recognized as the HTML <code>br</code> element and output without an
end-tag.</p>

<p>The <code>html</code> output method should not perform escaping for
the content of the <code>script</code> and <code>style</code>
elements. For example, a literal result element written in the
stylesheet as</p>

<div class="exampleInner"><pre>&lt;script&gt;if (a &amp;lt; b) foo()&lt;/script&gt;</pre></div>

<p>or</p>

<div class="exampleInner"><pre>&lt;script&gt;&lt;![CDATA[if (a &lt; b) foo()]]&gt;&lt;/script&gt;</pre></div>

<p>should be output as</p>

<div class="exampleInner"><pre>&lt;script&gt;if (a &lt; b) foo()&lt;/script&gt;</pre></div>

<p>The <code>html</code> output method should not escape
<code>&lt;</code> characters occurring in attribute values.</p>

<p>If the <code>indent</code> attribute has the value
<code>yes</code>, then the <code>html</code> output method may add or
remove whitespace as it outputs the result tree, so long as it does
not change how an HTML user agent would render the output.  The
default value is <code>yes</code>.</p>

<p>The <code>html</code> output method should escape non-ASCII
characters in URI attribute values using the method recommended in
<a href="http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1">Section
B.2.1</a> of the HTML 4.0 Recommendation.</p>

<p>The <code>html</code> output method may output a character using a
character entity reference, if one is defined for it in the version of
HTML that the output method is using.</p>

<p>The <code>html</code> output method should terminate processing
instructions with <code>&gt;</code> rather than
<code>?&gt;</code>.</p>

<p>The <code>html</code> output method should output boolean
attributes (that is attributes with only a single allowed value that
is equal to the name of the attribute) in minimized form. For example,
a start-tag written in the stylesheet as</p>

<div class="exampleInner"><pre>&lt;OPTION selected="selected"&gt;</pre></div>

<p>should be output as</p>

<div class="exampleInner"><pre>&lt;OPTION selected&gt;</pre></div>

<p>The <code>html</code> output method should not escape a
<code>&amp;</code> character occurring in an attribute value
immediately followed by a <code>{</code> character (see <a href="http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.7.1.1">Section
B.7.1</a> of the HTML 4.0 Recommendation). For example, a start-tag
written in the stylesheet as</p>

<div class="exampleInner"><pre>&lt;BODY bgcolor='&amp;amp;{{randomrbg}};'&gt;</pre></div>

<p>should be output as</p>

<div class="exampleInner"><pre>&lt;BODY bgcolor='&amp;{randomrbg};'&gt;</pre></div>

<p>The <code>encoding</code> attribute specifies the preferred
encoding to be used. If there is a <code>HEAD</code> element, then the
<code>html</code> output method should add a <code>META</code> element
immediately after the start-tag of the <code>HEAD</code> element
specifying the character encoding actually used. For example,</p>

<div class="exampleInner"><pre>&lt;HEAD&gt;
&lt;META http-equiv="Content-Type" content="text/html; charset=EUC-JP"&gt;
...</pre></div>

<p>It is possible that the result tree will contain a character that
cannot be represented in the encoding that the XSLT processor is using
for output.  In this case, if the character occurs in a context where
HTML recognizes character references, then the character should be
output as a character entity reference or decimal numeric character
reference; otherwise (for example, in a
<code>script</code> or <code>style</code> element or in a comment),
the XSLT processor should signal an error.</p>

<p>If the <code>doctype-public</code> or <code>doctype-system</code>
attributes are specified, then the <code>html</code> output method
should output a document type declaration immediately before the first
element.  The name following <code>&lt;!DOCTYPE</code> should be
<code>HTML</code> or <code>html</code>.  If the
<code>doctype-public</code> attribute is specified, then the output
method should output <code>PUBLIC</code> followed by the specified
public identifier; if the <code>doctype-system</code> attribute is
also specified, it should also output the specified system identifier
following the public identifier.  If the <code>doctype-system</code>
attribute is specified but the <code>doctype-public</code> attribute
is not specified, then the output method should output
<code>SYSTEM</code> followed by the specified system identifier.</p>

<p>The <code>media-type</code> attribute is applicable for the
<code>html</code> output method.  The default value is
<code>text/html</code>.</p>

</div>

<div class="div2">

<h3><a name="N10310"></a>16.3 Text Output Method</h3>

<p>The <code>text</code> output method outputs the result tree by
outputting the string-value of every text node in the result tree in
document order without any escaping.</p>

<p>The <code>media-type</code> attribute is applicable for the
<code>text</code> output method.  The default value for the
<code>media-type</code> attribute is <code>text/plain</code>.</p>

<p>The <code>encoding</code> attribute identifies the encoding that
the <code>text</code> output method should use to convert sequences of
characters to sequences of bytes.  The default is system-dependent. If
the result tree contains a character that cannot be represented in the
encoding that the XSLT processor is using for output, the XSLT
processor should signal an error.</p>

</div>

<div class="div2">

<h3><a name="disable-output-escaping"></a>16.4 Disabling Output Escaping</h3>

<p>Normally, the <code>xml</code> output method escapes &amp; and &lt;
(and possibly other characters) when outputting text nodes.  This
ensures that the output is well-formed XML. However, it is sometimes
convenient to be able to produce output that is almost, but not quite
well-formed XML; for example, the output may include ill-formed
sections which are intended to be transformed into well-formed XML by
a subsequent non-XML aware process.  For this reason, XSLT provides a
mechanism for disabling output escaping. An <code>xsl:value-of</code>
or <code>xsl:text</code> element may have a
<code>disable-output-escaping</code> attribute; the allowed values are
<code>yes</code> or <code>no</code>; the default is <code>no</code>;
if the value is <code>yes</code>, then a text node generated by
instantiating the <code>xsl:value-of</code> or <code>xsl:text</code>
element should be output without any escaping. For example,</p>

<div class="exampleInner"><pre>&lt;xsl:text disable-output-escaping="yes"&gt;&amp;lt;&lt;/xsl:text&gt;</pre></div>

<p>should generate the single character <code>&lt;</code>.</p>

<p>It is an error for output escaping to be disabled for a text node
that is used for something other than a text node in the result tree.
Thus, it is an error to disable output escaping for an
<code>xsl:value-of</code> or <code>xsl:text</code> element that is
used to generate the string-value of a comment, processing instruction
or attribute node; it is also an error to convert a node-set to a number or a string if the node-set contains a text node for which escaping
was disabled.  In both cases, an XSLT processor may signal the error;
if it does not signal the error, it must recover by ignoring the
<code>disable-output-escaping</code> attribute.</p>

<p id="diff-35">When a root node is copied using an
<code>xsl:copy-of</code> element (see <a href="#copy-of"><b>11.3 Using Values of Variables and Parameters with
xsl:copy-of</b></a>) and
escaping was disabled for a text node descendant of that root node,
then escaping should also be disabled for the resulting copy of that
text node. For example</p>

<div class="exampleInner"><pre>&lt;xsl:variable name="x"&gt;
&lt;xsl:text disable-output-escaping="yes"&gt;&amp;lt;&lt;/xsl:text&gt;
&lt;/xsl:variable&gt;
&lt;xsl:copy-of select="$x"/&gt;</pre></div>

<p>should output <code>&lt;</code> not
<code>&amp;lt;</code>.</p>

<p>Text nodes for which escaping is disabled are subject to
merging with text nodes that are adjacent in the result tree in the
same way as text nodes for which is escaping is not disabled.  An
element or root node in the result tree never has two consecutive text
node children. Thus, it is possible for a escaping to be disabled for
some but not all of the characters in a text node.</p>

<p>The <code>disable-output-escaping</code> attribute may be used with
the <code>html</code> output method as well as with the
<code>xml</code> output method.  The <code>text</code> output method
ignores the <code>disable-output-escaping</code> attribute, since it
does not perform any output escaping.</p>

<p>An XSLT processor will only be able to disable output escaping if
it controls how the result tree is output. This may not always be the
case.  For example, the result tree may be used as the source tree for
another XSLT transformation instead of being output.  An XSLT
processor is not required to support disabling output escaping.  If an
<code>xsl:value-of</code> or <code>xsl:text</code> specifies that
output escaping should be disabled and the XSLT processor does not
support this, the XSLT processor may signal an error; if it does not
signal an error, it must recover by not disabling output escaping.</p>

<p>If output escaping is disabled for a character that is not
representable in the encoding that the XSLT processor is using for
output, then the XSLT processor may signal an error; if it does not
signal an error, it must recover by not disabling output escaping.</p>

<p>Since disabling output escaping may not work with all XSLT
processors and can result in XML that is not well-formed, it should be
used only when there is no alternative.</p>


</div>

<div class="div2">

<h3><a name="multiple-output"></a>16.5 Multiple Output Documents</h3>


  
  
    
      
    
  
  
    
      
      
      
      
    
  
  
    
      
    
  
  
    
      
    
  
  
    
      
      
    
  
  
    
      
      
    
  
  
    
      
    
  
  
    
      
    
  
  
    
      
    
  
  
    
      
      
    
  
  
    
      
    
  
  


<p>The <code>xsl:document</code> element is used to create multiple
result documents.  As well as the main result document, there can be
subsidiary result documents.  Each subsidiary result document is
created using an <code>xsl:document</code> element. The content of the
<code>xsl:document</code> element is a template; this is instantiated
to create a sequence of nodes; a root node is created with this
sequence of nodes as its children; the tree with this root node
represents the subsidiary result document. The <code>href</code>
attribute specifies where the subsidiary document should be stored; it
must be an absolute or relative URI; it must not have a fragment
identifier. For example, the following would create a main result
document specifying an HTML frameset with two frames, together with
two subsidiary documents, one for the contents of each frame:</p>

<div class="exampleInner"><pre>&lt;xsl:template match="/"&gt;
  &lt;html&gt;
    &lt;head&gt;&lt;title&gt;Frame example&lt;/title&gt;&lt;/head&gt;
    &lt;frameset cols="20%, 80%"&gt;
      &lt;frame src="toc.html"/&gt;
      &lt;xsl:document href="toc.html"&gt;
        &lt;html&gt;
          &lt;head&gt;&lt;title&gt;Table of Contents&lt;/title&gt;&lt;/head&gt;
          &lt;body&gt;
             &lt;xsl:apply-templates mode="toc" select="*"/&gt;
          &lt;/body&gt;
        &lt;/html&gt;
      &lt;/xsl:document&gt;
      &lt;frame src="body.html"/&gt;
      &lt;xsl:document href="body.html"&gt;
        &lt;html&gt;
          &lt;head&gt;&lt;title&gt;Body&lt;/title&gt;&lt;/head&gt;
          &lt;body&gt;
             &lt;xsl:apply-templates select="*"/&gt;
          &lt;/body&gt;
        &lt;/html&gt;
      &lt;/xsl:document&gt;
    &lt;/frameset&gt;
  &lt;/html&gt;
&lt;/xsl:template&gt;</pre></div>

<p>The attributes on <code>xsl:output</code> elements affect only the
main result document. The output of a subsidiary result document is
controlled by the attributes on the <code>xsl:document</code> element
that was used to create that subsidiary result document. With the
exception of the <code>href</code> attribute which is allowed only on
<code>xsl:document</code>, the attributes on <code>xsl:document</code>
are applied to a subsidiary result document in the same way that the
attributes on <code>xsl:output</code> are applied to the main result
document. In particular, the <code>method</code> attribute on an
<code>xsl:document</code> element is defaulted based on the content of
the subsidiary document created by that <code>xsl:document</code>
element, not based on the content of the main result document.</p>

<p>Normally, <code>xsl:document</code> can be understood as directly
creating an additional result document.  However, when
<code>xsl:document</code> is used within <code>xsl:variable</code> or
<code>xsl:param</code> elements, the following more sophisticated
conceptual model is needed.</p>

<p>Documents involved in XSLT processing can be divided into two
categories.</p>

<ul>

<li><p>One category contains the documents that the XSLT processor
constructs by instantiating templates; these are the main
result document, subsidiary documents created by
<code>xsl:document</code>, and documents created by a variable-binding
element with content.</p></li>

<li><p>The other category contains the documents
constructed by parsing or other processes external to the XSLT
processor; these are the main source document and documents
returned by the <code>document</code> function.</p></li>

</ul>

<p>With each document in the former category, an XSLT processor
associates a possibly empty set of subsidiary documents. The
relationship between a document and its associated subsidiary
documents thus organizes documents in this category into one or more
unordered trees, where the associated subsidiary documents of a
document are considered the children of that document.  The main
result document is the root of one such tree; the documents created by
variable-binding elements with content are the roots of the other
trees.  Each subsidiary document created by an
<code>xsl:document</code> element has a parent within this tree of
documents.</p>

<p>During the processing of a stylesheet, there is a current result
document; initially this is the main result document; the current
result document is changed by the <code>xsl:document</code> element
and by variable-binding elements with content.  When an
<code>xsl:document</code> element is instantiated, the content is
instantiated with the subsidiary document being created by that
<code>xsl:document</code> element as the current result document. When
a variable-binding element with content is instantiated, the content
is instantiated with the document being created (that is, the document
whose root node is the sole member of the node-set that will be the
value of the variable defined by that element) as the current result
document.  A document created by the instantiation of an
<code>xsl:document</code> is not automatically output; instead, it is
added to the set of subsidiary documents associated with the current
result document.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>The <code>xsl:document</code> is allowed inside
<code>xsl:attribute</code>, <code>xsl:comment</code> and
<code>xsl:processing-instruction</code> and behaves in those contexts
in the same way as elsewhere.</p></div>

<div class="issue"><p class="prefix"><a name="issue-message-document"></a><b>Issue (issue-message-document):</b></p><p>What should happen if
<code>xsl:document</code> occurs inside
<code>xsl:message</code>?</p></div>

<p>When a root node is copied with <code>xsl:copy</code> or
<code>xsl:copy-of</code>, the subsidiary documents associated with the
document of which it is the root node are copied and added to the set
of subsidiary documents associated with the current result document.
Copying a subsidiary document copies its subsidiary documents
recursively.</p>

<p>Output conceptually follows the construction of the main result
document and any subsidiary documents.  The XSLT processor outputs the
main result document and its associated subsidiary documents; when the
XSLT processor outputs a subsidiary document it also recursively
outputs its associated subsidiary documents. Apart from this, no other
subsidiary documents are output.  A subsidiary document associated
with the document created by a variable-binding element with content
is not output; only copies created by the copying of the root node of
that document are ever output.</p>

<p>For each document that is output, there is an absolute URI that
can, in the appropriate circumstances, be used to access that
document.  Call this the output URI of the document.  The output URI
of the main result document is system-dependent, typically specified
when the XSLT processor is invoked.  When the <code>href</code>
attribute of a subsidiary document is an absolute URI, then that
absolute URI serves as the output URI.  When the <code>href</code>
attribute of a subsidiary document is a relative URI, the
relative URI is resolved into an absolute URI only if and when the
subsidiary document is output.  The output URI of the document with
which the subsidiary document is associated (ie the output URI of its
parent in the tree of documents) is used as the base URI.  The
resulting absolute URI is used as the output URI of the subsidiary
document.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>The output URI of a document is not dependent on the base URI
of the root node of the document.</p></div>

<p>It is an error if the set of documents to be output as the result
of a single XSLT transformation (that is, the main result document and
its subsidiary documents recursively) contain two documents with the
same output URI.</p>

</div>

</div>

<div class="div1">

<h2><a name="conformance"></a>17 Conformance</h2>

<p>A conforming XSLT processor must be able to use a stylesheet to
transform source trees into result trees as specified in this document.  A
conforming XSLT processor need not be able to output the result in XML
or in any other form.</p>

<div class="note"><p class="prefix"><b>Note:</b></p><p>Vendors of XSLT processors are strongly encouraged to provide
a way to verify that their processor is behaving conformingly by
allowing the result tree to be output as XML or by providing access to
the result tree through a standard API such as the DOM or
SAX.</p></div>

<p>A conforming XSLT processor must signal any errors except for those
that this document specifically allows an XSLT processor not to
signal. A conforming XSLT processor may but need not recover from any
errors that it signals.</p>

<p>A conforming XSLT processor may impose limits on the processing
resources consumed by the processing of a stylesheet.</p>

</div>

<div class="div1">

<h2><a name="notation"></a>18 Notation</h2>

<p>The specification of each XSLT-defined element type is preceded by
a summary of its syntax in the form of a model for elements of that
element type.  The meaning of syntax summary notation is as
follows:</p>

<ul>

<li><p>An attribute is required if and only if its name is in
bold.</p></li>

<li><p>The string that occurs in the place of an attribute value
specifies the allowed values of the attribute.  If this is surrounded
by curly braces, then the attribute value is treated as an <a title="Attribute Value Template" href="#dt-attribute-value-template">attribute value template</a>,
and the string occurring within curly braces specifies the allowed
values of the result of instantiating the attribute value template.
Alternative allowed values are separated by <code>|</code>.  A quoted
string indicates a value equal to that specific string. An unquoted,
italicized name specifies a particular type of value.</p></li>

<li><p>If the element is allowed not to be empty, then the element
contains a comment specifying the allowed content.  The allowed
content is specified in a similar way to an element type declaration
in XML; <em>template</em> means that any mixture of text nodes,
literal result elements, extension elements, and XSLT elements from
the <code>instruction</code> category is allowed;
<em>top-level-elements</em> means that any mixture of XSLT
elements from the <code>top-level-element</code> category is
allowed.</p></li>

<li><p>The element is prefaced by comments indicating if it belongs
to the <code>instruction</code> category or
<code>top-level-element</code> category or both.  The category of an
element just affects whether it is allowed in the content of elements
that allow a <em>template</em> or
<em>top-level-elements</em>.</p></li>

</ul>

</div>

</div>

<div class="back">
<div class="div1">

<h2><a name="N10922"></a>A References</h2>
<div class="div2">

<h3><a name="N10927"></a>A.1 Normative References</h3>

<dl>

<dt class="label"><a name="DOM2"></a>DOM2</dt><dd>World Wide Web Consortium. <em>Document
Object Model (DOM) Level 2 Core Specification.</em> W3C
Recommendation. See <a href="http://www.w3.org/TR/DOM-Level-2-Core/">http://www.w3.org/TR/DOM-Level-2-Core/</a></dd>

<dt class="label"><a name="ECMA262"></a>ECMA262</dt><dd>ECMA. <em>ECMA-262,
ECMAScript Language Specification, 3rd Edition</em> ECMA Standard.
See <a href="ftp://ftp.ecma.ch/ecma-st/Ecma-262.pdf">ftp://ftp.ecma.ch/ecma-st/Ecma-262.pdf</a></dd>

<dt class="label"><a name="XML"></a>XML</dt><dd>World Wide Web Consortium. <em>Extensible
Markup Language (XML) 1.0.</em> 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 class="label"><a name="XMLBASE"></a>XMLBASE</dt><dd>World Wide Web
Consortium. <em>XML Base.</em> W3C Candidate Recommendation. See
<a href="http://www.w3.org/TR/xmlbase/">http://www.w3.org/TR/xmlbase/</a></dd>

<dt class="label"><a name="XMLNAMES"></a>XML Names</dt><dd>World Wide Web
Consortium. <em>Namespaces in XML.</em> W3C Recommendation. See
<a href="http://www.w3.org/TR/REC-xml-names/">http://www.w3.org/TR/REC-xml-names/</a></dd>

<dt class="label"><a name="XPATH"></a>XPath</dt><dd>World Wide Web Consortium. <em>XML Path
Language.</em> W3C Recommendation. See <a href="http://www.w3.org/TR/xpath">http://www.w3.org/TR/xpath</a></dd>

</dl>
</div>
<div class="div2">

<h3><a name="N11053"></a>A.2 Other References</h3>

<dl>

<dt class="label"><a name="CSS2"></a>CSS2</dt><dd>World Wide Web Consortium.  <em>Cascading
Style Sheets, level 2 (CSS2)</em>.  W3C Recommendation.  See <a href="http://www.w3.org/TR/1998/REC-CSS2-19980512/">http://www.w3.org/TR/1998/REC-CSS2-19980512/</a></dd>

<dt class="label"><a name="DSSSL"></a>DSSSL</dt><dd>International Organization
for Standardization, International Electrotechnical Commission.
<em>ISO/IEC 10179:1996.  Document Style Semantics and Specification
Language (DSSSL)</em>.  International Standard.</dd>

<dt class="label"><a name="HTML"></a>HTML</dt><dd>World Wide Web Consortium. <em>HTML 4.0
specification</em>. W3C Recommendation. See <a href="http://www.w3.org/TR/REC-html40/">http://www.w3.org/TR/REC-html40/</a></dd>

<dt class="label"><a name="IANA"></a>IANA</dt><dd>Internet Assigned Numbers
Authority. <em>Character Sets</em>. See <a href="ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets">ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets</a>.</dd>

<dt class="label"><a name="LC3"></a>LC3</dt><dd>Scott Furman. <em>Java Method Overloading and
Live Connect 3</em>. See <a href="http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html">http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html</a>.</dd>

<dt class="label"><a name="RFC2278"></a>RFC2278</dt><dd>N. Freed, J. Postel.  <em>IANA
Charset Registration Procedures</em>.  IETF RFC 2278. See <a href="http://www.ietf.org/rfc/rfc2278.txt">http://www.ietf.org/rfc/rfc2278.txt</a>.</dd>

<dt class="label"><a name="RFC2376"></a>RFC2376</dt><dd>E. Whitehead, M. Murata.  <em>XML
Media Types</em>. IETF RFC 2376. See <a href="http://www.ietf.org/rfc/rfc2376.txt">http://www.ietf.org/rfc/rfc2376.txt</a>.</dd>

<dt class="label"><a name="RFC2396"></a>RFC2396</dt><dd>T. Berners-Lee, R. Fielding, and
L. Masinter.  <em>Uniform Resource Identifiers (URI): Generic
Syntax</em>. IETF RFC 2396. See <a href="http://www.ietf.org/rfc/rfc2396.txt">http://www.ietf.org/rfc/rfc2396.txt</a>.</dd>

<dt class="label"><a name="UNICODE-TR10"></a>UNICODE TR10</dt><dd>Unicode Consortium.
<em>Unicode Technical Report #10. Unicode Collation
Algorithm</em>.  Unicode Technical Report.  See <a href="http://www.unicode.org/unicode/reports/tr10/index.html">http://www.unicode.org/unicode/reports/tr10/index.html</a>.</dd>

<dt class="label"><a name="XHTML"></a>XHTML</dt><dd>World Wide Web Consortium. <em>XHTML
1.0: The Extensible HyperText Markup Language.</em> W3C Proposed
Recommendation. See <a href="http://www.w3.org/TR/xhtml1/">http://www.w3.org/TR/xhtml1/</a></dd>

<dt class="label"><a name="XPTR"></a>XPointer</dt><dd>World Wide Web
Consortium. <em>XML Pointer Language (XPointer).</em> W3C Working
Draft. See <a href="http://www.w3.org/TR/xptr">http://www.w3.org/TR/xptr</a></dd>

<dt class="label"><a name="XMLSTYLE"></a>XML Stylesheet</dt><dd>World Wide Web
Consortium. <em>Associating stylesheets with XML documents.</em>
W3C Recommendation. See <a href="http://www.w3.org/TR/xml-stylesheet/">http://www.w3.org/TR/xml-stylesheet/</a></dd>

<dt class="label"><a name="XSL"></a>XSL</dt><dd>World Wide Web Consortium.  <em>Extensible
Stylesheet Language (XSL).</em>  W3C Working Draft.  See <a href="http://www.w3.org/TR/xsl/">http://www.w3.org/TR/xsl/</a></dd>

<dt class="label"><a name="XSLT10"></a>XSLT10</dt><dd>World Wide Web
Consortium. <em>XSL Transformations (XSLT) Version 1.0</em> W3C
Recommendation. See <a href="http://www.w3.org/TR/1999/REC-xslt-19991116">http://www.w3.org/TR/1999/REC-xslt-19991116</a></dd>

<dt class="label"><a name="XSLT11REQ"></a>XSLT11REQ</dt><dd>World Wide Web
Consortium. <em>XSL Transformations Requirements Version 1.1</em>
W3C Working Draft. See <a href="http://www.w3.org/TR/xslt11req">http://www.w3.org/TR/xslt11req</a></dd>

<dt class="label"><a name="XSLT20REQ"></a>XSLT20REQ</dt><dd>World Wide Web
Consortium. <em>XSL Transformations Requirements Version 2.0</em>
W3C Working Draft. See <a href="http://www.w3.org/TR/xslt20req">http://www.w3.org/TR/xslt20req</a></dd>

</dl>

</div>
</div>

<div class="div1">

<h2><a name="element-syntax-summary"></a>B Element Syntax Summary</h2>



</div>

<div class="div1">

<h2><a name="N11359"></a>C DOM-Based Language Bindings</h2>

<p>This appendix defines three language bindings for extension
functions, each of which use the DOM2 core.</p>

<div class="div2">

<h3><a name="N11368"></a>C.1 DOM Issues</h3>

<p>XSLT Trees are presented to extensions functions in the form of
Document Object Model (DOM) Level 2 <a href="#DOM2">[DOM2]</a> core
interfaces.</p>

<p>Since the <a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1590626202">The
DOM Structure Model</a> and the <a href="http://www.w3.org/TR/xslt#data-model">XSLT Data Model</a>,
along with the <a href="http://www.w3.org/TR/xpath#data-model">XPath
Data Model</a>, are not fully equivalent, it is necessary to define
the mapping between the two models, and identify where tree
presentations may not be consistent between XSLT processors that use
different implementation strategies. The two types of XSLT processors
that we are concerned with are:</p>

<ul>

<li><p>The processor creates its own internal tree structure (or
internal XPath cache), and presents that structure to extensions via
DOM interfaces. In this case, the processor is fully in control of
the structure of the tree.</p></li>

<li><p>The XPath/XSLT data model is implemented as a view over the
a DOM that was passed to the XSLT processor. In this case the XSLT
processor generally has a contract with the caller that it can not
mutate the DOM, and so the XSLT processor is not fully in control of the
structure of the tree. For XSLT processors that are passed a DOM,
this DOM should be able to be presented to extensions without
modification.</p></li>

</ul>

<p>Thus, in order for an extension function to be fully interoperable,
it must take into account that it may be given node structures that
are not consistent from implementation to implementation. For
instance, Text nodes could be broken into several chunks, or could be
a single node. The text below enumerates the guidelines for how nodes
are to be passed to extension functions, and how node results are to
be returned.</p>

<p>An XSLT processor maintains a mapping that associates each XSLT
document with the DOM Document or DocumentFragment that represents it.
An XSLT processor need not create a DOM Document or DocumentFragment
to represent an XSLT document until a node from that XSLT document is
passed to an extension function using a DOM-based language binding.
Distinct XSLT documents are mapped to distinct DOM Documents or
DocumentFragments.</p>

<div class="div3">

<h4><a name="node-set-to-external-function"></a>C.1.1 Passing an XPath node-set to an Extension Function</h4>

<p>A XPath node-set is mapped to a DOM NodeList, by building a list of
the XPath nodes in document order and then mapping each XPath node in
the list to a DOM node.</p>

<p>XPath nodes are mapped to DOM nodes as follows.</p>

<ul>
<li>
<p>A root node is presented as a Document node.</p>
</li>
<li>
<p>An element node is presented as an Element node.</p>
</li>
<li>
<p>An attribute node is presented as an Attr node.</p>
</li>
<li>
<p>The DOM tree may contain additional Attr nodes with
the name "xmlns" or "xmlns:*" to represent namespaces. Since a DOM
may use namespaces that are not declared, an extension function can
not rely on these namespace declarations being present.</p>
</li>
<li>
<p>A text node is presented as a Text node (which might
or might not be normalized). This Text may be a derived CDATASection.
</p>
<div class="issue"><p class="prefix"><a name="issue-multiple-dom-text-nodes"></a><b>Issue (issue-multiple-dom-text-nodes):</b></p><p>What happens
if a single XPath text node is represented by multiple
DOM Text nodes (because of unnormalized Text nodes, CDATA sections
or entity references)?</p></div>
</li>
<li>
<p>A comment node is presented as a Comment node.</p>
</li>
<li>
<p>A processing instruction node is presented as a
ProcessingInstruction node.</p>
</li>
<li>
<p>The DOM tree may or may not contain nodes to
represent constructs that are absent from the XPath data model, for
example entity references, and Notation nodes.</p>
</li>
</ul>

<p>Where whitespace has been stripped from the XPath tree,
the DOM tree may or may not contain nodes representing such
whitespace. Extension functions should not rely on the presence or
absense of such whitespace.</p>

<p>The extension function may navigate freely from the nodes actually
supplied to other nodes in the tree, using the standard DOM
interfaces. Attempting to modify the tree is not recommended: the
processor may throw a DOMException if such an attempt is made. In any
case, the effect of mutation of the source tree during transformation
is undefined.</p>

<p>The result of calling methods that create new nodes, for example
<code>createElement</code>, is undefined; the processor may throw a
DOMException if such an attempt is made.  This restriction does not
apply to the DOM <code>Document</code> that is the value
of the ownerDocument attribute on XSLTContext.</p>

<p>The names and values of DOM nodes will follow the standard DOM
semantics, not the XPath semantics. For example the name of a comment
node will be <code>#comment</code>.</p>

<p>The result of calling <code>getDocumentType</code> is undefined:
the processor may throw a DOMException if such an attempt is made.</p>

<p>The result of calling <code>getSpecified</code> on an
<code>Attr</code> node is undefined, since this information is not
available in the XPath data model.</p>

</div>

<div class="div3">

<h4><a name="N11530"></a>C.1.2 Returning a NodeList or Node from an Extension Function</h4>

<p>When the implementation of an extension function returns a DOM
Node, an XSLT processor will attempt to map that Node to an XSLT node
as follows:</p>

<ol>

<li><p>First, it determines the root of the DOM tree containing this
DOM Node by using the <code>parentNode</code> <code>Node</code>
attribute and the <code>ownerElement</code> <code>Attr</code>
attribute.  It is an error if this root is neither a DOM
<code>Document</code> nor a DOM
<code>DocumentFragment</code>.</p></li>

<li><p>Next, it determines which XSLT document is associated with
this DOM <code>Document</code> or <code>DocumentFragment</code> root.
If there is no such XSLT document, then the XSLT processor attempts to
create a new XSLT document from the DOM <code>Document</code> or
<code>DocumentFragment</code> root.  It is only required to be able to
do so in the case where the root is a <code>DocumentFragment</code>
whose <code>ownerDocument</code> is the same as the
<code>XSLTContext</code> <code>ownerDocument</code> attribute.  When
it creates a new XSLT document, namespace fixup (see <a href="#namespace-fixup"><b>3.5 Namespace Fixup</b></a>) is performed; whitespace stripping
(see <a href="#strip"><b>3.4 Whitespace Stripping</b></a>) is <em>not</em> performed.
Once an XSLT document has
been created for a particular DOM <code>Document</code> or
<code>DocumentFragment</code>, modification to that
<code>Document</code> or <code>DocumentFragment</code> is no longer
allowed; the XSLT processor may throw a DOM exception if an extension
function attempts this.  The newly created XSLT document is associated
with the DOM <code>Document</code> or <code>DocumentFragment</code>
root from which it was created, so that if an extension function
subsequently returns that same <code>Document</code> or
<code>DocumentFragment</code>, it will be mapped to the same XSLT
document.</p></li>

<li><p>Finally, it determines which node in that XSLT document
corresponds to the DOM <code>Node</code> that is being mapped.</p></li>

</ol>

<p>Thus, if a node-set containing a single node is passed to an
extension function as a DOM <code>Node</code> and the implementation
of the extension function returns that same DOM <code>Node</code>,
then the result of calling function will be a node-set containing a
single node, which is the same node as the node in the node-set passed
to the extension function.</p>

<p>An implementation of an extension function may also return a DOM
<code>NodeList</code>.  In this case, each DOM <code>Node</code> in
the <code>NodeList</code> is converted to an XSLT node and the
<code>NodeList</code> is converted to a node-set containing all of the
resulting nodes.</p>

<p>The implementation of an extension function can use the
<code>XSLTContext</code> <code>ownerDocument</code> attribute to
create DOM <code>Node</code>s.  Before an implementation of an
extension function returns DOM <code>Node</code>s that it has created,
it should also create a <code>DocumentFragment</code> in the same way
and add those <code>Node</code>s to that
<code>DocumentFragment</code>.  It can also return the
<code>DocumentFragment</code> itself, which will be mapped to an XSLT
root node.</p>

<p>The only operations allowed on the <code>Document</code> that is
the value of the <code>XSLTContext</code> <code>ownerDocument</code>
attribute are calls to the following methods:
<code>createDocumentFragment</code>, <code>createElement</code>,
<code>createElementNS</code>, <code>createAttribute</code>,
<code>createAttributeNS</code>, <code>createTextNode</code>,
<code>createComment</code>, <code>createProcessingInstruction</code>,
<code>importNode</code>.  The result of calling any other methods or
accessing any attributes is implementation-dependent.</p>

</div>

</div>

<div class="div2">

<h3><a name="N11723"></a>C.2 IDL/DOM2 Language Binding</h3>

<p>The following specifies the <code>XSLTContext</code> interface in
IDL:</p>

<div class="exampleInner"><pre>// File: xslt.idl
#pragma prefix "w3c.org"
#include "dom.idl"
module xslt
{
  typedef sequence&lt;unsigned short&gt; XPathString;
  interface XSLTContext {
    // ---- Properties/Attributes ----
    // context node from XPath expression context
    readonly attribute dom::Node contextNode;
    // context position from XPath expression context
    readonly attribute unsigned long contextPosition;
    // context size from XPath expression context
    readonly attribute unsigned long contextSize;
    // current node from XSLT context; same as calling
    // current() function from the XPath expression context
    readonly attribute dom::Node currentNode;
    // Document to be used for creating nodes
    readonly attribute dom::Document ownerDocument;
    // ---- Methods ----
    // XSLT System Property
    Object systemProperty(in XPathString namespaceURI,
                          in XPathString localName);
    // Return the string value of the Node passed in
    stringValue(in dom::Node n);
  };
};</pre></div>

</div>

<div class="div2">

<h3><a name="ecmascript-binding"></a>C.3 ECMAScript/DOM2 Language Binding</h3>

<p>This section defines the ECMAScript <a href="#ECMA262">[ECMA262]</a>
language binding for XSLT extension functions.</p>

<p>To implement an extension function in ECMAScript, stylesheet
developers associate an implementation to their extension function
namespace prefix using an <code>xsl:script</code> element with
<code>language="ecmascript"</code> or <code>language="javascript"</code>
as in the following example:</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:date="http://www.example.com/2000/XSLT/library/date"&gt;

&lt;xsl:param name="upperCust" select="true()"/&gt;

&lt;xsl:script implements-prefix="date"
             language="ecmascript"
             src="DateRoutines.js"/&gt;
&lt;xsl:script implements-prefix="util"
             language="ecmascript"&gt;
function upper(n) {
  return n.toUpperCase();
}
function lower(n) {
 return n.toLowerCase();
}

function iff(arg1, arg2, arg3) {
  if (arg1) {
    return arg2;
  }
  else {
    return arg3;
  }
}
&lt;/xsl:script&gt;

&lt;xsl:template match="/"&gt;
  &lt;CustomerId&gt;
    &lt;xsl:value-of select="util:iff($upperCust,
                                   util:upper(/order/custid),
                                   util:lower(/order/custid))"/&gt;
  &lt;/CustomerId&gt;
  &lt;OrderDate&gt;
    &lt;xsl:value-of select="date:format(/order/date,'MM/DD/YY')"/&gt;
  &lt;/OrderDate&gt;
&lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></div>

<p>For ECMAScript, the value of the <code>src</code> attribute on
<code>xsl:script</code> is a URI reference of an ECMAScript resource
that defines the functions associated with the namespace URI specified
by the <code>implements-prefix</code> attribute. The implementation
can also be provided locally by omitting the <code>src</code>
attribute and including the script function definitions as the content
of the <code>xsl:script</code> element.</p>

<p>The ECMAScript standard <a href="#ECMA262">[ECMA262]</a> allows conforming
implementations to provide additional types, values, objects
properties and program syntax beyond that described in the ECMAScript
standard.  For maximum portability, implementations of extension
functions should rely only what is defined in the ECMAScript standard
itself.</p>

<p>Functions provided by <code>xsl:script</code> elements with
distinct namespace URIs execute in distinct contexts to avoid name
collisions.</p>

<table border="1" summary="Editorial note"><tr><td align="left" valign="top" width="50%"><b>Editorial note</b></td><td align="right" valign="top" width="50%">&nbsp;</td></tr><tr><td colspan="2" align="left" valign="top">Figure out what the correct way to say this is in
terms of the ECMAScript standard. Probably need to say there is a
distinct global object for each namespace URI.</td></tr></table>

<p>When multiple <code>xsl:script</code> elements with the same
namespace URI and the <code>ecmascript</code> language are
encountered, the scripts for each element are concatenated in import
precedence order, lowest precedence first. This allows a function
provided by an <code>xsl:script</code> element of higher import
precedence to redefine a function of the same name provided by an
<code>xsl:script</code> element of lower import precedence.</p>

<p>A function with given local name and namespace URI is considered to
be available for the purposes of the <code>function-available</code>
function if, after executing all the scripts associated with that
namespace URI, the global object for the namespace URI has a property
with the specified local name whose value is a function.</p>

<p>The local part of the expanded-name of the extension function is
converted to the ECMAScript function name as follows. For each hyphen
in the local part of the expanded-name of the function, the character
following the hyphen is converted to upper-case using the
<code>toUpperCase</code> method of the ECMAScript <code>String</code>
object, and then the hyphen is removed. For example, the name
<code>get-value</code> would be treated as equivalent to
<code>getValue</code>.</p>

<p>The following function argument conversions are performed:</p>

<ul>
<li><p>An XPath <code>string</code> object is mapped to an ECMAScript
<code>string</code> value</p></li>
<li><p>An XPath <code>number</code> object is mapped to an ECMAScript
<code>number</code> value</p></li>
<li><p>An XPath <code>boolean</code> object is mapped to an ECMAScript
<code>boolean</code> value</p></li>
<li><p>An XPath <code>node-set</code> object is mapped to the ECMAScript
binding for the DOM <code>NodeList</code></p></li>
<li><p>An XSLT external object is mapped to the ECMAScript
<code>object</code> that it wraps</p></li>
</ul>

<p>The following conversions are performed on return values.</p>

<ul>

<li><p>An ECMAScript string value or String object is mapped to an XPath
string object.</p></li>

<li><p>An ECMAScript number value or Number object is mapped to an XPath
number object.</p></li>

<li><p>An ECMAScript boolean value or Boolean object is mapped to
an XPath boolean object.</p></li>

<li><p>An ECMAScript objects that is an instance of any of the
following objects:</p>

<ul>
<li>
<p>DocumentFragment</p>
</li>
<li>
<p>Document</p>
</li>
<li>
<p>Node</p>
</li>
<li>
<p>NodeList</p>
</li>
<li>
<p>Attr</p>
</li>
<li>
<p>Element</p>
</li>
<li>
<p>Text</p>
</li>
<li>
<p>Comment</p>
</li>
<li>
<p>CDATASection</p>
</li>
<li>
<p>EntityReference</p>
</li>
<li>
<p>ProcessingInstruction</p>
</li>
</ul>
<p>are mapped to an XPath <code>node-set</code>.</p>
</li>
<li>
<p>The ECMAScript null value is mapped to an XSLT external object.</p>
</li>
<li>
<p>The ECMAScript undefined value is mapped to an empty node-set.</p>
</li>
<li>
<p>Any other ECMAScript object is mapped to an XSLT external object.</p>
</li>
</ul>

<p>The following specifies the <code>XSLTContext</code> object
language binding for ECMAScript. It is accessible as a property
of the global object.</p>

<div class="exampleInner"><pre>Object XSLTContext

// Property: context node from XPath expression context
//     Type: Node
contextNode

// Property: context position from XPath expression context
//     Type: number
contextPosition

// Property: context size from XPath expression context
//     Type: number
contextSize

// Property: current node from XSLT context
//     Type: Node
currentNode

// Property: Document to be used for creating nodes
//     Type: Document
ownerDocument

//   Method: Return the system property of the specified name
//  Returns: Object
systemProperty(String namespaceURI, String localName)

//   Method: Return the XPath string value of the node passed in
//  Returns: string value
stringValue(Node n)</pre></div>

</div>

<div class="div2">

<h3><a name="java-binding"></a>C.4 Java/DOM2 Language Binding</h3>

<p>This section defines the Java language binding for XSLT extension
functions.</p>

<table border="1" summary="Editorial note"><tr><td align="left" valign="top" width="50%"><b>Editorial note</b></td><td align="right" valign="top" width="50%">&nbsp;</td></tr><tr><td colspan="2" align="left" valign="top">Need normative reference to Java language
spec.</td></tr></table>

<p>To implement an extension function in Java, stylesheet developers
associate an implementation to their extension function namespace
prefix using an <code>xsl:script</code> element with
<code>language="java"</code> as in the following example:</p>

<div class="exampleInner"><pre>&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:date="<var>uri.any</var>"&gt;

&lt;xsl:script implements-prefix="date" language="java"
src="java:com.example.datestuff.DateRoutines"/&gt;

&lt;xsl:template match="/"&gt;
&lt;OrderDate&gt;
&lt;xsl:value-of select="date:format(/order/date,'MM/DD/YY')"/&gt;
&lt;/OrderDate&gt;
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;</pre></div>

<p>For Java, the value of the <code>src</code> attribute on
<code>xsl:script</code> is a URI reference identifying a Java class;
the methods of this class implement the functions whose expanded-names
have the namespace URI specified by the <code>implements-prefix</code>
attribute.  The URI specified by the <code>src</code> attribute may
use the <code>java:</code> URI scheme:
<code>src="java:<var>fully.qualified.ClassName</var>"</code>; the XSLT
processor may also allow the URI to use other URI schemes to locate
a resource containing the Java class file.</p>

<p>When multiple <code>xsl:script</code> elements implementing
the same prefix for the same language are encountered, the processor
will use the <code>xsl:script</code> element with the highest
import precedence to identify the code unit for the extension
function namespace.</p>

<p>The <code>function-available</code> function returns true
if the named class can be loaded and if it has at least one public
method with the specified name. The expression
<code>function-available('xyz:new')</code> evaluates to true if the
associated class has any constructor.  If
<code>function-available</code> returns false, then a call on
the function will fail; if it returns true, there is no guarantee that
any particular call will succeed.</p>

<p>If a Java extension function throws an unhandled exception, it will
be considered an error in the XSLT processing, the transformation may
stop, and the error message from the exception should be reported.</p>

<div class="issue"><p class="prefix"><a name="issue-java-extension-state"></a><b>Issue (issue-java-extension-state):</b></p><p>At the moment, there is no way for
the implementation of a function in Java to cache information in a
thread-safe way.  For example, there is no way to implement an
extension function that would behave like the built-in
<code>document</code> function, which needs to keep a URI-to-Document
mapping, in order to ensure that it always returns the same Document
for the same URI.</p></div>

<div class="div3">

<h4><a name="java-identify-method"></a>C.4.1 Identifying the Java Method</h4>

<p>The local part of the <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> of the
extension function specifies the name of the method to be called.  To
invoke an instance method for a particular Java object, that Java
object is passed as the first argument to the function call.  A
constructor is treated as a static method named <code>new</code>.</p>

<p>Names are "camel-cased" as follows. For each hyphen in
the local part of the expanded-name of the function, the character
following the hyphen is converted to upper-case using the
<code>toUpperCase</code> method of <code>java.lang.Character</code>,
and then the hyphen is removed. For example, the name
<code>get-value</code> would be treated as equivalent to
<code>getValue</code>.</p>

<p>It is not possible to invoke a Java method whose name is not an
<a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCName</a>, for example, a name
containing a dollar sign character.</p>

<p>Java allows method overloading: a class may have more than one
method with the same name, so long as each method has a different
signature (different argument types).  The XSLT processor uses the
arguments passed to the extension function to determine which method
to call and resolve the method name to a particular method.  The
algorithm used for method resolution is based on <a href="#LC3">[LC3]</a>;
this uses an approach that is similar to the approach that the Java
language uses to resolve method names.</p>

<p>The first step in resolving a method invocation is to determine which
methods of a class are accessible and applicable. A Java method is
accessible and applicable if all of the following are true:</p>
<ul>
<li>
<p>The method is public.</p>
</li>
<li>
<p>The method name is the same as the local name of the extension function after camel-casing.</p>
</li>
<li>
<p>The number of parameters in the method declaration equals the
number of argument expressions in the function call expression with the
following exceptions:</p>
<ul>
<li>
<p>The method may have an optional, leading
<code>XSLTContext</code> argument. In this case the method would have one more
than the number of argument expressions in the method invocation.</p>
</li>
<li>
<p>If the method is an instance method, the current instance of
the object is passed as the first extension function argument. In
this case, the method would have one fewer than the number of
argument expressions in the function call expression.</p>
</li>
</ul>
</li>
<li>
<p>The type of each actual argument can be converted according to
the rules specified in <a href="#java-argument-conversions"><b>C.4.2 Argument Conversions</b></a>
below.</p>
</li>
</ul>

<p>If there are no applicable methods for an invocation, an error
occurs. If there is only one applicable method, it is the one
invoked. If there is more than one applicable method, then the
following algorithm is applied to determine which to invoke.</p>

<p>When determining which of the applicable methods to invoke, the
processor must apply the algorithm described below with a special test
for an XSLTContext object (see <a href="#java-expression-context"><b>C.4.4 Accessing XSLT Context Information</b></a>), as the first argument to the
method. Methods that have the XSLTContext as the first argument are
preferred over methods that do not.</p>

<p>When choosing between two or more applicable methods, an algorithm
is used that is similar in spirit to the ones used in Java and C++.
Suppose that <var>U</var> and <var>S</var> are both applicable methods
for an invocation, each having n parameters. Suppose, moreover, that
the Java types of the parameters for method <var>U</var> are
<var>u</var><sub>1</sub>,...,<var>u</var><var><sub>n</sub></var> and
the Java types of the parameters for method <var>S</var> are
<var>s</var><sub>1</sub>,...,<var>s</var><var><sub>n</sub></var>. Finally,
the runtime XSLT types of the actual arguments are
<var>t</var><sub>1</sub>,...,<var>t</var><var><sub>n</sub></var>. Then
the method <var>U</var> is preferred over method <var>S</var> if and
only if for all <var>j</var> from 1 to <var>n</var>:</p>

<ul>
<li>
<p><var>u</var><var><sub>j</sub></var> and
<var>s</var><var><sub>j</sub></var> are the same type, or</p>
</li>
<li>
<p>conversion to type <var>u</var><var><sub>j</sub></var> is preferred
to the conversion to type <var>s</var><var><sub>j</sub></var> when
converting from <var>t</var><var><sub>j</sub></var></p>
</li>
</ul>

<p>A method is said to be maximally preferred for a method invocation if
it is applicable and there is no more preferred applicable method. If
there is only one maximally preferred method, that method is
necessarily preferred to all other applicable methods and it is the
one invoked. If there is more than one maximally preferred method, an
error should be thrown.</p>

</div>

<div class="div3">

<h4><a name="java-argument-conversions"></a>C.4.2 Argument Conversions</h4>

<p>The following table specifies the allowed conversions of XSLT
objects to Java values when converting arguments for method
invocation. If a conversion is not specifically listed below, then it
is disallowed.  In each section corresponding to an XPath type below,
Java types are listed in order of preference, most preferred
first. Types that are equally preferred are listed in the same table
cell.</p>

<table width="100%" border="1">
<tbody>
<tr>
<th align="center" rowspan="1" colspan="1">XSLT argument type</th>
<th align="center" rowspan="1" colspan="1">Java argument type</th>
<th align="center" rowspan="1" colspan="1">Conversion technique</th>
</tr>
<tr>
<td rowspan="6" colspan="1">boolean</td>
<td rowspan="1" colspan="1">boolean</td>
<td rowspan="2" colspan="1">Convert XSLT true, false objects to corresponding
Java true, false values.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Boolean</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Object</td>
<td rowspan="1" colspan="1">Convert as for java.lang.Boolean.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.String</td>
<td rowspan="1" colspan="1">Convert to a string as if by a call to the
string function.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">double, float, long, int, short, byte</td>
<td rowspan="2" colspan="1">Convert to a number as if by a call to the
number and then
use the rules for converting from an XSLT number.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Double, java.lang.Float, java.lang.Long,
java.lang.Integer, java.lang.Short, java.lang.Byte</td>
</tr>
<tr>
<td rowspan="18" colspan="1">number</td>
<td rowspan="1" colspan="1">double</td>
<td rowspan="2" colspan="1">Transfer exact value to Java without any conversion.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Double</td>
</tr>
<tr>
<td rowspan="1" colspan="1">float</td>
<td rowspan="2" colspan="1">Round XSLT number to float precision.
Values that are to large to be represented by a float
are converted to positive or negative infinity.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Float</td>
</tr>
<tr>
<td rowspan="1" colspan="1">long</td>
<td rowspan="10" colspan="1">Truncate XSLT number to integral value by eliminating
fractional part. NaNs or numbers with a magnitude too large to be
represented in the target integral type result in a runtime error.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Long</td>
</tr>
<tr>
<td rowspan="1" colspan="1">int</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Integer</td>
</tr>
<tr>
<td rowspan="1" colspan="1">short</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Short</td>
</tr>
<tr>
<td rowspan="1" colspan="1">char</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Character</td>
</tr>
<tr>
<td rowspan="1" colspan="1">byte</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Byte</td>
</tr>
<tr>
<td rowspan="1" colspan="1">boolean</td>
<td rowspan="2" colspan="1">Convert number to boolean as if by a call to the
boolean function.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Boolean</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.String</td>
<td rowspan="1" colspan="1">Convert number to string as if by a call to the
string function.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Object</td>
<td rowspan="1" colspan="1">Convert as for java.lang.Double.</td>
</tr>
<tr>
<td rowspan="8" colspan="1">string</td>
<td rowspan="1" colspan="1">java.lang.String</td>
<td rowspan="1" colspan="1">Convert from XSLT string to java.lang.String</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Object</td>
<td rowspan="1" colspan="1">Convert as for java.lang.String.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">char</td>
<td rowspan="2" colspan="1">For one-character strings, result is
Unicode character. For strings longer than 1 character, an error is
raised.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Character</td>
</tr>
<tr>
<td rowspan="1" colspan="1">double, float, long, int, short, byte</td>
<td rowspan="2" colspan="1">Convert string to number as if by a call to the
number function, and then use
the rules for converting from an XSLT number.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Double, java.lang.Float, java.lang.Long,
java.lang.Integer, java.lang.Short, java.lang.Byte</td>
</tr>
<tr>
<td rowspan="1" colspan="1">boolean</td>
<td rowspan="2" colspan="1">Convert string to boolean as if by a call to the
boolean function.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Boolean</td>
</tr>
<tr>
<td rowspan="10" colspan="1">node-set</td>
<td rowspan="1" colspan="1"><a href="http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html#org.w3c.dom.NodeList">org.w3c.dom.NodeList</a></td>
<td rowspan="1" colspan="1">Map the node-set to a org.w3c.dom.NodeList as described in
<a href="#node-set-to-external-function"><b>C.1.1 Passing an XPath node-set to an Extension Function</b></a>.</td>
</tr>
<tr>
<td rowspan="1" colspan="1"><a href="http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html#org.w3c.dom.Node">org.w3c.dom.Node</a>,
<a href="http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html#org.w3c.dom.Attr">org.w3c.dom.Attr,</a>
<a href="http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html#org.w3c.dom.CDATASection">org.w3c.dom.CDATASection</a>,
<a href="http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html#org.w3c.dom.CharacterData">org.w3c.dom.CharacterData</a>,
<a href="http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html#org.w3c.dom.Comment">org.w3c.dom.Comment</a>,
<a href="http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html#org.w3c.dom.Document">org.w3c.dom.Document</a>,
<a href="http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html#org.w3c.dom.Element">org.w3c.dom.Element</a>,
<a href="http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html#org.w3c.dom.ProcessingInstruction">org.w3c.dom.ProcessingInstruction</a>,
<a href="http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html#org.w3c.dom.Text">org.w3c.dom.Text</a></td>
<td rowspan="1" colspan="1">Take first node from node-set, and
map to a Node as described in the section on
<a href="#node-set-to-external-function"><b>C.1.1 Passing an XPath node-set to an Extension Function</b></a>.
It is a runtime error if the resulting Node is not assignable
to the Java argument type.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.String</td>
<td rowspan="1" colspan="1">Convert node-set to string as if by a call to the
string function.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Object</td>
<td rowspan="1" colspan="1">Convert as to org.w3c.dom.NodeList</td>
</tr>
<tr>
<td rowspan="1" colspan="1">char</td>
<td rowspan="2" colspan="1">Convert node-set to string as if by a call to the
string function;
then use the rule for converting from an XSLT string to a char.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Character</td>
</tr>
<tr>
<td rowspan="1" colspan="1">double, float, long, int, short, byte</td>
<td rowspan="2" colspan="1">Convert node-set to number as if by a call to the
number function, then
use the rules for converting from an XSLT number.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Double, java.lang.Float, java.lang.Long,
java.lang.Integer, java.lang.Short, java.lang.Byte</td>
</tr>
<tr>
<td rowspan="1" colspan="1">boolean</td>
<td rowspan="2" colspan="1">Convert node-set to boolean as if by a call to the
boolean function.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Boolean</td>
</tr>
<tr>
<td rowspan="6" colspan="1">external object</td>
<td rowspan="1" colspan="1">Any interface or class that is
assignment-compatible with the Java object wrapped by the external
object, i.e. the wrapped Java object is an
<code>instanceof</code> the Java argument type</td>
<td rowspan="1" colspan="1">Use the Java object wrapped by the external object.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.String</td>
<td rowspan="1" colspan="1">Call the wrapped object's <code>toString</code> method
and return the result as a new java.lang.String.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">char</td>
<td rowspan="2" colspan="1">Call the wrapped object's <code>toString</code> method
and convert the string to a char using the rules
for converting from an XSLT string.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Character</td>
</tr>
<tr>
<td rowspan="1" colspan="1">double, float, long, int, short, byte</td>
<td rowspan="2" colspan="1">Call the wrapped object's <code>toString</code> method,
and convert the resulting string to an XSLT number
as by a call to the number function.
Then convert the number using the rules
for converting from an XSLT number.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">java.lang.Double, java.lang.Float, java.lang.Long,
java.lang.Integer, java.lang.Short, java.lang.Byte</td>
</tr>
</tbody>
</table>

<p>Among Java class or interface types, further processing is
required.  Intuitively, the rule for preference among Java types when
converting from a Java object that is wrapped in an XSLT external
object is that the most specific class or interface is preferred. More
formally, let <var>T</var> be the Java class of the Java object
wrapped by an external object.  Let <var>S</var> and <var>U</var> be
class or interface types. <var>S</var> is preferred to <var>U</var> if
and only if:</p>

<ul>
<li>
<p>An instance of <var>T</var> is assignable to a variable of type
<var>S</var>, i.e. <var>T</var> instanceof <var>S</var> is true</p>
</li>
<li>
<p>An instance of <var>S</var> is assignable to a variable of type
<var>U</var>, i.e. <var>S</var> instanceof <var>U</var> is true</p>
</li>
<li>
<p><var>S</var> and <var>U</var> are not the same types</p>
</li>
</ul>

</div>

<div class="div3">

<h4><a name="N13111"></a>C.4.3 Return Value Conversions</h4>

<p>Values returned by an extension function implemented
by a Java method are converted as follows.</p>

<ul>

<li><p>If the Java method returns void, the XPath function returns
an empty node-set.</p></li>

<li><p>If the Java method returns null, the XPath function
returns an external object that wraps null.</p></li>

<li><p>If the Java method returns a String, the XPath function returns the
equivalent string. This string must consist of characters that are
valid in XML.</p></li>

<li><p>If the Java method returns a <code>double</code>, <code>int</code>,
<code>float</code>, <code>long</code>, <code>short</code>,
<code>char</code>, <code>byte</code> or their object equivalents, the
XPath function returns the equivalent number.</p></li>

<li><p>If the Java method returns a <code>boolean</code> or
<code>Boolean</code>, the XPath function returns the equivalent
boolean.</p></li>

<li><p>If the Java method returns an <code>org.w3c.dom.NodeList</code>, the
XPath function returns a node-set.</p></li>

<li><p>If the Java method returns a DOM Node or an object of a type from a
DOM Node, then XPath function returns a node-set with a single
member.</p></li>

<li><p>If the Java method returns any other object, the XPath function
returns a external object that wraps that object.</p></li>

</ul>

</div>

<div class="div3">

<h4><a name="java-expression-context"></a>C.4.4 Accessing XSLT Context Information</h4>

<p>The way in which the XSLTContext object is passed to an extension
function is specified in <a href="#java-identify-method"><b>C.4.1 Identifying the Java Method</b></a>. The
<code>XSLTContext</code> interface is as follows:</p>

<div class="exampleInner"><pre>package org.w3c.xsl;

import org.w3c.dom.Node;
import org.w3c.dom.Document;

/**
 * Interface to be used with XSLT extension functions written in Java
 */
interface XSLTContext
{
    /**
     * Return context node from the XPath expression context.
     */
    Node getContextNode();
    /**
     * Returns the context position from the XPath expression context.
     */
    int getContextPosition();
    /**
     * Returns the context size from the XPath expression context.
     */
    int getContextSize();
    /**
     * Returns the current node from the XSLT context; the same
     * as calling current() function from the XPath expression context.
     */
    Node getCurrentNode();
    /**
     * Returns a Document to be used for creating nodes.
     */
    Document getOwnerDocument();
    /**
     * Returns an Object representing the value of the system property
     * whose expanded-name has the specified namespace URI and local part.
     */
    Object systemProperty(String namespaceURI, String localName);
    /**
     * Returns the string-value of the specified Node.
     */
    String stringValue(Node n);
};</pre></div>

</div>
</div>
</div>

<div class="div1">

<h2><a name="dtd"></a>D DTD Fragment for XSLT Stylesheets (Non-Normative)</h2>

<div class="note"><p class="prefix"><b>Note:</b></p><p>This DTD Fragment is not normative because XML 1.0 DTDs do
not support XML Namespaces and thus cannot correctly describe the
allowed structure of an XSLT stylesheet.</p></div>

<p>The following entity can be used to construct a DTD for XSLT
stylesheets that create instances of a particular result DTD.  Before
referencing the entity, the stylesheet DTD must define a
<code>result-elements</code> parameter entity listing the allowed
result element types.  For example:</p>

<div class="exampleInner"><pre>&lt;!ENTITY % result-elements "
  | fo:inline-sequence
  | fo:block
"&gt;</pre></div>

<p>Such result elements should be declared to have
<code>xsl:use-attribute-sets</code> and
<code>xsl:extension-element-prefixes</code> attributes.  The following
entity declares the <code>result-element-atts</code> parameter for
this purpose. The content that XSLT allows for result elements is the
same as it allows for the XSLT elements that are declared in the
following entity with a content model of <code>%template;</code>.  The
DTD may use a more restrictive content model than
<code>%template;</code> to reflect the constraints of the result
DTD.</p>

<p>The DTD may define the <code>non-xsl-top-level</code> parameter
entity to allow additional top-level elements from namespaces other
than the XSLT namespace.</p>

<p>The use of the <code>xsl:</code> prefix in this DTD does not imply
that XSLT stylesheets are required to use this prefix.  Any of the
elements declared in this DTD may have attributes whose name starts
with <code>xmlns:</code> or is equal to <code>xmlns</code> in addition
to the attributes declared in this DTD.</p>

<div class="exampleInner"><pre>&lt;!ENTITY % char-instructions "
  | xsl:apply-templates
  | xsl:call-template
  | xsl:apply-imports
  | xsl:for-each
  | xsl:value-of
  | xsl:copy-of
  | xsl:number
  | xsl:choose
  | xsl:if
  | xsl:text
  | xsl:copy
  | xsl:variable
  | xsl:message
  | xsl:fallback
  | xsl:document
"&gt;

&lt;!ENTITY % instructions "
  %char-instructions;
  | xsl:processing-instruction
  | xsl:comment
  | xsl:element
  | xsl:attribute
"&gt;

&lt;!ENTITY % char-template "
 (#PCDATA
  %char-instructions;)*
"&gt;

&lt;!ENTITY % template "
 (#PCDATA
  %instructions;
  %result-elements;)*
"&gt;

&lt;!-- Used for the type of an attribute value that is a URI reference.--&gt;
&lt;!ENTITY % URI "CDATA"&gt;

&lt;!-- Used for the type of an attribute value that is list of URI
references. --&gt;
&lt;!ENTITY % URIs "CDATA"&gt;

&lt;!-- Used for the type of an attribute value that is a pattern.--&gt;
&lt;!ENTITY % pattern "CDATA"&gt;

&lt;!-- Used for the type of an attribute value that is an
     attribute value template.--&gt;
&lt;!ENTITY % avt "CDATA"&gt;

&lt;!-- Used for the type of an attribute value that is a QName; the prefix
     gets expanded by the XSLT processor. --&gt;
&lt;!ENTITY % qname "NMTOKEN"&gt;

&lt;!-- Like qname but a whitespace-separated list of QNames. --&gt;
&lt;!ENTITY % qnames "NMTOKENS"&gt;

&lt;!-- Used for the type of an attribute value that is an NCName. --&gt;
&lt;!ENTITY % ncname "NMTOKEN"&gt;

&lt;!-- Used for the type of an attribute value that is an expression.--&gt;
&lt;!ENTITY % expr "CDATA"&gt;

&lt;!-- Used for the type of an attribute value that consists
     of a single character.--&gt;
&lt;!ENTITY % char "CDATA"&gt;

&lt;!-- Used for the type of an attribute value that is a priority. --&gt;
&lt;!ENTITY % priority "NMTOKEN"&gt;

&lt;!ENTITY % space-att "xml:space (default|preserve) #IMPLIED"&gt;

&lt;!-- This may be overridden to customize the set of elements allowed
at the top-level. --&gt;

&lt;!ENTITY % non-xsl-top-level ""&gt;

&lt;!ENTITY % top-level "
 (xsl:import*,
  (xsl:include
  | xsl:strip-space
  | xsl:preserve-space
  | xsl:output
  | xsl:key
  | xsl:decimal-format
  | xsl:attribute-set
  | xsl:variable
  | xsl:param
  | xsl:template
  | xsl:namespace-alias
  | xsl:script
  %non-xsl-top-level;)*)
"&gt;

&lt;!ENTITY % top-level-atts '
  extension-element-prefixes CDATA #IMPLIED
  exclude-result-prefixes CDATA #IMPLIED
  id ID #IMPLIED
  version NMTOKEN #REQUIRED
  xmlns:xsl CDATA #FIXED "http://www.w3.org/1999/XSL/Transform"
  %space-att;
'&gt;

&lt;!-- This entity is defined for use in the ATTLIST declaration
for result elements. --&gt;

&lt;!ENTITY % result-element-atts '
  xsl:extension-element-prefixes CDATA #IMPLIED
  xsl:exclude-result-prefixes CDATA #IMPLIED
  xsl:use-attribute-sets %qnames; #IMPLIED
  xsl:version NMTOKEN #IMPLIED
'&gt;

&lt;!ENTITY % output-atts '
  method %avt; #IMPLIED
  version %avt; #IMPLIED
  encoding %avt; #IMPLIED
  omit-xml-declaration %avt; #IMPLIED
  standalone %avt; #IMPLIED
  doctype-public %avt; #IMPLIED
  doctype-system %avt; #IMPLIED
  cdata-section-elements %avt; #IMPLIED
  indent %avt; #IMPLIED
  media-type %avt; #IMPLIED
'&gt;

&lt;!ELEMENT xsl:stylesheet %top-level;&gt;
&lt;!ATTLIST xsl:stylesheet %top-level-atts;&gt;

&lt;!ELEMENT xsl:transform %top-level;&gt;
&lt;!ATTLIST xsl:transform %top-level-atts;&gt;

&lt;!ELEMENT xsl:import EMPTY&gt;
&lt;!ATTLIST xsl:import href %URI; #REQUIRED&gt;

&lt;!ELEMENT xsl:include EMPTY&gt;
&lt;!ATTLIST xsl:include href %URI; #REQUIRED&gt;

&lt;!ELEMENT xsl:strip-space EMPTY&gt;
&lt;!ATTLIST xsl:strip-space elements CDATA #REQUIRED&gt;

&lt;!ELEMENT xsl:preserve-space EMPTY&gt;
&lt;!ATTLIST xsl:preserve-space elements CDATA #REQUIRED&gt;

&lt;!ELEMENT xsl:output EMPTY&gt;
&lt;!ATTLIST xsl:output %output-atts;&gt;

&lt;!ELEMENT xsl:key EMPTY&gt;
&lt;!ATTLIST xsl:key
  name %qname; #REQUIRED
  match %pattern; #REQUIRED
  use %expr; #REQUIRED
&gt;

&lt;!ELEMENT xsl:decimal-format EMPTY&gt;
&lt;!ATTLIST xsl:decimal-format
  name %qname; #IMPLIED
  decimal-separator %char; "."
  grouping-separator %char; ","
  infinity CDATA "Infinity"
  minus-sign %char; "-"
  NaN CDATA "NaN"
  percent %char; "%"
  per-mille %char; "&amp;#x2030;"
  zero-digit %char; "0"
  digit %char; "#"
  pattern-separator %char; ";"
&gt;

&lt;!ELEMENT xsl:namespace-alias EMPTY&gt;
&lt;!ATTLIST xsl:namespace-alias
  stylesheet-prefix CDATA #REQUIRED
  result-prefix CDATA #REQUIRED
&gt;

&lt;!ELEMENT xsl:template
 (#PCDATA
  %instructions;
  %result-elements;
  | xsl:param)*
&gt;

&lt;!ATTLIST xsl:template
  match %pattern; #IMPLIED
  name %qname; #IMPLIED
  priority %priority; #IMPLIED
  mode %qname; #IMPLIED
  %space-att;
&gt;

&lt;!ELEMENT xsl:value-of EMPTY&gt;
&lt;!ATTLIST xsl:value-of
  select %expr; #REQUIRED
  disable-output-escaping (yes|no) "no"
&gt;

&lt;!ELEMENT xsl:copy-of EMPTY&gt;
&lt;!ATTLIST xsl:copy-of select %expr; #REQUIRED&gt;

&lt;!ELEMENT xsl:number EMPTY&gt;
&lt;!ATTLIST xsl:number
   level (single|multiple|any) "single"
   count %pattern; #IMPLIED
   from %pattern; #IMPLIED
   value %expr; #IMPLIED
   format %avt; '1'
   lang %avt; #IMPLIED
   letter-value %avt; #IMPLIED
   grouping-separator %avt; #IMPLIED
   grouping-size %avt; #IMPLIED
&gt;

&lt;!ELEMENT xsl:apply-templates (xsl:sort|xsl:with-param)*&gt;
&lt;!ATTLIST xsl:apply-templates
  select %expr; "node()"
  mode %qname; #IMPLIED
&gt;

&lt;!ELEMENT xsl:apply-imports EMPTY&gt;

&lt;!-- xsl:sort cannot occur after any other elements or
any non-whitespace character --&gt;

&lt;!ELEMENT xsl:for-each
 (#PCDATA
  %instructions;
  %result-elements;
  | xsl:sort)*
&gt;

&lt;!ATTLIST xsl:for-each
  select %expr; #REQUIRED
  %space-att;
&gt;

&lt;!ELEMENT xsl:sort EMPTY&gt;
&lt;!ATTLIST xsl:sort
  select %expr; "."
  lang %avt; #IMPLIED
  data-type %avt; "text"
  order %avt; "ascending"
  case-order %avt; #IMPLIED
&gt;

&lt;!ELEMENT xsl:if %template;&gt;
&lt;!ATTLIST xsl:if
  test %expr; #REQUIRED
  %space-att;
&gt;

&lt;!ELEMENT xsl:choose (xsl:when+, xsl:otherwise?)&gt;
&lt;!ATTLIST xsl:choose %space-att;&gt;

&lt;!ELEMENT xsl:when %template;&gt;
&lt;!ATTLIST xsl:when
  test %expr; #REQUIRED
  %space-att;
&gt;

&lt;!ELEMENT xsl:otherwise %template;&gt;
&lt;!ATTLIST xsl:otherwise %space-att;&gt;

&lt;!ELEMENT xsl:attribute-set (xsl:attribute)*&gt;
&lt;!ATTLIST xsl:attribute-set
  name %qname; #REQUIRED
  use-attribute-sets %qnames; #IMPLIED
&gt;

&lt;!ELEMENT xsl:call-template (xsl:with-param)*&gt;
&lt;!ATTLIST xsl:call-template
  name %qname; #REQUIRED
&gt;

&lt;!ELEMENT xsl:with-param %template;&gt;
&lt;!ATTLIST xsl:with-param
  name %qname; #REQUIRED
  select %expr; #IMPLIED
&gt;

&lt;!ELEMENT xsl:variable %template;&gt;
&lt;!ATTLIST xsl:variable 
  name %qname; #REQUIRED
  select %expr; #IMPLIED
&gt;

&lt;!ELEMENT xsl:param %template;&gt;
&lt;!ATTLIST xsl:param 
  name %qname; #REQUIRED
  select %expr; #IMPLIED
&gt;

&lt;!ELEMENT xsl:text (#PCDATA)&gt;
&lt;!ATTLIST xsl:text
  disable-output-escaping (yes|no) "no"
&gt;

&lt;!ELEMENT xsl:processing-instruction %char-template;&gt;
&lt;!ATTLIST xsl:processing-instruction 
  name %avt; #REQUIRED
  %space-att;
&gt;

&lt;!ELEMENT xsl:element %template;&gt;
&lt;!ATTLIST xsl:element 
  name %avt; #REQUIRED
  namespace %avt; #IMPLIED
  use-attribute-sets %qnames; #IMPLIED
  %space-att;
&gt;

&lt;!ELEMENT xsl:attribute %char-template;&gt;
&lt;!ATTLIST xsl:attribute 
  name %avt; #REQUIRED
  namespace %avt; #IMPLIED
  %space-att;
&gt;

&lt;!ELEMENT xsl:comment %char-template;&gt;
&lt;!ATTLIST xsl:comment %space-att;&gt;

&lt;!ELEMENT xsl:copy %template;&gt;
&lt;!ATTLIST xsl:copy
  %space-att;
  use-attribute-sets %qnames; #IMPLIED
&gt;

&lt;!ELEMENT xsl:message %template;&gt;
&lt;!ATTLIST xsl:message
  %space-att;
  terminate (yes|no) "no"
&gt;

&lt;!ELEMENT xsl:fallback %template;&gt;
&lt;!ATTLIST xsl:fallback %space-att;&gt;

&lt;!ELEMENT xsl:document %template;&gt;
&lt;!ATTLIST xsl:document
  href %avt; #REQUIRED
  %output-atts;
&gt;

&lt;!ELEMENT xsl:script (#PCDATA)&gt;
&lt;!ATTLIST xsl:script
  implements-prefix %ncname; #REQUIRED
  language %qname; #REQUIRED
  src %URI; #IMPLIED
  archive %URIs; #IMPLIED
&gt;</pre></div>


</div>

<div class="div1">

<h2><a name="N13295"></a>E Examples (Non-Normative)</h2>

<div class="div2">

<h3><a name="N13300"></a>E.1 Document Example</h3>

<p>This example is a stylesheet for transforming documents that
conform to a simple DTD into XHTML <a href="#XHTML">[XHTML]</a>.  The DTD
is:</p>

<div class="exampleInner"><pre>&lt;!ELEMENT doc (title, chapter*)&gt;
&lt;!ELEMENT chapter (title, (para|note)*, section*)&gt;
&lt;!ELEMENT section (title, (para|note)*)&gt;
&lt;!ELEMENT title (#PCDATA|emph)*&gt;
&lt;!ELEMENT para (#PCDATA|emph)*&gt;
&lt;!ELEMENT note (#PCDATA|emph)*&gt;
&lt;!ELEMENT emph (#PCDATA|emph)*&gt;</pre></div>

<p>The stylesheet is:</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/TR/xhtml1"&gt;

&lt;xsl:strip-space elements="doc chapter section"/&gt;
&lt;xsl:output
   method="xml"
   indent="yes"
   encoding="iso-8859-1"
/&gt;

&lt;xsl:template match="doc"&gt;
 &lt;html&gt;
   &lt;head&gt;
     &lt;title&gt;
       &lt;xsl:value-of select="title"/&gt;
     &lt;/title&gt;
   &lt;/head&gt;
   &lt;body&gt;
     &lt;xsl:apply-templates/&gt;
   &lt;/body&gt;
 &lt;/html&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="doc/title"&gt;
  &lt;h1&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/h1&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="chapter/title"&gt;
  &lt;h2&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/h2&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="section/title"&gt;
  &lt;h3&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/h3&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="para"&gt;
  &lt;p&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/p&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="note"&gt;
  &lt;p class="note"&gt;
    &lt;b&gt;NOTE: &lt;/b&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/p&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="emph"&gt;
  &lt;em&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/em&gt;
&lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></div>

<p>With the following input document</p>

<div class="exampleInner"><pre>&lt;!DOCTYPE doc SYSTEM "doc.dtd"&gt;
&lt;doc&gt;
&lt;title&gt;Document Title&lt;/title&gt;
&lt;chapter&gt;
&lt;title&gt;Chapter Title&lt;/title&gt;
&lt;section&gt;
&lt;title&gt;Section Title&lt;/title&gt;
&lt;para&gt;This is a test.&lt;/para&gt;
&lt;note&gt;This is a note.&lt;/note&gt;
&lt;/section&gt;
&lt;section&gt;
&lt;title&gt;Another Section Title&lt;/title&gt;
&lt;para&gt;This is &lt;emph&gt;another&lt;/emph&gt; test.&lt;/para&gt;
&lt;note&gt;This is another note.&lt;/note&gt;
&lt;/section&gt;
&lt;/chapter&gt;
&lt;/doc&gt;</pre></div>

<p>it would produce the following result</p>

<div class="exampleInner"><pre>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
&lt;html xmlns="http://www.w3.org/TR/xhtml1"&gt;
&lt;head&gt;
&lt;title&gt;Document Title&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Document Title&lt;/h1&gt;
&lt;h2&gt;Chapter Title&lt;/h2&gt;
&lt;h3&gt;Section Title&lt;/h3&gt;
&lt;p&gt;This is a test.&lt;/p&gt;
&lt;p class="note"&gt;
&lt;b&gt;NOTE: &lt;/b&gt;This is a note.&lt;/p&gt;
&lt;h3&gt;Another Section Title&lt;/h3&gt;
&lt;p&gt;This is &lt;em&gt;another&lt;/em&gt; test.&lt;/p&gt;
&lt;p class="note"&gt;
&lt;b&gt;NOTE: &lt;/b&gt;This is another note.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div>

</div>

<div class="div2">

<h3><a name="data-example"></a>E.2 Data Example</h3>

<p>This is an example of transforming some data represented in XML
using three different XSLT stylesheets to produce three different
representations of the data, HTML, SVG and VRML.</p>

<p>The input data is:</p>

<div class="exampleInner"><pre>&lt;sales&gt;

        &lt;division id="North"&gt;
                &lt;revenue&gt;10&lt;/revenue&gt;
                &lt;growth&gt;9&lt;/growth&gt;
                &lt;bonus&gt;7&lt;/bonus&gt;
        &lt;/division&gt;

        &lt;division id="South"&gt;
                &lt;revenue&gt;4&lt;/revenue&gt;
                &lt;growth&gt;3&lt;/growth&gt;
                &lt;bonus&gt;4&lt;/bonus&gt;
        &lt;/division&gt;

        &lt;division id="West"&gt;
                &lt;revenue&gt;6&lt;/revenue&gt;
                &lt;growth&gt;-1.5&lt;/growth&gt;
                &lt;bonus&gt;2&lt;/bonus&gt;
        &lt;/division&gt;

&lt;/sales&gt;</pre></div>

<p>The following stylesheet, which uses the simplified syntax
described in <a href="#result-element-stylesheet"><b>2.3 Literal Result Element as Stylesheet</b></a>, transforms
the data into HTML:</p>

<div class="exampleInner"><pre>&lt;html xsl:version="1.1"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      lang="en"&gt;
    &lt;head&gt;
	&lt;title&gt;Sales Results By Division&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
	&lt;table border="1"&gt;
	    &lt;tr&gt;
		&lt;th&gt;Division&lt;/th&gt;
		&lt;th&gt;Revenue&lt;/th&gt;
		&lt;th&gt;Growth&lt;/th&gt;
		&lt;th&gt;Bonus&lt;/th&gt;
	    &lt;/tr&gt;
	    &lt;xsl:for-each select="sales/division"&gt;
		&lt;!-- order the result by revenue --&gt;
		&lt;xsl:sort select="revenue"
			  data-type="number"
			  order="descending"/&gt;
		&lt;tr&gt;
		    &lt;td&gt;
			&lt;em&gt;&lt;xsl:value-of select="@id"/&gt;&lt;/em&gt;
		    &lt;/td&gt;
		    &lt;td&gt;
			&lt;xsl:value-of select="revenue"/&gt;
		    &lt;/td&gt;
		    &lt;td&gt;
			&lt;!-- highlight negative growth in red --&gt;
			&lt;xsl:if test="growth &amp;lt; 0"&gt;
			     &lt;xsl:attribute name="style"&gt;
				 &lt;xsl:text&gt;color:red&lt;/xsl:text&gt;
			     &lt;/xsl:attribute&gt;
			&lt;/xsl:if&gt;
			&lt;xsl:value-of select="growth"/&gt;
		    &lt;/td&gt;
		    &lt;td&gt;
			&lt;xsl:value-of select="bonus"/&gt;
		    &lt;/td&gt;
		&lt;/tr&gt;
	    &lt;/xsl:for-each&gt;
	&lt;/table&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></div>

<p>The HTML output is:</p>

<div class="exampleInner"><pre>&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Sales Results By Division&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table border="1"&gt;
&lt;tr&gt;
&lt;th&gt;Division&lt;/th&gt;&lt;th&gt;Revenue&lt;/th&gt;&lt;th&gt;Growth&lt;/th&gt;&lt;th&gt;Bonus&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;North&lt;/em&gt;&lt;/td&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;West&lt;/em&gt;&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td style="color:red"&gt;-1.5&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;South&lt;/em&gt;&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div>

<p>The following stylesheet transforms the data into SVG:</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd"&gt;

&lt;xsl:output method="xml" indent="yes" media-type="image/svg"/&gt;

&lt;xsl:template match="/"&gt;

&lt;svg width = "3in" height="3in"&gt;
    &lt;g style = "stroke: #000000"&gt; 
        &lt;!-- draw the axes --&gt;
        &lt;line x1="0" x2="150" y1="150" y2="150"/&gt;
        &lt;line x1="0" x2="0" y1="0" y2="150"/&gt;
        &lt;text x="0" y="10"&gt;Revenue&lt;/text&gt;
        &lt;text x="150" y="165"&gt;Division&lt;/text&gt;
        &lt;xsl:for-each select="sales/division"&gt;
	    &lt;!-- define some useful variables --&gt;

	    &lt;!-- the bar's x position --&gt;
	    &lt;xsl:variable name="pos"
	                  select="(position()*40)-30"/&gt;

	    &lt;!-- the bar's height --&gt;
	    &lt;xsl:variable name="height"
	                  select="revenue*10"/&gt;

	    &lt;!-- the rectangle --&gt;
	    &lt;rect x="{$pos}" y="{150-$height}"
                  width="20" height="{$height}"/&gt;

	    &lt;!-- the text label --&gt;
	    &lt;text x="{$pos}" y="165"&gt;
	        &lt;xsl:value-of select="@id"/&gt;
	    &lt;/text&gt; 

	    &lt;!-- the bar value --&gt;
	    &lt;text x="{$pos}" y="{145-$height}"&gt;
	        &lt;xsl:value-of select="revenue"/&gt;
	    &lt;/text&gt;
        &lt;/xsl:for-each&gt;
    &lt;/g&gt;
&lt;/svg&gt;

&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;</pre></div>

<p>The SVG output is:</p>

<div class="exampleInner"><pre>&lt;svg width="3in" height="3in"
     xmlns="http://www.w3.org/Graphics/SVG/svg-19990412.dtd"&gt;
    &lt;g style="stroke: #000000"&gt;
	&lt;line x1="0" x2="150" y1="150" y2="150"/&gt;
	&lt;line x1="0" x2="0" y1="0" y2="150"/&gt;
	&lt;text x="0" y="10"&gt;Revenue&lt;/text&gt;
	&lt;text x="150" y="165"&gt;Division&lt;/text&gt;
	&lt;rect x="10" y="50" width="20" height="100"/&gt;
	&lt;text x="10" y="165"&gt;North&lt;/text&gt;
	&lt;text x="10" y="45"&gt;10&lt;/text&gt;
	&lt;rect x="50" y="110" width="20" height="40"/&gt;
	&lt;text x="50" y="165"&gt;South&lt;/text&gt;
	&lt;text x="50" y="105"&gt;4&lt;/text&gt;
	&lt;rect x="90" y="90" width="20" height="60"/&gt;
	&lt;text x="90" y="165"&gt;West&lt;/text&gt;
	&lt;text x="90" y="85"&gt;6&lt;/text&gt;
    &lt;/g&gt;
&lt;/svg&gt;</pre></div>

<p>The following stylesheet transforms the data into VRML:</p>

<div class="exampleInner"><pre>&lt;xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

&lt;!-- generate text output as mime type model/vrml, using default charset --&gt;
&lt;xsl:output method="text" encoding="UTF-8" media-type="model/vrml"/&gt;  

        &lt;xsl:template match="/"&gt;#VRML V2.0 utf8 
 
# externproto definition of a single bar element 
EXTERNPROTO bar [ 
  field SFInt32 x  
  field SFInt32 y  
  field SFInt32 z  
  field SFString name  
  ] 
  "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl" 
 
# inline containing the graph axes 
Inline {  
        url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl" 
        } 
        
                &lt;xsl:for-each select="sales/division"&gt;
bar {
        x &lt;xsl:value-of select="revenue"/&gt;
        y &lt;xsl:value-of select="growth"/&gt;
        z &lt;xsl:value-of select="bonus"/&gt;
        name "&lt;xsl:value-of select="@id"/&gt;" 
        }
                &lt;/xsl:for-each&gt;
        
        &lt;/xsl:template&gt; 
 
&lt;/xsl:stylesheet&gt;</pre></div>

<p>The VRML output is:</p>

<div class="exampleInner"><pre>#VRML V2.0 utf8 
 
# externproto definition of a single bar element 
EXTERNPROTO bar [ 
  field SFInt32 x  
  field SFInt32 y  
  field SFInt32 z  
  field SFString name  
  ] 
  "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl" 
 
# inline containing the graph axes 
Inline {  
        url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl" 
        } 
        
                
bar {
        x 10
        y 9
        z 7
        name "North" 
        }
                
bar {
        x 4
        y 3
        z 4
        name "South" 
        }
                
bar {
        x 6
        y -1.5
        z 2
        name "West" 
        }</pre></div>

</div>

</div>

<div class="div1">

<h2><a name="N13416"></a>F Acknowledgements (Non-Normative)</h2>
<p>The following have contributed to authoring this draft:</p>
<blockquote><p>
Scott Boag, Lotus
<br>Michael Kay, ICL
<br>Daniel Lipkin, Saba
<br>Jonathan Marsh, Microsoft
<br>Steve Muench, Oracle
<br>Henry Thompson, University of Edinburgh
<br>Norman Walsh, Arbortext
<br>Steve Zilles, Adobe
</p></blockquote>

<p>This specification was developed and approved for publication by the
W3C XSL Working Group (WG). WG approval of this specification does not
necessarily imply that all WG members voted for its approval. The
current members of the XSL WG are:</p>

<ul>
<li>
Sharon Adler
, IBM
 (<i>Co-Chair</i>) 
</li>
<li>
Anders Berglund
, IBM
</li>
<li>
Perin Blanchard
, Novell
</li>
<li>
Scott Boag
, Lotus
</li>
<li>
Jeff Caruso
, Pageflex
</li>
<li>
James Clark
</li>
<li>
Max Froumentin
, W3C
</li>
<li>
Andrew Greene
, Pageflex
</li>
<li>
Paul Grosso
, ArborText
</li>
<li>
Eduardo Gutentag
, Sun
</li>
<li>
Juliane Harbarth
, Software AG
</li>
<li>
Michael Kay
, ICL
</li>
<li>
Bill Lindsey
, B-Bop
</li>
<li>
Bob Lojek
, Ask Jeeves
</li>
<li>
Chris Maden
, Lexica
</li>
<li>
Jonathan Marsh
, Microsoft
</li>
<li>
Steve Muench
, Oracle
</li>
<li>
Drew Munro
, XMLSolutions
</li>
<li>
Scott Parnell
, Xerox
</li>
<li>
Eduardo Pelegri-Llopart
, Sun
</li>
<li>
Ramesh Pendakur
, Intel
</li>
<li>
Vincent Quint
, W3C
</li>
<li>
Zarella Rendon
, DataChannel
</li>
<li>
Jeremy Richman
, Interleaf
</li>
<li>
Jonathan Robie
, Software AG
</li>
<li>
Mark Scardina
, Oracle
</li>
<li>
Henry Thompson
, University of Edinburgh
</li>
<li>
Amr Yassin
, Philips Electronics
</li>
<li>
Ray Waldin
, Lexica
</li>
<li>
Norman Walsh
, Sun
</li>
<li>
Linda Welsh
, Intel
</li>
<li>
Shon Vella
, Novell
</li>
<li>
Sanjiva Weerawarana
, IBM
</li>
<li>
Steve Zilles
, Adobe
 (<i>Co-Chair</i>) 
</li>
</ul>

<p>The members of the XSL WG at the time of the publication
of XSLT 1.0 were:</p>

<ul>
<li>
Sharon Adler
, IBM
 (<i>Co-Chair</i>) 
</li>
<li>
Anders Berglund
, IBM
</li>
<li>
Perin Blanchard
, Novell
</li>
<li>
Scott Boag
, Lotus 
</li>
<li>
Larry Cable
, Sun
</li>
<li>
Jeff Caruso
, Bitstream
</li>
<li>
James Clark
</li>
<li>
Peter Danielsen
, Bell Labs
</li>
<li>
Don Day
, IBM
</li>
<li>
Stephen Deach
, Adobe
</li>
<li>
Dwayne Dicks
, SoftQuad
</li>
<li>
Andrew Greene
, Bitstream
</li>
<li>
Paul Grosso
, Arbortext
</li>
<li>
Eduardo Gutentag
, Sun
</li>
<li>
Juliane Harbarth
, Software AG
</li>
<li>
Mickey Kimchi
, Enigma
</li>
<li>
Chris Lilley
, W3C
</li>
<li>
Chris Maden
, Exemplary Technologies
</li>
<li>
Jonathan Marsh
, Microsoft
</li>
<li>
Alex Milowski 
, Lexica
</li>
<li>
Boris Moore
, RivCom
</li>
<li>
Steve Muench
, Oracle
</li>
<li>
Scott Parnell
, Xerox
</li>
<li>
Vincent Quint
, W3C
</li>
<li>
Dan Rapp
, Novell
</li>
<li>
Gregg Reynolds
, Datalogics
</li>
<li>
Jonathan Robie
, Software AG
</li>
<li>
Mark Scardina
, Oracle
</li>
<li>
Henry Thompson
, University of Edinburgh
</li>
<li>
Philip Wadler
, Bell Labs
</li>
<li>
Norman Walsh
, Arbortext
</li>
<li>
Sanjiva Weerawarana
, IBM
</li>
<li>
Steve Zilles
, Adobe
 (<i>Co-Chair</i>) 
</li>
</ul>

</div>

<div class="div1">

<h2><a name="N14079"></a>G Changes from XSLT 1.0 (Non-Normative)</h2>

<p>The following are the changes since XSLT 1.0:</p>

<ul>

<li><p>The result tree fragment data-type has been
eliminated. Variable-binding elements with content now construct
node-sets (see <a href="#variable-values"><b>11.2 Values of Variables and Parameters</b></a>).</p></li>

<li><p>Instead of the allowing the output method complete freedom to
add namespace nodes, a process of namespace fixup is applied to the
result tree before it is output; this same namespace fixup process is
also applied to documents constructed variable-binding elements with
content (see <a href="#namespace-fixup"><b>3.5 Namespace Fixup</b></a>).</p></li>

<li><p>Support for XML Base has been added (see <a href="#base-uri"><b>3.2 Base URI</b></a>).</p></li>

<li><p>Multiple output documents can be created using the
<code>xsl:document</code> element (see <a href="#multiple-output"><b>16.5 Multiple Output Documents</b></a>).  For consistency with
<code>xsl:document</code>, the attributes on <code>xsl:output</code>
are now interpreted as attribute value templates.</p></li>

<li><p>An <code>xsl:apply-imports</code> element is allowed to have
parameters (see <a href="#apply-imports"><b>5.6 Overriding Template Rules</b></a> and <a href="#with-param"><b>11.6 Passing Parameters to Templates</b></a>).</p></li>

<li><p>Extension functions can be defined using the
<code>xsl:script</code> function (see <a href="#define-extension-functions"><b>14.4 Defining Extension Functions</b></a>).</p></li>

<li><p>Extension functions are allowed to return
"external" objects, which do not have any of the builtin
XPath types.</p></li>

</ul>

<p>Reported <a href="http://www.w3.org/1999/11/REC-xslt-19991116-errata/">errors</a>
have also been fixed.</p>

</div>

</div>
</body></html>