x-xfdf.mkiv /size: 2002 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=x-xfdf,
3%D        version=2011.09.07,
4%D          title=\CONTEXT\ XML Modules,
5%D       subtitle=\XFDF,
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 a revival of using \XFDF, but now in a more \MKIV-ish way. We
15%D supported it long ago already in \MKII\ but never used it at a large
16%D scale (not that much user interest anyway).
17
18\startmodule[xfdf]
19
20% see xfdf-001.xfdf and xfdf-001.tex
21
22% %D Possible speedup but hardly worth the trouble.
23%
24% \startluacode
25%
26%     local hashes = { } table.setmetatableindex(hashes,function(t,k) local v = { } t[k] = v return v end)
27%
28%     function xml.functions.xfdf_collect_values(root)
29%         local hash = hashes[root]
30%         for c in xml.collected(root,"/xfdf/fields/field/value") do
31%             hash[xml.parent(c).at.name] = c
32%         end
33%     end
34%
35%     function xml.functions.xfdf_get_values(root,name)
36%         return hashes[root][name]
37%     end
38%
39%     function lxml.xfdf_get_values(root,name)
40%         xml.sprint(hashes[lxml.id(root)][name])
41%     end
42%
43% \stopluacode
44%
45% \def\xfdfvalue#1#2%
46%   {\ctxlua{lxml.xfdf_get_values("#1","#2")}}
47
48\startxmlsetups xfdf:define
49    \xmlsetsetup{#1}{*}{xfdf:*}
50  % \xmlfilter  {#1}{./function(xfdf_collect_values)}
51\stopxmlsetups
52
53\xmlregisterns{xfdf}{http://ns.adobe.com/xfdf/}
54
55\xmlregisterdocumentsetup{xfdf}{xfdf:define}
56
57\startxmlsetups xfdf:value
58    \xmlflush{#1}
59\stopxmlsetups
60
61\def\xfdfload #1#2{\xmlloadonly{#1}{#2}{xfdf}}
62\def\xfdfvalue#1#2{\xmlfirst{#1}{/xfdf/fields/field[@name='#2']/value}}
63\def\xfdftext #1#2{\xmlfirst{#1}{/xfdf/fields/field[@name='#2']/value/paragraphs()}}
64
65% \startxmlsetups xfdf:b
66%     \bold{\xmlflush{#1}}
67% \stopxmlsetups
68
69% \xfdfload {whatever}{xfdf-001.xfdf}
70% \xfdfvalue{whatever}{somefield}
71
72\stopmodule
73