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\unexpanded\def\xmlresetsorter #1{\ctxlxml{sorters.reset("#1")}}
26\unexpanded\def\xmladdsortentry#1#2#3{\ctxlxml{sorters.add("#1","#2",\!!bs#3\!!es)}}
27\unexpanded\def\xmlshowsorter #1{\ctxlxml{sorters.show("#1")}}
28 \def\xmlflushsorter #1#2{\ctxlxml{sorters.flush("#1","#2")}}
29\unexpanded\def\xmlsortentries #1{\ctxlxml{sorters.sort("#1")}}
30
31\protect \endinput
32
33\startbuffer[test]
34<demo>
35 <entry>
36 <category>one<category>
37 <key>alpha<key>
38 <content>alpha indeed<content>
39 <entry>
40 <entry>
41 <category>one<category>
42 <key>gamma<key>
43 <content>gamma indeed<content>
44 <entry>
45 <entry>
46 <category>one<category>
47 <key>beta<key>
48 <content>beta indeed<content>
49 <entry>
50 <entry>
51 <category>two<category>
52 <key>alpha<key>
53 <content>alpha again<content>
54 <entry>
55 <entry>
56 <category>two<category>
57 <key>gamma<key>
58 <content>gamma again<content>
59 <entry>
60 <entry>
61 <category>two<category>
62 <key>beta<key>
63 <content>beta again<content>
64 <entry>
65<demo>
66\stopbuffer
67
68\startxmlsetups xml:mysetups
69 \xmlsetsetup{\xmldocument}{demoentrycontent}{xml:*}
70\stopxmlsetups
71
72\xmlregistersetup{xml:mysetups}
73
74\startxmlsetups xml:demo
75 \xmlresetsorter{demo}
76 \xmlfilter{#1}{entrycommand(xml:entry:getkeys)}
77 \blank sortkeys: \blank\xmlshowsorter{demo}\blank
78 \xmlsortentries{demo}
79 \xmlflushsorter{demo}{xml:entry:flush}
80\stopxmlsetups
81
82\startxmlsetups xml:entry:getkeys
83 \xmladdsortentry{demo}{#1}{\xmltext{#1}{category}}
84 \xmladdsortentry{demo}{#1}{\xmltext{#1}{keyentry}}
85\stopxmlsetups
86
87\startxmlsetups xml:entry:flush
88 \xmltext{#1}{content}\par
89\stopxmlsetups
90
91\startxmlsetups xml:entry
92 \xmltext{#1}{content}\par
93\stopxmlsetups
94
95\starttext
96 \xmlprocessbuffer{main}{test}{}
97\stoptext
98 |