lxml-sor.mkiv /size: 2432 b    last modification: 2020-07-01 14:35
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
% the flusher is unexpandable so that it can be used in tables (noalign
23
% interferences)
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
}{
demo
|
entry
|
content
}{
xml
:
*
}
70
\stopxmlsetups
71 72
\xmlregistersetup
{
xml
:
mysetups
}
73 74
\startxmlsetups
xml
:
demo
75
\xmlresetsorter
{
demo
}
76
\xmlfilter
{
#
1
}{
entry
/
command
(
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
}{
key
|
entry
}}
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