1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16\writestatus{loading}{ConTeXt XML Support Sorting}
17
18\registerctxluafile{lxmlsor}{}
19
20\unprotect
21
22
23
24
25
26
27\permanent\protected\def\xmlresetsorter #1{\ctxlxml{sorters.reset("#1")}}
28\permanent\protected\def\xmladdsortentry#1#2#3{\ctxlxml{sorters.add("#1","#2",\!!bs#3\!!es)}}
29\permanent\protected\def\xmlshowsorter #1{\ctxlxml{sorters.show("#1")}}
30\permanent \def\xmlflushsorter #1#2{\ctxlxml{sorters.flush("#1","#2")}}
31\permanent\protected\def\xmlsortentries #1{\ctxlxml{sorters.sort("#1")}}
32
33\protect \endinput
34
35\startbuffer[test]
36<demo>
37 <entry>
38 <category>one<category>
39 <key>alpha<key>
40 <content>alpha indeed<content>
41 <entry>
42 <entry>
43 <category>one<category>
44 <key>gamma<key>
45 <content>gamma indeed<content>
46 <entry>
47 <entry>
48 <category>one<category>
49 <key>beta<key>
50 <content>beta indeed<content>
51 <entry>
52 <entry>
53 <category>two<category>
54 <key>alpha<key>
55 <content>alpha again<content>
56 <entry>
57 <entry>
58 <category>two<category>
59 <key>gamma<key>
60 <content>gamma again<content>
61 <entry>
62 <entry>
63 <category>two<category>
64 <key>beta<key>
65 <content>beta again<content>
66 <entry>
67<demo>
68\stopbuffer
69
70\startxmlsetups xml:mysetups
71 \xmlsetsetup{\xmldocument}{demoentrycontent}{xml:*}
72\stopxmlsetups
73
74\xmlregistersetup{xml:mysetups}
75
76\startxmlsetups xml:demo
77 \xmlresetsorter{demo}
78 \xmlfilter{#1}{entrycommand(xml:entry:getkeys)}
79 \blank sortkeys: \blank\xmlshowsorter{demo}\blank
80 \xmlsortentries{demo}
81 \xmlflushsorter{demo}{xml:entry:flush}
82\stopxmlsetups
83
84\startxmlsetups xml:entry:getkeys
85 \xmladdsortentry{demo}{#1}{\xmltext{#1}{category}}
86 \xmladdsortentry{demo}{#1}{\xmltext{#1}{keyentry}}
87\stopxmlsetups
88
89\startxmlsetups xml:entry:flush
90 \xmltext{#1}{content}\par
91\stopxmlsetups
92
93\startxmlsetups xml:entry
94 \xmltext{#1}{content}\par
95\stopxmlsetups
96
97\starttext
98 \xmlprocessbuffer{main}{test}{}
99\stoptext
100 |