ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Simon Pepping <spepping@scaprea.hobby.nl>
Subject: Re: DocBook probleempje
Date: Thu, 14 Feb 2002 23:13:23 +0100	[thread overview]
Message-ID: <20020214231323.A651@scaprea> (raw)
In-Reply-To: <5.1.0.14.1.20020213211323.035265d8@server-1>; from pragma@wxs.nl on Wed, Feb 13, 2002 at 09:15:45PM +0100

Hans,

This looks good. But it does not reproduce the order of the elements
right if one of the elements does not occur in the first row, but does
in one of the following: it comes last.

I think it is too ambitious to dynamically determine the order in such
cases. So I reworked your code for the case of a predetermined order.

% first pass, header

\unprotect

% when the element occurs, register it
\def\environmentSaveElement#1%
    {\defineXMLenvironmentsave[#1]
		{\@EA\gdef\csname used!#1\endcsname{1}} \donothing}

% if the element is used,
% typeset the TH cell and add element to the list of elements used
\def\showElementTH#1{%
	\@EA\ifx\csname used!#1\endcsname\relax\else
		\bTD#1\eTD
		\doglobal\addtocommalist{#1}\ElementsUsed
	\fi
}

\protect

% second pass, body

% typeset the TD cell
\def\showElementTD#1{\expanded{\bTD\XMLflush{#1}}\eTD}

% for each revision, first clean out all elements,
% then process the content, and finally typeset the saved elements
\def\doRevision#1%
   {\processcommacommand[\ElementsUsed]\XMLerase
    #1% process content
    \bTR\processcommacommand[\ElementsUsed]\showElementTD\eTR}

% save element
\def\saveElement#1{\defineXMLsave[#1]}

\defineXMLenvironmentsave[revhistory]
   {\bgroup}
   {% define element list
	\def\ElementList{revnumber,date,authorinitials,revremark,approved}
	% initialize elements used
    \gdef\ElementsUsed{}
	% define elements
    \processcommacommand[\ElementList]\environmentSaveElement
	% process content first pass
	\XMLflush{revhistory}
    \bTABLE
	% typeset header and construct the list of elements used;
	% the two-pass registration ensures
	% that the list of elements used
    % is in the same order as the element list
    \bTR\processcommacommand[\ElementList]\showElementTH\eTR
	% redefine revision and elements used
    \defineXMLargument[revision] \doRevision
	\processcommacommand[\ElementsUsed]\saveElement
	% process content second pass
    \XMLflush{revhistory}%
    \eTABLE
    \egroup}

\starttext
\startbuffer
<revhistory>
    <revision>
       <revnumber>0.06</revnumber>
       <date>2001-01-08</date>
       <revremark>
          Changed date format (YYYY-MM-DD)
       </revremark>
    </revision>
    <revision>
       <revnumber>0.07</revnumber>
       <date>2001-01-09</date>
       <authorinitials>gjf</authorinitials>
       <revremark>
          Changed date format (YYYY-MM-DD) again
       </revremark>
    </revision>
    <revision>
       <revnumber>0.08</revnumber>
       <authorinitials>gjf</authorinitials>
       <revremark>
          Changed date format (YYYY-MM-DD) once more
       </revremark>
    </revision>
</revhistory>
\stopbuffer

\processXMLbuffer

\stoptext

On Wed, Feb 13, 2002 at 09:15:45PM +0100, Hans Hagen wrote:
> I already gambled on you asking this:
> 
> % watch how we now redefine the #1 element to a saved one
> 
> \def\WhatAHackA#1%
>     {\defineXMLenvironmentsave[#1]
>        {\doglobal\addtocommalist{#1}\CrapList
>         \bTD#1\eTD\defineXMLsave[#1]}
>        \donothing}
> 
> % here we first erase them all, then save them when present, and finaly add 
> them to the table
> 
> \def\WhatAHackB#1%
>    {\bTR
>     \processcommacommand[\CrapList]\XMLerase
>     #1% sets content
>     \processcommacommand[\CrapList]\WhatAHackC
>     \eTR}
> 
> % a cell
> 
> \def\WhatAHackC#1%
>     {\expanded{\bTD\XMLflush{#1}}\eTD}
> 
> % a slightly different main macro
> 
> \defineXMLenvironmentsave[revhistory]
>    {\bgroup}
>    {\def\HackList{revnumber,date,revremark,authorinitials}
>     \gdef\CrapList{}
>     \defineXMLenvironment[revision] \donothing \donothing
>     \processcommacommand[\HackList]\WhatAHackA
>     \bTABLE
>     \bTR\XMLflush{revhistory}\eTR
>     \defineXMLargument[revision] \WhatAHackB
>     \XMLflush{revhistory}%
>     \eTABLE
>     \egroup}
> 
> % [still no aux file needed]
> 

Groeten, Simon

-- 
Simon Pepping
email: spepping@scaprea.hobby.nl


  reply	other threads:[~2002-02-14 22:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20020208220553.B384@scaprea>
2002-02-10 21:04 ` Hans Hagen
2002-02-11 21:15   ` Simon Pepping
2002-02-13 20:15     ` Hans Hagen
2002-02-14 22:13       ` Simon Pepping [this message]
2002-02-15  7:46         ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020214231323.A651@scaprea \
    --to=spepping@scaprea.hobby.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).