lxml-sor.mkxl /size: 2509 b    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=lxml-sor,
3%D        version=2009.08.24,
4%D          title=\CONTEXT\ \XML\ Support,
5%D       subtitle=Sorting,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D THIS IS VERY EXPERIMENTAL!
15
16\writestatus{loading}{ConTeXt XML Support / Sorting}
17
18\registerctxluafile{lxml-sor}{}
19
20\unprotect
21
22%D The flusher is unexpandable so that it can be used in tables (noalign
23%D interferences).
24
25% todo: public implementors
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}{demo|entry|content}{xml:*}
72\stopxmlsetups
73
74\xmlregistersetup{xml:mysetups}
75
76\startxmlsetups xml:demo
77    \xmlresetsorter{demo}
78    \xmlfilter{#1}{entry/command(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}{key|entry}}
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