[NTG-context] index: xml in mkiv

Jano Kula jano.kula at tiscali.cz
Sat Sep 25 16:24:08 CEST 2010


Hello Hans,

just to remind the other issues. The code from xml-mkiv.pdf doesn't work 
as expected. Only in \TestMode=2 the index is rendered as supposed.

demo.tex + demo.xml below

Jano



%%%%%%%%%%
% demo.tex
\newcount\TestMode
\TestMode=0 % expansion=xml
%\TestMode=1 % expansion=yes, index, setup
%\TestMode=2 % expansion=yes

\startxmlsetups xml:mysetups
   \xmlsetsetup{\xmldocument}{demo|index|content|chapter|title|em}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:mysetups}

% main document
\startxmlsetups xml:demo
   \xmlflush{#1}
   \subject{contents}
   \placelist[chapter][criterium=all]
   \subject{index}
   \placeregister[index][criterium=all]
   \page % else buffer is forgotten when placing header
\stopxmlsetups


\startxmlsetups xml:chapter
   \ifcase \TestMode
     % xml code travels around
     \setuphead[chapter][expansion=xml]
     \startchapter[title=eh: \xmltext{#1}{title}]
   \or
     % index is used for access via setup
     \setuphead[chapter][expansion=yes,xmlsetup=xml:title:flush]
     \startchapter[title=\xmlgetindex{#1}]
   \or
     % tex call to xml using index is used
     \setuphead[chapter][expansion=yes]
     \startchapter[title=hm: \xmlreference{#1}{xml:title:flush}]
   \fi
   \xmlfirst{#1}{content}
   \stopchapter
\stopxmlsetups

\startxmlsetups xml:title:flush
   \xmltext{#1}{title}
\stopxmlsetups

% We need to deal with emphasis and the content of the chapter.
\startxmlsetups xml:em
   \begingroup\em\xmlflush{#1}\endgroup
\stopxmlsetups

\startxmlsetups xml:content
   \xmlflush{#1}
\stopxmlsetups


%A similar approach is followed with the index entries. Watch how we use 
the numbered entries variant (in this case we could also have used just 
entries and keys.
\startxmlsetups xml:index
   \ifcase \TestMode
     \setupregister[index][expansion=xml,xmlsetup=]
     \setstructurepageregister
       [index]
       [entries:1=\xmlfirst{#1}{content},
       keys:1=\xmltext{#1}{key}]
   \or
     \setupregister[index][expansion=yes,xmlsetup=xml:index:flush]
     \setstructurepageregister
       [index]
       [entries:1=\xmlgetindex{#1},
       keys:1=\xmltext{#1}{key}]
   \or
     \setupregister[index][expansion=yes,xmlsetup=]
     \setstructurepageregister
       [index]
       [entries:1=\xmlreference{#1}{xml:index:flush},
       keys:1=\xmltext{#1}{key}]
   \fi
\stopxmlsetups

\startxmlsetups xml:index:flush
   \xmlfirst{#1}{content}
\stopxmlsetups


% The file is processed by:
\starttext
   \xmlprocessfile{main}{demo.xml}{}
\stoptext


% additional control
%\startxmlsetups xml:ctx:sectionentry
%\xmlflush{#1}
%\stopxmlsetups
%\startxmlsetups xml:ctx:registerentry
%\xmlflush{#1}
%\stopxmlsetups


%%%%%%%%%%
% demo.xml
<?xml version='1.0' ?>
<demo>
<chapter>
<title>Some <em>short</em> title</title>
<content>
zeta
<index>
<key>zeta</key>
<content>zeta again</content>
</index>
alpha
<index>
<key>alpha</key>
<content>alpha <em>again</em></content>
</index>
gamma
<index>
<key>gamma</key>
<content>gamma</content>
</index>
beta
<index>
<key>beta</key>
<content>beta</content>
</index>
delta
<index>
<key>delta</key>
<content>delta</content>
</index>
done!
</content>
</chapter>
</demo>





More information about the ntg-context mailing list