index.html
94.5 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
<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en-US"><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>Requirements and Use Cases for XSLT 2.1</title><style type="text/css">
code { font-family: monospace; }
div.constraint,
div.note,
div.notice { margin-left: 2em; }
div.issue { padding-left: 5px; padding-right: 5px; margin-top: 5px;
padding-top: 1px; padding-bottom: 1px;
background-color: #f0f0d0 }
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><a name="title" id="title"></a>Requirements and Use Cases for XSLT 2.1</h1>
<h2><a name="w3c-doctype" id="w3c-doctype"></a>W3C Working Draft 10 June 2010</h2><dl><dt>This version:</dt><dd>
<a href="http://www.w3.org/TR/2010/WD-xslt-21-requirements-20100610/">http://www.w3.org/TR/2010/WD-xslt-21-requirements-20100610/</a>
</dd><dt>Latest version:</dt><dd>
<a href="http://www.w3.org/TR/xslt-21-requirements/">http://www.w3.org/TR/xslt-21-requirements/</a>
</dd><dt>Editor:</dt><dd>Petr Cimprich, UNITY Mobile <a href="http://www.unitymobile.com/"><http://www.unitymobile.com/></a></dd></dl><p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice-20000612#Copyright">Copyright</a> © 2010 <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.ercim.eu/"><abbr lang="fr" title="Institut National de Recherche en Informatique et Automatique">ERCIM</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" id="abstract"></a>Abstract</h2><p>
This document is a characterization of requirements and use cases for <a href="#xslt21">[XSL Transformations (XSLT) Version 2.1]</a>. The Requirements lists enhancements requested over time that may be addressed in XSLT 2.1. </p></div><div>
<h2><a name="status" id="status"></a>Status of this Document</h2><p><em>This section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list of
current W3C publications and the latest revision of this technical report
can be found in the <a href="http://www.w3.org/TR/">W3C technical reports index.</a></em></p><p>This is the <a href="http://www.w3.org/2005/10/Process-20051014/tr.html#first-wd">First
Public Working Draft</a> of the Requirements and Use Cases for XSLT 2.1,
produced by the <a href="http://www.w3.org/Style/XSL/">W3C XSL Working Group</a>, which is part of
the <a href="http://www.w3.org/XML/Activity">XML Activity</a>.
The Working Group expects to eventually publish this document as a Working
Group Note.
</p><p>Please report errors in this document using W3C's <a href="http://www.w3.org/Bugs/Public/">public Bugzilla system</a> (instructions can be found at <a href="http://www.w3.org/XML/2005/04/qt-bugzilla"></a>). If access to that system is not feasible, you may send your comments to the W3C XSLT/XPath/XQuery public comments mailing list, <a href="mailto:public-qt-comments@w3.org">public-qt-comments@w3.org</a>. It will be very helpful if you include the string "[XSLT21Req]" in the subject line of your report, whether made in Bugzilla or in email. Please use multiple Bugzilla entries (or, if necessary, multiple email messages) if you have more than one comment to make. Archives of the comments and responses are available at <a href="http://lists.w3.org/Archives/Public/public-qt-comments/"></a>.</p><p> Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress. </p><p>This document was produced by a group operating under the <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent Policy</a>. The group does not expect this document to become a W3C Recommendation. This document is informative only. W3C maintains a <a href="http://www.w3.org/2004/01/pp-impl/19552/status#disclosures">public list of any patent disclosures</a> made in connection with the deliverables of the XSL Working Group; those pages also include instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the W3C Patent Policy</a>.</p></div><div class="toc">
<h2><a name="contents" id="contents"></a>Table of Contents</h2><p class="toc">1 <a href="#introduction">Introduction</a><br>2 <a href="#requirements">Requirements</a><br> 2.1 <a href="#d0e112">Enabling Streamable Processing</a><br> 2.2 <a href="#d0e134">Modes and Schema-awareness</a><br> 2.3 <a href="#d0e141">Composite Keys</a><br> 2.4 <a href="#d0e148">The xsl:analyze-string Instruction Applied to an Empty Sequence</a><br> 2.5 <a href="#d0e172">Context Item for a Named Template</a><br> 2.6 <a href="#d0e179">Traditional Hebrew Numbering</a><br> 2.7 <a href="#d0e186">Separate Compilation of Stylesheet Modules</a><br> 2.8 <a href="#d0e215">The start-at Attribute of xsl:number</a><br> 2.9 <a href="#d0e231">Allowing xsl:variable before xsl:param</a><br> 2.10 <a href="#d0e253">Combining group-starting-with and group-ending-with</a><br> 2.11 <a href="#d0e274">Improvements to Schema for Stylesheets</a><br> 2.12 <a href="#d0e281">Setting Initial Template Parameters</a><br> 2.13 <a href="#d0e288">Invoking XQuery from XSLT</a><br> 2.14 <a href="#d0e306">Enhancement to Sorting and Grouping</a><br> 2.15 <a href="#d0e327">Enhancement to Conditional Modes</a><br> 2.16 <a href="#d0e340">Default Initial Template</a><br>3 <a href="#scenarios">Real-World Scenarios</a><br> 3.1 <a href="#scenario-mpeg21">Transforming MPEG-21 BSDL</a><br> 3.2 <a href="#scenario-soap-validation">Validation of SOAP Digital Signatures</a><br> 3.3 <a href="#scenario-rdf-dump">Transformation of the RDF Dump of the Open Directory</a><br> 3.4 <a href="#scenario-mobile">Transformations on a Cell Phone</a><br> 3.5 <a href="#scenario-multiple-fo">XSL FO Multiple Extraction/Processing</a><br> 3.6 <a href="#scenarion-eft-edi">EFT/EDI Transformation</a><br>4 <a href="#tasks">Tasks</a><br> 4.1 <a href="#d1-splitting-flat">Splitting Flat Data</a><br> 4.2 <a href="#d1-splitting-nested">Splitting Nested Data</a><br> 4.3 <a href="#d1-joining">Joining</a><br> 4.4 <a href="#d1-concatenation">Concatenation</a><br> 4.5 <a href="#d1-adding-children">Adding Children</a><br> 4.6 <a href="#d1-renaming-nested">Renaming and Counting Nested Elements</a><br> 4.7 <a href="#d1-renaming-nested-more-counting">Renaming and Counting Nested Elements and Counting Other Elements</a><br> 4.8 <a href="#d1-filtering-att">Filtering According to Attribute</a><br> 4.9 <a href="#d1-filtering-child">Filtering According to Child</a><br> 4.10 <a href="#d1-histogram">Histogram</a><br> 4.11 <a href="#d3-hierarchical-flat">Hierarchical to Flat</a><br> 4.12 <a href="#d3-flat-hierarchical">Flat to Hierarchical</a><br> 4.13 <a href="#d4-csv">CSV Result</a><br> 4.14 <a href="#d1-local-sorting">Local Sorting</a><br> 4.15 <a href="#d2-references">Resolving References</a><br> 4.16 <a href="#d1-multiple-extraction">Multiple Extraction/Processing</a><br> 4.17 <a href="#d1-grouping">Grouping</a><br> 4.18 <a href="#d1-iterate">Iterations</a><br> 4.19 <a href="#d1-windowing">Making Explicit Sections</a><br> 4.20 <a href="#d1-merging">Merging Sorted Sequences</a><br></p>
<h3><a name="appendices" id="appendices"></a>Appendices</h3><p class="toc">A <a href="#sample-data">Sample Data</a><br> A.1 <a href="#data-1a">Flat Collection</a><br> A.2 <a href="#data-1b">Nested Collection</a><br> A.3 <a href="#data-2">Product Catalog</a><br> A.4 <a href="#data-3">Hierarchical to Flat</a><br> A.5 <a href="#data-4">Rows and Columns</a><br> A.6 <a href="#data-transactions">Transactions and Balance</a><br> A.7 <a href="#data-windowing">Explicit Sections</a><br>B <a href="#references">References</a><br></p></div><hr><div class="body"><div class="div1">
<h2><a name="introduction" id="introduction"></a>1 Introduction</h2><p>This document is a characterization of requirements and use cases for <a href="#xslt21">[XSL Transformations (XSLT) Version 2.1]</a>.
The section <a href="#requirements"><b>2 Requirements</b></a> lists enhancements requested over time that
may be addressed in XSLT 2.1. The relative priorities to be assigned to these different
enhancements are still being decided.</p><p>Use cases are presented in two different styles:
section <a href="#scenarios"><b>3 Real-World Scenarios</b></a> contains real-world scenarios illustrating some
shortcomings of <a href="#xslt20">[XSL Transformations (XSLT) Version 2.0]</a>, while section <a href="#tasks"><b>4 Tasks</b></a> contains descriptions
of specific transformation tasks that make it possible to analyze the implementation in XSLT 2.0
and the proposed implementation in XSLT 2.1.</p></div><div class="div1">
<h2><a name="requirements" id="requirements"></a>2 Requirements</h2><div class="div2">
<h3><a name="d0e112" id="d0e112"></a>2.1 Enabling Streamable Processing</h3><p>XSLT should provide some facilities to enable transformation of a source document on the fly
without constructing a complete tree representation of the document in memory. Difficulties with
transformations when the entire document cannot fit into memory or when results must be produced
while reading the input are the main motivation for this requirement.</p><p>The streaming facilities can impose constraints on stylesheets to ensure that streamable
processing is possible. There must be a way to determine if a construct is streamable and whether
the processor can guarantee that it will be processed using streaming.</p><p>To facilitate the analysis of streamability, new explicit constructs for some typical tasks may be added
to the language. The constructs would be useful in themselves not only in conjunction with streaming.</p><ul><li><p>Merging several sorted input sequences.</p></li><li><p>Computing multiple results during a single scan of the input data.</p></li><li><p>Adding an explicit instruction for iterative processing of a sequence.</p></li><li><p>Adding a declaration of mode so that properties like the streamability can be declared on the mode.</p></li></ul></div><div class="div2">
<h3><a name="d0e134" id="d0e134"></a>2.2 Modes and Schema-awareness</h3><p>The ability to take advantage of schema-awareness in XSLT 2.0 is
limited by the fact that most of the code consists of template rules, and in a
typical template rule written with match="elementname" there is no type
information available statically about the type of the context node. Rewriting
all the template rules to use match="schema-element(elementname)" is laborious,
and only works for elements declared globally; it also makes it very difficult
to maintain parallel schema-aware and non-schema-aware versions of the
stylesheet.</p><p>This problem can be reduced by making schema-awareness a property of a mode.
Modes could be declared so that rules in this mode will only match untyped nodes,
or to treat an element name E used at the start of a match pattern as schema-element(E);
either for all elements or for the elements that corresponds to the name of a global element
declaration.</p></div><div class="div2">
<h3><a name="d0e141" id="d0e141"></a>2.3 Composite Keys</h3><p>Composite (multi-part) sort keys are allowed in XSLT 2.0, but composite access keys (xsl:key)
or grouping keys are not allowed. Users are required to construct such keys by string concatenation,
which is clumsy and error prone because the result may not be unique, and it prevents use of non-string
types as keys.</p><p>Composite access keys and composite grouping keys can be allowed.</p></div><div class="div2">
<h3><a name="d0e148" id="d0e148"></a>2.4 The <code>xsl:analyze-string</code> Instruction Applied to an Empty Sequence</h3><p>The <code>fn:analyze-string()</code> function which has been introduced in <a href="#xpath11-functions">[XPath and XQuery Functions and Operators 1.1]</a>
behaves like most string functions in that it accepts an empty sequence as input, and treats it in the same way
as a zero-length string. The <code>xsl:analyze-string</code> instruction in XSLT 2.0 does not work this way: it
reports an error if the input is an
empty sequence.</p><p>This can be changed for usability, for consistency, and to make it a little bit easier for
implementations to reuse code between <code>xsl:analyze-string</code> and <code>fn:analyze-string()</code>.</p></div><div class="div2">
<h3><a name="d0e172" id="d0e172"></a>2.5 Context Item for a Named Template</h3><p>The scope for static checking of named templates against a schema is very limited in XSLT 2.0, because
the type of the context item is not known and cannot be declared.</p><p>A mechanism is needed to declare the type and other properties of the context item at the level of the
initial stylesheet invocation. It would be useful to reuse this construct to allow declaration of the context item
supplied to a named template. </p></div><div class="div2">
<h3><a name="d0e179" id="d0e179"></a>2.6 Traditional Hebrew Numbering</h3><p>There are issues with "Traditional Hebrew" numbering. Sometimes numbers are printed with
additional marks to indicate that they are numbers, sometimes they aren't. The XSLT 2.0 specification
uses both conventions, once in the example for dates, once in the example for numbering. The types
of additional marks also change. In modern texts, numbers are sometimes marked with a geresh following
the number, and sometimes with a gershayim; In archaic texts, overdots are sometimes used to indicate that the
value is numeric and not a word. When the number is represented as words, it could be masculine or feminine, in
both ordinal and cardinal forms. There's currently no way to specify masculine or feminine for cardinal forms.
There are two conventions for how to specify a number in words: The modern convention (the equivalent of
representing 1234 as "one thousand two hundred thirty four") and the archaic convention ("four and thirty
and two hundred and one thousand").</p><p>What can help is an additional way to provide the XSLT processor with nonstandard language-specific
options.</p></div><div class="div2">
<h3><a name="d0e186" id="d0e186"></a>2.7 Separate Compilation of Stylesheet Modules</h3><p>As XSLT applications become larger, there is a requirement for separate
compilation of stylesheet modules. The design of XSLT 2.0 makes this difficult
because there are only few constraints on what an importing/including stylesheet
can do to change the behavior of an imported/included stylesheet. Some of the
changes that are needed to make separate compilation viable include:</p><ul><li><p>a change to the syntax and/or semantics of xsl:include and xsl:import to
recognize the existence of precompiled stylesheet modules,</p></li><li><p>an addition of attributes controlling visibility of the declarations of
functions, named templates, global variables and other objects such as
attribute sets in a precompiled module,</p></li><li><p>rules constraining the ability to override variables, templates and
functions,</p></li><li><p>some kind of connection between importing and modes,</p></li><li><p>making some declarations such as <code>xsl:strip-space</code> and <code>xsl:output</code> less
global.</p></li></ul><p>Some constraints will apply in stylesheet modules that are suitable for separate compilation.</p></div><div class="div2">
<h3><a name="d0e215" id="d0e215"></a>2.8 The <code>start-at</code> Attribute of <code>xsl:number</code></h3><p>A simple and useful addition to <code>xsl:number</code> would be an attribute
<code>start-at="expression"</code> to control the first number in the numbering sequence (defaulting to 1).
This will be useful for example where numbering is to run across the documents in a collection.</p></div><div class="div2">
<h3><a name="d0e231" id="d0e231"></a>2.9 Allowing <code>xsl:variable</code> before <code>xsl:param</code></h3><p>The XSLT 2.0 specification forbids intermixing of <code>xsl:variable</code> and <code>xsl:param</code> in templates.
This seems to be unnecessarily restrictive to some users. Allowing <code>xsl:variable</code> before <code>xsl:param</code>
in a template would be useful for some use cases, for example to calculate default parameter values. </p></div><div class="div2">
<h3><a name="d0e253" id="d0e253"></a>2.10 Combining <code>group-starting-with</code> and <code>group-ending-with</code></h3><p>The <code>group-starting-with</code> and <code>group-ending-with</code> attributes are not allow to coexist
on the <code>xsl:for-each-group</code> instruction in XSLT 2.0. Removing this restriction would provide a natural
solution to some grouping use cases. For example the grouping of the following sequence of elements into a true
hierarchy.</p><div class="exampleInner"><pre>
<start/>
<item/>
<item/>
<start/>
<item/>
<end/>
<item/>
<end/>
</pre></div></div><div class="div2">
<h3><a name="d0e274" id="d0e274"></a>2.11 Improvements to Schema for Stylesheets</h3><p>The patterns for NCNames and QNames should be made consistent and more precise regarding the naming
rules for the first character and later characters. This affects xsl:QName, nametests, and method, and could be an
opportunity to define "QName-but-not-NCName" as a type.</p><p>The complexType declarations for "text-element-base-type" and "transform-element-base-type" belong
in Part A.</p></div><div class="div2">
<h3><a name="d0e281" id="d0e281"></a>2.12 Setting Initial Template Parameters</h3><p>Parameters passed to the transformation are matched against stylesheet parameters, not
against the template parameters declared within the initial template. The initial template parameters
take their default values.</p><p>This restriction can be relaxed. APIs will be allowed to allow the parameters to the initial template
to be set. This does not mean that every invocation API must offer this capability; some invocation
interfaces do not allow parameters to be set at all.</p></div><div class="div2">
<h3><a name="d0e288" id="d0e288"></a>2.13 Invoking XQuery from XSLT</h3><p>XSLT should have a way to invoke XQuery, including one or more of these ways:</p><ul><li><p>Dynamic evaluation, similar to an instruction to evaluate XSLT code dynamically from XSLT.</p></li><li><p>Importing an XQuery library, so that its functions can be called from an XSLT stylesheet.</p></li><li><p>Embedding XQuery in a stylesheet.</p></li><li><p>Invoking statically known queries, e.g., xquery-invoke("query.xqy", $src).</p></li></ul></div><div class="div2">
<h3><a name="d0e306" id="d0e306"></a>2.14 Enhancement to Sorting and Grouping</h3><p>The following extensions could be made to XSLT grouping and sorting capabilities:</p><ul><li><p>Allow xsl:variable before xsl:sort, to compute a value that can be used
both in the sort key expression and in the subsequent processing of the
relevant item.</p></li><li><p>Allow grouping keys to be specified in a separate group element.</p></li><li><p>Use this to allow composite grouping keys.</p></li><li><p>Allow control over how a sequence-valued group key is handled.</p></li><li><p>Allow variables to be declared before the group-by OR group-starting-when in place of group-starting-with;
the value is an expression rather than a pattern, and a new group starts when the expression is
true.</p></li></ul></div><div class="div2">
<h3><a name="d0e327" id="d0e327"></a>2.15 Enhancement to Conditional Modes</h3><p>It would be useful to set mode to the current mode to be able to set the mode conditionally,
based on the current mode. Additionally, it would help to make the mode conditional (dependent
on the current mode) but not be the same as the current mode. In other words, the requirement
is to dispatch to a different mode depending on what the current mode is.</p><p>This requirement does not mean to allow the <code>mode</code> attribute on <code>xsl:apply-templates</code>
to be set dynamically. Other options like the current-mode() function should be considered.</p></div><div class="div2">
<h3><a name="d0e340" id="d0e340"></a>2.16 Default Initial Template</h3><p>It would be useful as the stylesheet author to be able to define a default initial template within the stylesheet.
This would allow to run a transformation with no input without the need for the user to supply the name of initial
template. For example:</p><div class="exampleInner"><pre>
<xsl:stylesheet ...
default-initial-template="main">
<xsl:template name="main">
...
</pre></div></div></div><div class="div1">
<h2><a name="scenarios" id="scenarios"></a>3 Real-World Scenarios</h2><p>The use cases described in this section illustrate when real users reach
limits of existing XML transformation standards. The use cases are elaborated in
form of short stories.</p><div class="div2">
<h3><a name="scenario-mpeg21" id="scenario-mpeg21"></a>3.1 Transforming MPEG-21 BSDL</h3><p>The BSDL (Bitstream Syntax Description Language) is an XML schema developed
within the <a href="#iso-21000-7">[ISO/IEC 21000-7:2004]</a> standard (a part of MPEG-21 framework)
in order to describe the high-level structure of a scalable video bitstream. The
strength of BSDL lies in fact that it allows a bitstream adaptation by means of
changing an XML-based description of bitstream which makes it possible to create
a universal adaptation engine.</p><p>As the size of BSDL files is proportional to the number of bitstream frames
the BSDL files can be rather large. Apart from the number of frames the size of
BSDL files depends on the coding format of the video stream and the level of
detail of the BSDL. The more detail a BSDL contains, the larger is its size.</p><p>For example, an H.264/AVC encoded video stream lasting 7 minutes has a size
of 155 MB and contains approximately 10200 frames. The size of corresponding
BSDL file is 7.7 MB. XSLT transformations of BSDL files for longer streams often
touch limits of a processing environment. Transformations of BSDL descriptions
of "infinite" live streams require custom transformation tools.</p><p>The following fragment of BSDL file - Bitstream Syntax schema for temporal
scalable H.264/AVC bitstreams - contains a <code>byte_stream_nal_unit</code> element,
representing a NAL (Network Abstraction Layer) unit. An BSDL file can contain many
thousands of such or similar repeating elements.</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<Byte_stream xmlns="h264_avc"
bs1:bitstreamURI="example_cif.264"
xmlns:bs1="urn:mpeg:mpeg21:2003:01-DIA-BSDL1-NS"
xsi:schemaLocation="h264_avc h264_avc.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jvt="h264_avc">
<byte_stream_nal_unit>
<zero_byte>00</zero_byte>
<startcode>000001</startcode>
<nal_unit>
<forbidden_zero_bit>0</forbidden_zero_bit>
<nal_ref_idc>3</nal_ref_idc>
<nal_unit_type>5</nal_unit_type>
<raw_byte_sequence_payload>
<slice_layer_without_partitioning_rbsp>
<slice_header>
<first_mb_in_slice>0</first_mb_in_slice>
<slice_type>7</slice_type>
<pic_parameter_set_id>0</pic_parameter_set_id>
<frame_num xsi:type="b4">0</frame_num>
<idr_pic_id>0</idr_pic_id>
<pic_order_cnt_lsb xsi:type="b6">0</pic_order_cnt_lsb>
</slice_header>
<stuffbits>0</stuffbits>
<payload_data>29 24031</payload_data>
</slice_layer_without_partitioning_rbsp>
</raw_byte_sequence_payload>
</nal_unit>
</byte_stream_nal_unit>
:
</Byte_stream>
</pre></div><p>See <a href="#bsdl-content-adaptation">[BSDL: Application of Content Adaptation]</a> for more details.</p></div><div class="div2">
<h3><a name="scenario-soap-validation" id="scenario-soap-validation"></a>3.2 Validation of SOAP Digital Signatures</h3><p>The <a href="#xml-signature">[XML Signature]</a> technology has been widely adopted by Web
Services to provide message-level security. As the design of XML Signature
introduces a number of complex processing steps the validation of signatures often
lead to performance and scalability problems.</p><p>The processing steps include:</p><ol type="1"><li><p>selection of a nodeset</p></li><li><p>canonicalization</p></li><li><p>applying a digest algorithm</p></li></ol><p>While the third step is a specific cryptographic task the first and the
second step can be seen as transformation of an XML message into an XML fragment.
Using traditional XML tools like DOM, XPath and XSLT, the first two steps are
considered a bottleneck of secure Web Service systems. With larger XML messages
the processing time becomes unacceptable for real-time services.</p><p>Current services requiring better performance and scalability are thrown upon
proprietary solutions, as described in <a href="#lu">[Streaming Validation for Digital Signatures]</a>.</p></div><div class="div2">
<h3><a name="scenario-rdf-dump" id="scenario-rdf-dump"></a>3.3 Transformation of the RDF Dump of the Open Directory</h3><p>The Open Directory (http://www.dmoz.org) is a large open source web catalog,
whose content is organized into topics. These topics are hierarchically
organized (topics may contain subtopics). Every topic contains a list of
resources, consisting of a title, its URL, and a description. The complete
content of the Open Directory is available for download as one very large
(> 1 GB) RDF/XML dump.</p><p>Processing this RDF/XML file with XML software obviously requires
streaming techniques. One possible task is to create a human readable
representation by transforming the RDF file into multiple HTML pages. The
resulting HTML should be similar to the existing web pages under
www.dmoz.org.</p><p>The required transformation is rather simple: create a single HTML page for
every topic that contains links to its subtopics as well as the title, the description
and the URL of its resources. Since all topic elements occur as a flat list this
transformation can be done using similar transforming strategies as demonstrated
in <a href="#d3-flat-hierarchical"><b>4.12 Flat to Hierarchical</b></a>. More detailed information about this
RDF transforming using STX is provided in <a href="#becker">[Transforming XML on the Fly]</a>.</p><p>Another variant is to start a new group for each <code>Topic</code> containing values
from all the following <code>ExternalPage</code> elements. This is the same task as
<a href="#d1-grouping"><b>4.17 Grouping</b></a>, task b2.</p></div><div class="div2">
<h3><a name="scenario-mobile" id="scenario-mobile"></a>3.4 Transformations on a Cell Phone</h3><p>Mobile devices such as cell phones, PDAs, etc. often provide very limited RAM
memory. Applications for such devices must be specially designed to respect
these limitations. An XML processing which takes place on these devices should not
require to store both XML source and result concurrently in memory. A strategy that
consumes source XML and produces the result simultaneously is much more appropriate.</p><p>A mobile blogging application is an example of application which needs to process
XML in the constrained environment. Using this application, people may create blog
entries on their mobile device and post them to special blog servers (aka blog service
providers - BSP). As different BSPs use different XML formats the challenge is to
provide an architecture for one mobile application that works with different BSPs.
This can be achieved by transforming the entered blog data (which is represented
as XML in the mobile blog application) into the required XML format of the receiving
BSP directly on the mobile device. For every BSP there is a special plugin that knows
the transformation rules.</p><p>Source XML:</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<entry>
<title type='text'>New Post</title>
<content type='xhtml'>
<div id='content'>Text embedded with the picture. </div>
<div id='picture'>
<object type='image/jpeg' id='pic[0]'
data='data:image/jpeg;base64,Base64CodeEmbedded'/>
</div>
</content>
<author>
<name>This is where the authors are posted.</name>
</author>
</entry>
</pre></div><p>Target XML (Flickr):</p><div class="exampleInner"><pre>
<?xml version="1.0" encoding=" ISO-8859-1" ?>
<a:entry xmlns:a="http://purl.org/atom/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<title mode="escaped">New Post</title>
<summary mode="escaped">Text embedded with the picture. </summary>
<content type="image/jpeg" mode="base64">
Base64CodeEmbedded
</content>
<issued />
<standalone xmlns="http://sixapart.com/atom/typepad#">
1
</standalone>
</a:entry>
</pre></div><p>One of the specific problems was the base64 encoded text for representing
images. It would be desirable to stream this text node, too. The current XML data
model represents this text as one text node so it is difficult or even impossible
to transform this text in smaller parts using XSLT, even if the whole task is to
the text as it is to the result.</p><p>See <a href="#mobile-blogging">[Plug-in Based Architecture for Mobile Blogging]</a> for more details.</p></div><div class="div2">
<h3><a name="scenario-multiple-fo" id="scenario-multiple-fo"></a>3.5 XSL FO Multiple Extraction/Processing</h3><p>Transformation of an extensive XML document consisting of sections,
headings, paragraphs, and figures. The result consists of a formatted
document containing three, consecutive, parts:</p><ul><li><p>heading titles extracted from the source document (aka table of content)</p></li><li><p>figure titles extracted from the source document (aka list of figures)</p></li><li><p>the source document transformed in a simple, mostly linear, way</p></li></ul><p>This kind of transformation is very common for producing an XSL FO
instance that is then formatted.</p><p>The complete stylesheet for this transformation can be downloaded from
<a href="http://www.w3.org/2010/06/ABmp_doc.xsl">http://www.w3.org/2010/06/ABmp_doc.xsl</a>.</p></div><div class="div2">
<h3><a name="scenarion-eft-edi" id="scenarion-eft-edi"></a>3.6 EFT/EDI Transformation</h3><p>Given a huge (more than 1GB) denormalized XML extraction from database
or other data source. The XSLT implementation needs to process nested regrouping
and sorting along with varies calculation and produce grouped and sorted output
as plain text.</p><p>This is a rather simplified version of a typical EFT/EDI (Electronic Funds
Transfer/Electronic Data Interchange) transformation Oracle product handles. In real life
such XSLT transform is not written by hand, instead the product compiles an table based
EFT/EDI definition with PL/SQL alike syntax to XSLT by a processor, which usually yields in
a complicated transformation. Nevertheless, even the simplified version does include some
of the major challenging part of XSLT 2.0 in terms of streaming, e.g. regrouping with
sorting, sorting within grouped data, and aggregation.</p><p>The xml data is some time normalized with structure, but most of the time it's
rather just straightforward rowset/row dataset like following xml, and the size of
that can easily reach hundreds of megabyte, even gigabyte level:</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<rowset>
<row>
<c1>aa</c1>
<c2>ab</c2>
<c3>ac</c3>
:
</row>
<row>
<c1>ba</c1>
<c2>bb</c2>
<c3>bc</c3>
:
</row>
:
</rowset>
</pre></div><p>The XSLT is like this:</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output format="text"/>
<xsl:template match="/">
<xsl:for-each-group select="rowset/row" group-by="c1">
<xsl:sort select="current-grouping-key()"/>
<xsl:call-template name="process_rows"/>
</xsl:for-each-group>
<xsl:text>GRAND TOTAL:</xsl:text>
<xsl:value-of select="sum(rowset/row/c3)"/>
</xsl:template>
<xsl:template name="process_rows">
<xsl:for-each select="current-group()">
<xsl:sort select="c2"/>
<xsl:text>FROM:</xsl:text>
<xsl:value-of select="c1"/>
<xsl:text>,TO:</xsl:text>
<xsl:value-of select="c2"/>
<xsl:text>,AMOUNT:</xsl:text>
<xsl:value-of select="c3"/>
</xsl:for-each>
<xsl:text>TOTAL:</xsl:text>
<xsl:value-of select="sum(current-group()/c3)"/>
</xsl:template>
</xsl:stylesheet>
</pre></div></div></div><div class="div1">
<h2><a name="tasks" id="tasks"></a>4 Tasks</h2><p>Tasks are examples of relatively simple transformations whose definitions in XSLT 2.0 are not easy,
straightforward or even possible. Some of these tasks are difficult solely because of the fact that
one or more input or output XML documents is so large that the entire document cannot be held in memory.
Other difficulties are related to merging and forking documents, restricted capabilities to iterate and
the lack of common constructs (dynamic evaluation of expressions, try/catch).</p><p>The transformation task illustrating troubles with huge XML documents (<a href="#d1-splitting-flat"><b>4.1 Splitting Flat Data</b></a>)
can be defined in XSLT 2.0. The processor can even recognize that there is no need to keep the entire
document in memory and can run the transformation in a memory-efficient way in some cases. But there no
guarantee of this behavior. New facilities suggested for XSLT 2.1 aim to guarantee that a transformation
must be processed in a streaming manner.</p><div class="div2">
<h3><a name="d1-splitting-flat" id="d1-splitting-flat"></a>4.1 Splitting Flat Data</h3><p><b>Task:</b> Split the document <a href="#data-1a"><b>A.1 Flat Collection</b></a> so that each
<code>chapter</code> child is copied to a separate XML document, with a URI of the form
outer/chapterN.xml where N is a sequence number. The input document <a href="#data-1a"><b>A.1 Flat Collection</b></a>
is too large to fit into memory but each <code>chapter</code> subtree (and thus each
output document) fits into memory.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/wrapper">
<xsl:for-each select="chapter">
<xsl:result-document href="chapter{position()}.xml">
<xsl:-of select="."/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. The only difference is that the unnamed mode is explicitly
marked as capable of being processed in a streaming manner.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes"/>
<xsl:template match="/wrapper">
<xsl:for-each select="chapter">
<xsl:result-document href="chapter{position()}.xml">
<xsl:-of select="."/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-splitting-nested" id="d1-splitting-nested"></a>4.2 Splitting Nested Data</h3><p>The same task as <a href="#d1-splitting-flat"><b>4.1 Splitting Flat Data</b></a> but with a different input data.
The main difference is that <code>chapter</code> elements are not necessarily children of
the <code>wrapper</code> element.</p><p><b>Task:</b> Split the document <a href="#data-1b"><b>A.2 Nested Collection</b></a> so that each
<code>chapter</code> which is not descendant of another <code>chapter</code> element is copied
to a separate XML document, with a URI of the form chapterN.xml where N is
a sequence number.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/wrapper">
<xsl:for-each select="//chapter[not(ancestor::chapter)]">
<xsl:result-document href="chapter{position()}.xml">
<xsl:copy-of select="."/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. Again, the only difference is that the unnamed mode is explicitly
marked as streamable.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes"/>
<xsl:template match="/wrapper">
<xsl:for-each select="outermost(//chapter)"/>
<xsl:result-document href="chapter{position()}.xml">
<xsl:copy-of select="."/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-joining" id="d1-joining"></a>4.3 Joining</h3><p><b>Task:</b> Do the inverse of the <a href="#d1-splitting-flat"><b>4.1 Splitting Flat Data</b></a> use
case. That is, join documents produced by the <a href="#d1-splitting-flat"><b>4.1 Splitting Flat Data</b></a>
use case and create a single <a href="#data-1a"><b>A.1 Flat Collection</b></a> document on the output.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="last-doc"/>
<xsl:template name="main">
<wrapper>
<xsl:for-each select="1 to $last-doc">
<xsl:copy-of select="document(concat('chapter', ., '.xml'))"/>
</xsl:for-each>
</wrapper>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. This version uses a new construct <code>xsl:stream</code> that reads a source document and processes the content of the document in a streaming manner.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="last-doc"/>
<xsl:template name="main">
<wrapper>
<xsl:for-each select="1 to $last-doc">
<xsl:stream href="{concat('chapter', ., '.xml')}">
<xsl:copy-of select="."/>
</xsl:stream>
</xsl:for-each>
</wrapper>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-concatenation" id="d1-concatenation"></a>4.4 Concatenation</h3><p><b>Task:</b> Given two 1GB documents with structure of <a href="#data-1a"><b>A.1 Flat Collection</b></a>,
create a single 2GB file with the same structure, that contains first all the
<code>chapter</code> children from the first file, then all the <code>chapter</code> children
from the second file. A relevant difference between this use case and
<a href="#d1-joining"><b>4.3 Joining</b></a> is that the two input documents are too large to fit
into memory in this use case, while <a href="#d1-joining"><b>4.3 Joining</b></a> concatenates a number
of smaller input documents each of them can be held in memory.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="doc1"/>
<xsl:param name="doc2"/>
<xsl:template name="main">
<wrapper>
<xsl:copy-of select="document($doc1)/wrapper/chapter"/>
<xsl:copy-of select="document($doc2)/wrapper/chapter"/>
</wrapper>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. The unnamed mode is explicitly marked as streamable
and the documents are read using <code>xsl:stream</code>.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes"/>
<xsl:param name="doc1"/>
<xsl:param name="doc2"/>
<xsl:template name="main">
<wrapper>
<xsl:stream href="{$doc1}">
<xsl:copy-of select="wrapper/chapter"/>
</xsl:stream>
<xsl:stream href="{$doc2}">
<xsl:copy-of select="wrapper/chapter"/>
</xsl:stream>
</wrapper>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-adding-children" id="d1-adding-children"></a>4.5 Adding Children</h3><p><b>Task:</b> Given an input document with the structure of
<a href="#data-1a"><b>A.1 Flat Collection</b></a>, produce a new 1GB document where a predefined
nested content (child elements) is added to each <code>chapter</code> element.
The existing contents of the <code>chapter</code> elements are retained.
The new contents are added at the beginning.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="content_to_add"/>
<xsl:template match="chapter">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="document($content_to_add)"/>
<xsl:copy-of select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. The unnamed mode is marked as streamable. The <code>on-no-match</code> attribute specifies which built-in rules to use to process a node that does not match any user-written template. The value "copy" means that the source tree is copied unchanged to the output. This why the "identity template" can be left out from the stylesheet.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes" on-no-match="copy"/>
<xsl:param name="content_to_add"/>
<xsl:template match="chapter">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="document($content_to_add)"/>
<xsl:copy-of select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-renaming-nested" id="d1-renaming-nested"></a>4.6 Renaming and Counting Nested Elements</h3><p><b>Task:</b> Rename all <code>chapter</code> elements in <a href="#data-1b"><b>A.2 Nested Collection</b></a>
to <code>section</code>. Additionally, print the number of renamed elements
at the end of the document.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/wrapper">
<xsl:copy>
<xsl:apply-templates />
<renamed count="{count(//chapter)}" />
</xsl:copy>
</xsl:template>
<xsl:template match="chapter">
<section>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</section>
</xsl:template>
<xsl:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:transform>
</pre></div><p>XSLT 2.1 implementation. The unnamed mode is marked as streamable. The default built-in rule is "copy". A new instruction <code>xsl:fork</code> is used to enable streamed processing in the case where several constructs (<code>xsl:apply-templates</code>, count()) need to be evaluated during a single pass over the input data. The result is exactly the same as if the xsl:fork element was not there; it only provides a hint to processor that contained instructions should be evaluated during a single pass. The instruction must be independent.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode name="rename" streamable="yes" on-no-match="copy"/>
<xsl:template name="/wrapper">
<xsl:copy>
<xsl:fork>
<xsl:apply-templates />
<renamed count="{count(//chapter)}" />
</xsl:fork>
</xsl:copy>
</xsl:template>
<xsl:template match="chapter">
<section>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</section>
</xsl:template>
</xsl:transform>
</pre></div></div><div class="div2">
<h3><a name="d1-renaming-nested-more-counting" id="d1-renaming-nested-more-counting"></a>4.7 Renaming and Counting Nested Elements and Counting Other Elements</h3><p><b>Task:</b> The same task like <a href="#d1-renaming-nested"><b>4.6 Renaming and Counting Nested Elements</b></a> but in addition we also want
to count <code>removed</code> in <a href="#data-1b"><b>A.2 Nested Collection</b></a>. The number of renamed <code>chapter</code> elements and the number of <code>removed</code> elements is printed out at the end of the document.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/wrapper">
<xsl:copy>
<xsl:apply-templates />
<renamed count="{count(//chapter)}" />
<removed count="{count(//removed)}" />
</xsl:copy>
</xsl:template>
<xsl:template match="chapter">
<section>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</section>
</xsl:template>
<xsl:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:transform>
</pre></div><p>XSLT 2.1 implementation. The unnamed mode is marked as streamable. The default built-in rule is "copy". The <code>xsl:fork</code> instruction is used to enable streamed processing of three independent constructs: <code>xsl:apply-templates</code>, count(//chapter), count(//removed).</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes" on-no-match="copy"/>
<xsl:template name="/wrapper">
<xsl:copy>
<xsl:fork>
<xsl:apply-templates />
<renamed count="{count(//chapter)}" />
<removed count="{count(//removed)}" />
</xsl:fork>
</xsl:copy>
</xsl:template>
<xsl:template match="chapter">
<section>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</section>
</xsl:template>
</xsl:transform>
</pre></div></div><div class="div2">
<h3><a name="d1-filtering-att" id="d1-filtering-att"></a>4.8 Filtering According to Attribute</h3><p><b>Task:</b> Given an input document with the structure of
<a href="#data-1a"><b>A.1 Flat Collection</b></a>, remove all <code>chapter</code> elements which have
the <code>removed</code> attribute.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="chapter[@removed]" />
<xsl:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. The unnamed mode is marked as streamable. The default built-in rule "copy" is used for all nodes but <code>chapter</code> elements with <code>removed</code> attribute.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes" on-no-match="copy"/>
<xsl:template match="chapter[@removed]" />
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-filtering-child" id="d1-filtering-child"></a>4.9 Filtering According to Child</h3><p><b>Task:</b> Given an input document with the structure of
<a href="#data-1a"><b>A.1 Flat Collection</b></a>, remove all <code>chapter</code> elements which have
at least one <code>removed</code> child.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="chapter[removed]"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. This is a windowing example. Each chapter is processed in non-streaming mode but independently on other chapters. The transformation is initiated in the unnamed streamable mode. A copy of the subtree rooted at the <code>chapter</code> element is created for each chapter and processed in a non-streamable "chapter" mode. </p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes" />
<xsl:mode name="chapter" streamable="no" />
<xsl:template match="/wrapper">
<xsl:copy>
<xsl:apply-templates select="copy-of(chapter)" mode="chapter" />
</xsl:copy>
</xsl:template>
<xsl:template match="chapter" mode="chapter">
<xsl:if test="not(removed)">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-histogram" id="d1-histogram"></a>4.10 Histogram</h3><p><b>Task:</b> Given a 1GB document with the structure of
<a href="#data-1a"><b>A.1 Flat Collection</b></a> produce a histogram showing the frequency
distribution of <code>chapter</code> elements by the number of
paragraphs (descendant <code>p</code> elements) in each document.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:template match="/wrapper">
<!-- count the number of <p> elements in each <chapter> -->
<xsl:variable name="counted_p">
<count>
<xsl:for-each select="chapter">
<ps><xsl:value-of select="count(p)"/></ps>
</xsl:for-each>
</count>
</xsl:variable>
<!-- find min and max -->
<xsl:variable name="min_ps" select="min($counted_p/count/ps) cast as xs:integer" />
<xsl:variable name="max_ps" select="max($counted_p/count/ps) cast as xs:integer" />
<!-- do the histogram -->
<xsl:text>Number of "chapter" elements with N "p" elements; N from </xsl:text>
<xsl:value-of select="$min_ps"/><xsl:text> to </xsl:text>
<xsl:value-of select="$max_ps"/>
<xsl:text>&#010;</xsl:text>
<xsl:for-each select="$min_ps to $max_ps">
<xsl:variable name="nr_ps" select="."/>
<xsl:variable name="nr_chapters" select="count($counted_p/count/ps[ . = $nr_ps])"/>
<xsl:call-template name="do_histo_bar">
<xsl:with-param name="nr" select="$nr_chapters"/>
</xsl:call-template>
<xsl:text>&#010;</xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template name="do_histo_bar">
<xsl:param name="nr" select="0"/>
<xsl:for-each select="1 to $nr">
<xsl:text>X</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. The unnamed mode is marked as streamable which is the only change needed to make this stylesheet streamable. The data is stored in a variable during a single pass through the input document. The subsequent processing only uses the stored data.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:mode streamable="yes"/>
<xsl:template match="/wrapper">
<!-- count the number of <p> elements in each <chapter> -->
<xsl:variable name="counted_p">
<count>
<xsl:for-each select="chapter">
<ps><xsl:value-of select="count(p)"/></ps>
</xsl:for-each>
</count>
</xsl:variable>
<!-- find min and max -->
<xsl:variable name="min_ps" select="min($counted_p/count/ps) cast as xs:integer" />
<xsl:variable name="max_ps" select="max($counted_p/count/ps) cast as xs:integer" />
<!-- do the histogram -->
<xsl:text>Number of "chapter" elements with N "p" elements; N from </xsl:text>
<xsl:value-of select="$min_ps"/><xsl:text> to </xsl:text>
<xsl:value-of select="$max_ps"/>
<xsl:text>&#010;</xsl:text>
<xsl:for-each select="$min_ps to $max_ps">
<xsl:variable name="nr_ps" select="."/>
<xsl:variable name="nr_chapters" select="count($counted_p/count/ps[ . = $nr_ps])"/>
<xsl:call-template name="do_histo_bar">
<xsl:with-param name="nr" select="$nr_chapters"/>
</xsl:call-template>
<xsl:text>&#010;</xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template name="do_histo_bar">
<xsl:param name="nr" select="0"/>
<xsl:for-each select="1 to $nr">
<xsl:text>X</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d3-hierarchical-flat" id="d3-hierarchical-flat"></a>4.11 Hierarchical to Flat</h3><p><b>Task:</b> Starting with a tree structure convert it to a flat list of
node that keeps the relation between node (with addition of two attributes
<code>@parent</code> and <code>@preceding-sibling</code>). See
<a href="#data-3"><b>A.4 Hierarchical to Flat</b></a>.</p><p>XSLT 2.0 implementation. This version reads the parent and preceding-sibling ID
from the tree. Parent and preceding-sibling axes are used which makes the streaming processing difficult.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/tree">
<nodes>
<xsl:apply-templates select="node"/>
</nodes>
</xsl:template>
<xsl:template match="node">
<xsl:text>&#010;</xsl:text>
<node>
<xsl:attribute name="id" select="@id"/>
<xsl:attribute name="parent" select="if (parent::tree) then 'ROOT' else parent::node/@id" />
<xsl:attribute name="preceding-sibling" select="preceding-sibling::node[1]/@id" />
<xsl:copy-of select="content"/>
</node>
<xsl:apply-templates select="node"/>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>Another XSLT 2.0 implementation. The parent and preceding-sibling ID are passed along as parameters.
which avoids both parent and preceding-sibling axes and is more convenient for streaming.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/tree">
<nodes>
<xsl:apply-templates select="node[1]"/>
</nodes>
</xsl:template>
<xsl:template match="node">
<xsl:param name="pid" select="'ROOT'"/>
<xsl:param name="sid"/>
<xsl:text>&#010;</xsl:text>
<node>
<xsl:attribute name="id" select="@id"/>
<xsl:attribute name="parent" select="$pid"/>
<xsl:attribute name="preceding-sibling" select="$sid"/>
<xsl:copy-of select="content"/>
</node>
<xsl:apply-templates select="node[1]">
<xsl:with-param name="pid" select="@id"/>
<xsl:with-param name="sid" select="''"/>
</xsl:apply-templates>
<xsl:apply-templates select="following-sibling::node[1]">
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="sid" select="@id"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. It's based on the second XSLT 2.0 implementation of the task
above. The unnamed mode is marked as streamable. There are two downwards selections
in the last template - child::node[1] and following-sibling::node[1]. These two
selections are streamable in this order but the XSLT processor need not to recognize this fact.
This transformation is not guaranteed streamable.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes"/>
<xsl:template match="/tree">
<nodes>
<xsl:apply-templates select="node[1]"/>
</nodes>
</xsl:template>
<xsl:template match="node">
<xsl:param name="pid" select="'ROOT'"/>
<xsl:param name="sid"/>
<xsl:text>&#010;</xsl:text>
<node>
<xsl:attribute name="id" select="@id"/>
<xsl:attribute name="parent" select="$pid"/>
<xsl:attribute name="preceding-sibling" select="$sid"/>
<xsl:copy-of select="content"/>
</node>
<xsl:apply-templates select="node[1]">
<xsl:with-param name="pid" select="@id"/>
<xsl:with-param name="sid" select="''"/>
</xsl:apply-templates>
<xsl:apply-templates select="following-sibling::node[1]">
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="sid" select="@id"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>Another XSLT 2.1 implementation with <code>xsl:iterate</code> rather than recursion. This removes
the issue with two downwards selections and is guaranteed streamable. However it relies on the fact that
<code>content</code> is the first element child of <code>node</code>.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes"/>
<xsl:template match="/tree">
<nodes>
<xsl:apply-templates select="*"/>
</nodes>
</xsl:template>
<xsl:template match="node">
<xsl:param name="pid" select="'ROOT'"/>
<xsl:param name="sid"/>
<xsl:iterate select="*">
<xsl:param name="pid"/>
<xsl:param name="sid"/>
<xsl:variable name="myid" select="string(@id)"/>
<xsl:apply-templates select=".">
<xsl:with-param name="gpid" select="(ancestor::node[2]/@id,'ROOT')[1]"/>
<xsl:with-param name="pid" select="parent::node/@id"/>
<xsl:with-param name="sid" select="$sid"/>
</xsl:apply-templates>
<xsl:next-iteration>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="sid" select="if (self::content) then '' else $myid"/>
</xsl:next-iteration>
</xsl:iterate>
</xsl:template>
<xsl:template match="content">
<xsl:param name="gpid"/>
<xsl:param name="pid"/>
<xsl:param name="sid"/>
<xsl:text>&#xa;</xsl:text>
<node id="{$pid}" parent="{$gpid}" preceding-sibling="{$sid}">
<xsl:copy-of select="."/>
</node>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d3-flat-hierarchical" id="d3-flat-hierarchical"></a>4.12 Flat to Hierarchical</h3><p><b>Task:</b> The reverse operation to <a href="#d3-hierarchical-flat"><b>4.11 Hierarchical to Flat</b></a>.
The conversion of a flat list of nodes to a tree structure. See <a href="#data-3"><b>A.4 Hierarchical to Flat</b></a>.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/nodes">
<tree>
<xsl:apply-templates select="node[1]"/>
</tree>
</xsl:template>
<xsl:template match="node">
<xsl:variable name="id" select="@id"/>
<node id="{@id}">
<xsl:copy-of select="content"/>
<!-- descendants -->
<xsl:apply-templates select="following-sibling::node[@parent = $id and @preceding-sibling = ''][1]"/>
</node>
<!-- following sibling -->
<xsl:apply-templates select="following-sibling::node[@preceding-sibling = $id]"/>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. This transformation is in theory streamable because all nodes that will be found with the first <code>apply-templates</code> (descendants) go before the nodes matching the second <code>apply-templates</code> (following siblings). But this fact is only evident to those who fully understand the meaning of the input data (<a href="#data-3"><b>A.4 Hierarchical to Flat</b></a>) and semantics of its elements and attributes. It would be rather difficult to come to the same conclusion with the automatic analysis of the stylesheet and input data. Therefore this task can be another example of transformation that is not recognized as streamable by an XSLT 2.1 processor despite of the fact that it could be run in a streaming way. This transformation is not guaranteed streamable.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes" />
<xsl:template match="/nodes">
<tree>
<xsl:apply-templates select="node[1]"/>
</tree>
</xsl:template>
<xsl:template match="node">
<xsl:variable name="id" select="@id"/>
<node id="{@id}">
<xsl:copy-of select="content"/>
<!-- descendants -->
<xsl:apply-templates select="following-sibling::node[@parent = $id and @preceding-sibling = ''][1]"/>
</node>
<!-- following sibling -->
<xsl:apply-templates select="following-sibling::node[@preceding-sibling = $id]"/>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d4-csv" id="d4-csv"></a>4.13 CSV Result</h3><p><b>Task:</b> Given 1GB input document containing multiple <code>row</code>
elements with <code>col</code> children (<a href="#data-4"><b>A.5 Rows and Columns</b></a>), produce
a csv document with the content of <code>col</code> elements.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="row">
<xsl:value-of select="col" separator=", "/>
<xsl:text>&#010;</xsl:text>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. The unnamed mode is marked as streamable.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes" />
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="row">
<xsl:value-of select="col" separator=", "/>
<xsl:text>&#010;</xsl:text>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-local-sorting" id="d1-local-sorting"></a>4.14 Local Sorting</h3><p><b>Task:</b> Given a 1GB document with the structure of
<a href="#data-1a"><b>A.1 Flat Collection</b></a>, produce an output document containing the same
data, but with all elements <code>p</code> within each <code>chapter</code> element
sorted in the alphabetic order. The other elements within the <code>chapter</code>
element follow the sorted <code>p</code> elements in the same document order.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/wrapper">
<xsl:copy>
<xsl:apply-templates select="chapter"/>
</xsl:copy>
</xsl:template>
<xsl:template match="chapter">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each select="p">
<xsl:sort />
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:apply-templates select="* except p"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. Another windowing example. Each chapter is processed in non-streaming mode but independently on other chapters. The transformation is initiated in the unnamed streamable mode. Each chapter is then sorted in a non-streamable "chapter" mode.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes"/>
<xsl:mode name="chapter" streamable="no" on-no-match="copy"/>
<xsl:template match="/wrapper">
<xsl:copy>
<xsl:apply-templates select="copy-of(chapter)" mode="chapter"/>
</xsl:copy>
</xsl:template>
<xsl:template match="chapter" mode="chapter">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each select="p">
<xsl:sort />
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:apply-templates select="* except p"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d2-references" id="d2-references"></a>4.15 Resolving References</h3><p><b>Task:</b> Given the two documents <a href="#data-2"><b>A.3 Product Catalog</b></a>, produce a new
document in which the code attribute is replaced by a description attribute, where
the description is derived from the product code by a lookup in a 100Kb product
codes document.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="product_codes" select="document('data-2-codes.xml')"/>
<xsl:template match="product">
<product description="{$product_codes/*/code[@id = current()/@code]}">
<xsl:apply-templates/>
</product>
</xsl:template>
<!-- identity transform template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. The unnamed mode is marked as streamable. All codes and their descriptions are stored in a variable.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes" on-no-match="copy" />
<xsl:variable name="product_codes" select="document('data-2-codes.xml')"/>
<xsl:template match="product">
<product description="{$product_codes/*/code[@id = current()/@code]}">
<xsl:apply-templates/>
</product>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-multiple-extraction" id="d1-multiple-extraction"></a>4.16 Multiple Extraction/Processing</h3><p><b>Task:</b> Process <a href="#data-1b"><b>A.2 Nested Collection</b></a> to produce a series of
<code>chapter-name</code> elements containing the content of the chapter/@name attributes
followed by a series of <code>chapter-id</code> elements containing the content of chapter/@id
attributes followed by a <code>body</code> element containing all <code>p</code> elements and
their text content.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/wrapper">
<result>
<xsl:apply-templates select=".//chapter" mode="name"/>
<xsl:apply-templates select=".//chapter" mode="id"/>
<body>
<xsl:apply-templates select=".//p"/>
</body>
</result>
</xsl:template>
<xsl:template match="chapter" mode="name">
<chapter-name>
<xsl:value-of select="@name"/>
</chapter-name>
</xsl:template>
<xsl:template match="chapter" mode="id">
<chapter-id>
<xsl:value-of select="@id"/>
</chapter-id>
</xsl:template>
<xsl:template match="p">
<p>
<xsl:value-of select="text()"/>
</p>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>This transformation requires multiple scans of the input data. The single scan way
of processing would require to buffer basically the whole document. Neither streaming
facilities of XSLT 2.1 nor <code>xsl:fork</code> can help to avoid the multiple scanning or
the extensive buffering.</p></div><div class="div2">
<h3><a name="d1-grouping" id="d1-grouping"></a>4.17 Grouping</h3><p><b>Task:</b> Process <a href="#data-1a"><b>A.1 Flat Collection</b></a> data. Group <code>chapter</code> elements
by position and insert new contents between the groups. Copy the input and add an empty
<code>pagebreak</code> element every 3 chapters.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="chapter">
<xsl:variable name="position">
<xsl:number />
</xsl:variable>
<xsl:if test="$position != 1 and $position mod 3 = 1">
<pagebreak />
</xsl:if>
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. The unnamed mode is marked as streamable.
The <code>xsl:number</code> instruction is not always guaranteed streamable
but in this specific case the streamed evaluation is possible.</p><div class="exampleInner"><pre>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.1">
<xsl:mode streamable="yes" on-no-match="copy"/>
<xsl:template match="chapter">
<xsl:variable name="position">
<xsl:number />
</xsl:variable>
<xsl:if test="$position != 1 and $position mod 3 = 1">
<pagebreak />
</xsl:if>
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-iterate" id="d1-iterate"></a>4.18 Iterations</h3><p><b>Task:</b> Transform the input document to the required output as described in
<a href="#data-transactions"><b>A.6 Transactions and Balance</b></a>. The data of individual transactions are accumulated and
the current balance is maintained for each transaction.</p><p>XSLT 2.0 implementation. A template is called recursively.</p><div class="exampleInner"><pre>
<xsl:template match="/transactions">
<account>
<xsl:apply-templates select="transaction[1]" />
</account>
</xsl:template>
<xsl:template match="transaction">
<xsl:param name="balance" select="0.00" as="xs:decimal"/>
<xsl:variable name="newBalance"
select="$balance + xs:decimal(@value)"/>
<balance date="{@date}" value="{$newBalance}" change="{@value}"/>
<xsl:apply-templates select="following-sibling::transaction[1]">
<xsl:with-param name="balance" select="$newBalance"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. The tail recursion is replaced with an iteration - using the new
<code>xsl:iterate</code> construct.</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:mode streamable="yes"/>
<xsl:template match="/transactions">
<account>
<xsl:iterate select="transaction">
<xsl:param name="balance" select="0.00" as="xs:decimal"/>
<xsl:variable name="newBalance"
select="$balance + xs:decimal(@value)"/>
<balance date="{@date}" value="{$newBalance}"/>
<xsl:next-iteration>
<xsl:with-param name="balance" select="$newBalance"/>
</xsl:next-iteration>
</xsl:iterate>
</account>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-windowing" id="d1-windowing"></a>4.19 Making Explicit Sections</h3><p><b>Task:</b> Process <a href="#data-windowing"><b>A.7 Explicit Sections</b></a> data.
Convert a structure with implicit sections to a structure with explicit sections.</p><p>This use case has been described in <a href="#xquery11-use-cases">[XQuery 1.1 Use Cases]</a> (4.2.2. - Windowing Q2).</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/body">
<chapter>
<xsl:for-each select="h2">
<section title="{text()}">
<xsl:apply-templates select="following-sibling::p[1]" />
</section>
</xsl:for-each>
</chapter>
</xsl:template>
<xsl:template match="p">
<para>
<xsl:value-of select="text()" />
</para>
<xsl:if test="name(following-sibling::*[1]) = 'p'">
<xsl:apply-templates select="following-sibling::p[1]"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. The unnamed mode is marked as streamable. The tail recursion is replaced with iteration.</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes"/>
<xsl:template match="/body">
<chapter>
<xsl:for-each select="h2">
<section title="{text()}">
<xsl:iterate select="following-sibling::*">
<para>
<xsl:value-of select="text()" />
</para>
<xsl:if test="name(following-sibling::*[1]) != 'p'">
<xsl:break />
</xsl:if>
</xsl:iterate>
</section>
</xsl:for-each>
</chapter>
</xsl:template>
</xsl:stylesheet>
</pre></div></div><div class="div2">
<h3><a name="d1-merging" id="d1-merging"></a>4.20 Merging Sorted Sequences</h3><p><b>Task:</b> Merge the input document specified in <a href="#data-transactions"><b>A.6 Transactions and Balance</b></a>
with another instance of the same document type to produce an output document of the same type
that contains all transactions from both input documents. Both input documents are already sorted.
The output keeps the same order.</p><p>XSLT 2.0 implementation.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="other" select="document('transactions-2.xml')"/>
<xsl:template match="/transactions">
<xsl:copy>
<xsl:apply-templates select="transaction[1]">
<xsl:with-param name="date" select="$other/transactions/transaction[1]/@date"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="transaction">
<xsl:param name="date"/>
<xsl:variable name="current_date" select="@date"/>
<xsl:for-each select="$other/transactions/transaction[@date &gt;= $date][@date &lt; $current_date]">
<Transaction date="{@date}" value="{@value}"/>
</xsl:for-each>
<transaction date="{@date}" value="{@value}"/>
<xsl:apply-templates select="following-sibling::transaction[1]">
<xsl:with-param name="date" select="$current_date"/>
</xsl:apply-templates>
<xsl:if test="not(following-sibling::transaction)">
<xsl:for-each select="$other/transactions/transaction[@date &gt; $date]">
<TRansaction date="{@date}" value="{@value}"/>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
</pre></div><p>XSLT 2.1 implementation. This transformation uses the <code>xsl:merge</code> instruction
which allows to construct a sorted sequence of items by merging several input pre-sorted sequences.
The <code>xsl:merge</code> instruction is designed to enable the streaming processing.</p><div class="exampleInner"><pre>
<xsl:stylesheet version="2.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes"/>
<xsl:template match="/transactions">
<xsl:copy>
<xsl:merge>
<xsl:merge-source select="doc('transactions-1.xml'), doc('transactions-2.xml')">
<xsl:merge-input select="transactions/transaction">
<xsl:merge-key select="@date"/>
</xsl:merge-input>
</xsl:merge-source>
<xsl:merge-action>
<xsl:copy-of select="current-group()"/>
</xsl:merge-action>
</xsl:merge>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</pre></div></div></div></div><div class="back"><div class="div1">
<h2><a name="sample-data" id="sample-data"></a>A Sample Data</h2><p>The following XML data are used in use cases</p><div class="div2">
<h3><a name="data-1a" id="data-1a"></a>A.1 Flat Collection</h3><p>A 1GB document consisting of a single <code>wrapper</code> element
with a number of <code>chapter</code> children, each of them having several
<code>p</code> children and an optional <code>removed</code> child. There are
no nested <code>chapter</code> elements.</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<wrapper>
<chapter id="1" name="a_chapter_1">
<p>S the first element of the list.</p>
<p>Ele.</p>
<p>He first element of the list, passing the rema.</p>
</chapter>
<removed/>
<chapter id="2" name="a_chapter_2" removed="yes">
<p>A.</p>
<removed/>
<p>Fied as the first el.</p>
<p>Fied as the first element of the list, passing the remaining elements as.</p>
<p>Ified as the first ele.</p>
<p>First element of the list, passing the remaining elements as.</p>
</chapter>
<chapter id="3" name="b_chapter_3" removed="yes">
<p>As the first element of the list, passing the remaining element.</p>
<removed/>
</chapter>
:
</wrapper>
</pre></div></div><div class="div2">
<h3><a name="data-1b" id="data-1b"></a>A.2 Nested Collection</h3><p>A less regular version of the strict <a href="#data-1a"><b>A.1 Flat Collection</b></a> document.
<code>chapter</code> elements are not children of <code>wrapper</code> and they are not all
siblings. Also, the content of <code>chapter</code> is not limited to <code>p</code>
elements. The size of document is still about 1GB.</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<wrapper>
<chapter id="1" name="chapter_1">
<p>S the first element of the list.</p>
<p>Ele.</p>
<chapter id="2" name="chapter_2">
<p>Element of the list, pao the syst.</p>
</chapter>
<p>He first element of tht, passing the rema.</p>
</chapter>
<set>
<chapter id="3" name="chapter_3">
<p>A.</p>
<chapter id="4" name="chapter_4" removed="yes">
<p>.</p>
<p>T element o.</p>
</chapter>
<removed/>
<p>Fied as the first el.</p>
<p>Fied as the fig the remaining elements as.</p>
<p>Ified as the first ele.</p>
<p>First element of the list, passing the remaining elements as.</p>
</chapter>
</set>
<chapter id="5" name="chapter_5" removed="yes">
<p>As the first element of the list, passing the remaining element.</p>
</chapter>
<removed/>
:
</wrapper>
</pre></div></div><div class="div2">
<h3><a name="data-2" id="data-2"></a>A.3 Product Catalog</h3><p>A 1GB catalog document that contains <code>product</code> elements with
<code>code</code> attributes, and a 100kB product codes document. </p><p>Main document:</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<catalog>
<product code="111">
<description>
<p>This amazing carburettor choke valve is the best thing for you since
pre-sliced bread. That is, unless, you live in a country where the bread is baked
fresh and delivered to you for eating within a short period of time.
In this case this product is the best thing since steamed frech lobster.</p>
<p>Use of this product will make your car go twice as fast, consume less petrol,
and pollute less.</p>
</description>
</product>
<product code="112">
<description>
<p>This amazing carburettor choke nut is the best thing for you since
pre-sliced bread. That is, unless, you live in a country where the bread is baked
fresh and delivered to you for eating within a short period of time.
In this case this product is the best thing since steamed frech lobster.</p>
<p>Use of this product will make your car go twice as fast, consume less petrol,
and pollute less.</p>
</description>
</product>
:
</catalog>
</pre></div><p>Product codes document:</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<product-codes>
<code id="111">carburetor choke valve</code>
<code id="112">carburettor choke nut</code>
<code id="113">carburettor choke bolt</code>
<code id="114">carburettor choke screw</code>
<code id="115">carburettor choke spanner</code>
<code id="116">carburettor choke screw driver</code>
<code id="117">carburettor choke chisel</code>
<code id="118">carburettor choke hammer</code>
<code id="119">carburettor choke jack</code>
:
</product-codes>
</pre></div></div><div class="div2">
<h3><a name="data-3" id="data-3"></a>A.4 Hierarchical to Flat</h3><p>This sample data consists of two documents:</p><p>The first one is a 1GB document that contains tree structure of
<code>node</code> elements with <code>id</code> attributes. Each node has
exactly one <code>content</code> element. The <code>content</code> element is
the first child of a <code>node</code>. There are no <code>node</code> descendants of
a <code>content</code> element.</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<tree>
<node id="id1">
<content>...</content>
<node id="id2">
<content>...</content>
:
</node>
<node id="id3">
<content>...</content>
:
</node>
:
</node>
</tree>
</pre></div><p>The second document is a 1GB document that contains flat structure of
<code>node</code> elements with <code>id</code> attributes, and additional
<code>parent</code> and <code>preceding-sibling</code> attributes that keep
information about a hierarchical structure of the first document.</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<nodes>
<node id="id1" parent="ROOT">
<content>.....</content>
</node>
<node id="id2" parent="id1" preceding-sibling="">
<content>.....</content>
</node>
<node id="id3" parent="id1" preceding-sibling="id2">
<content>.....</content>
</node>
:
</nodes>
</pre></div></div><div class="div2">
<h3><a name="data-4" id="data-4"></a>A.5 Rows and Columns</h3><p>This 1GB sample document contains multiple <code>row</code>
elements with <code>col</code> children.</p><div class="exampleInner"><pre>
<?xml version="1.0"?>
<table>
<row>
<col>aa</col>
<col>ab</col>
<col>ac</col>
:
</row>
<row>
<col>ba</col>
<col>bb</col>
<col>bc</col>
:
</row>
:
</table>
</pre></div></div><div class="div2">
<h3><a name="data-transactions" id="data-transactions"></a>A.6 Transactions and Balance</h3><p>The input XML document has this structure:</p><div class="exampleInner"><pre>
<transactions>
<transaction date="2008-09-01" value="12.00"/>
<transaction date="2008-09-01" value="8.00"/>
<transaction date="2008-09-02" value="-2.00"/>
<transaction date="2008-09-02" value="5.00"/>
<transaction date="2008-09-03" value="6.00"/>
<transaction date="2008-09-04" value="-3.00"/>
:
</transactions>
</pre></div><p>The required output structure is:</p><div class="exampleInner"><pre>
<account>
<balance date="2008-09-01" value="12.00"/>
<balance date="2008-09-01" value="20.00"/>
<balance date="2008-09-02" value="18.00"/>
<balance date="2008-09-02" value="23.00"/>
<balance date="2008-09-03" value="29.00"/>
<balance date="2008-09-04" value="26.00"/>
:
</account>
</pre></div></div><div class="div2">
<h3><a name="data-windowing" id="data-windowing"></a>A.7 Explicit Sections</h3><p>The input XML document:</p><div class="exampleInner"><pre>
<body>
<h2>heading1</h2>
<p>para1</p>
<p>para2</p>
<h2>heading2</h2>
<p>para3</p>
<p>para4</p>
<p>para5</p>
</body>
</pre></div><p>The expected result is:</p><div class="exampleInner"><pre>
<chapter>
<section title="heading1">
<para>para1</para>
<para>para2</para>
<para>heading2</para>
</section>
<section title="heading2">
<para>para3</para>
<para>para4</para>
<para>para5</para>
</section>
</chapter>
</pre></div></div></div><div class="div1">
<h2><a name="references" id="references"></a>B References</h2><dl><dt class="label"><a name="xslt20" id="xslt20"></a>XSL Transformations (XSLT) Version 2.0</dt><dd>
W3C
<cite>XSL Transformations (XSLT) Version 2.0</cite>
W3C Recommendation
See <a href="http://www.w3.org/TR/xslt20/">http://www.w3.org/TR/xslt20/</a>.</dd><dt class="label"><a name="xslt21" id="xslt21"></a>XSL Transformations (XSLT) Version 2.1</dt><dd>
W3C
<cite>XSL Transformations (XSLT) Version 2.1</cite>
W3C Working Draft
See <a href="http://www.w3.org/TR/xslt-21/">http://www.w3.org/TR/xslt-21/</a>.</dd><dt class="label"><a name="xpath11-functions" id="xpath11-functions"></a>XPath and XQuery Functions and Operators 1.1</dt><dd>
W3C
<cite>XPath and XQuery Functions and Operators 1.1</cite>
W3C Working Draft
See <a href="http://www.w3.org/TR/xpath-functions-11/">http://www.w3.org/TR/xpath-functions-11/</a>.</dd><dt class="label"><a name="xquery11-use-cases" id="xquery11-use-cases"></a>XQuery 1.1 Use Cases</dt><dd>
W3C
<cite>XQuery 1.1 Use Cases</cite>
W3C Working Draft
See <a href="http://www.w3.org/TR/xquery-11-use-cases/">http://www.w3.org/TR/xquery-11-use-cases/</a>.</dd><dt class="label"><a name="iso-21000-7" id="iso-21000-7"></a>ISO/IEC 21000-7:2004</dt><dd>
ISO/IEC
<cite>MPEG-21 -- Part 7: Digital Item Adaptation</cite>
ISO Standard
See <a href="http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=37379">http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=37379</a>.</dd><dt class="label"><a name="bsdl-content-adaptation" id="bsdl-content-adaptation"></a>BSDL: Application of Content Adaptation</dt><dd>
Myriam Amielh, Sylvain Devillers
<cite>Bitstream Syntax Description Language:
Application of XML-Schema to Multimedia Content Adaptation</cite>
See <a href="http://www2002.org/CDROM/alternate/334/">http://www2002.org/CDROM/alternate/334/</a>.</dd><dt class="label"><a name="xml-signature" id="xml-signature"></a>XML Signature</dt><dd>
W3C
<cite>XML-Signature Syntax and Processing</cite>
W3C Recommendation
See <a href="http://www.w3.org/TR/xmldsig-core/">http://www.w3.org/TR/xmldsig-core/</a>.</dd><dt class="label"><a name="lu" id="lu"></a>Streaming Validation for Digital Signatures</dt><dd>
Wei Lu, Kenneth Chiu, Aleksander Slominski and Dennis Gannon
<cite>A Streaming Validation Model for SOAP Digital Signature</cite>
See <a href="http://www.cs.indiana.edu/~welu/c14n_hpdc05.pdf">http://www.cs.indiana.edu/~welu/c14n_hpdc05.pdf</a>.</dd><dt class="label"><a name="mobile-blogging" id="mobile-blogging"></a>Plug-in Based Architecture for Mobile Blogging</dt><dd>
César Zapata, Christoffer Jakobsen
<cite>Feasibility Study of a Plug-in Based Architecture for Mobile Blogging</cite>
Master Thesis, Jönköping University
See <a href="http://www.diva-portal.org/hj/abstract.xsql?dbid=989">http://www.diva-portal.org/hj/abstract.xsql?dbid=989</a>.</dd><dt class="label"><a name="becker" id="becker"></a>Transforming XML on the Fly</dt><dd>
Oliver Becker
<cite>Transforming XML on the Fly</cite>
XML Europe 2003
See <a href="http://www.idealliance.org/papers/dx_xmle03/papers/04-02-02/04-02-02.html">http://www.idealliance.org/papers/dx_xmle03/papers/04-02-02/04-02-02.html</a>.</dd></dl></div></div></body></html>