ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Re: DocBook probleempje
       [not found] <20020208220553.B384@scaprea>
@ 2002-02-10 21:04 ` Hans Hagen
  2002-02-11 21:15   ` Simon Pepping
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2002-02-10 21:04 UTC (permalink / raw)
  Cc: ntg-context

Hi Simon,

Your problem can be solved in the following way: [i cc to teh list since it 
may be instructive]

% output=pdftex

% This is the first pass: add an \bTD .. \eTD (or \bTH .. eTH) entry

\def\WhatAHackA#1%
   {\defineXMLenvironmentsave[#1]
      {\bTD#1\eTD\defineXMLignore[#1]}
      \donothing}

% and this the second pass: actually typeset them

\def\WhatAHackB#1%
   {\defineXMLpickup[#1]
      \bTD
      \eTD}

% here we do the two passes (one can add an additional pass
% over the <revision> element, or even better: store the
% entries, and flush them when needed skipping empty elements)

\defineXMLenvironmentsave[revhistory]
    {\bgroup}
    {\def\HackList{revnumber,date,revremark,authorinitials}
     \defineXMLenvironment[revision] \donothing \donothing
     \processcommacommand[\HackList]\WhatAHackA
     \bTABLE
     \bTR\XMLflush{revhistory}\eTR
     \defineXMLpickup[revision] \bTR \eTR
     \processcommacommand[\HackList]\WhatAHackB
     \XMLflush{revhistory}
     \eTABLE
     \egroup}

% one could of course just name the \define...'s instead of a list, but the 
list is better when there are 100  possible entries
%
% \defineXMLenvironmentsave[revnumber]....
% \defineXMLenvironmentsave[...]

btw, a not yet finished but handy option is tex namespaces, which permits 
you to define element handlers at the outer level and swicht to a namespace 
when flushing a saved element;

i also have a system for building elements in mem, but yet unfinished

% The example:

\starttext

\startXMLdata
<revhistory>
    <revision>
       <revnumber>0.06</revnumber>
       <date>2001-01-08</date>
       <authorinitials>gjf</authorinitials>
        <revremark>
          Changed date format (YYYY-MM-DD)
       </revremark>
    </revision>
</revhistory>
\stopXMLdata

\startXMLdata
<revhistory>
    <revision>
       <revnumber>0.06</revnumber>
       <date>2001-01-08</date>
        <revremark>
          Changed date format (YYYY-MM-DD)
       </revremark>
    </revision>
</revhistory>
\stopXMLdata

\stoptext

At 10:05 PM 2/8/2002 +0100, you wrote:
>Hans,
>
>Hier nog een probleempje. De revhistory wil ik graag als een tabel
>weergeven. Maar er kunnen een groot aantal velden in voorkomen. Het
>liefst zou ik eerst kunnen kijken welke velden er voorkomen, en alleen
>die kolommen in de tabel opnemen. Dat is geen eenvoudige zaak, en
>vereist zeker meer dan één gang over de TeX file. Heb jij daar ideeen
>over?
>
><revhistory>
>    <revision>
>       <revnumber>0.06</revnumber>
>       <date>2001-01-08</date>
>       <authorinitials>gjf</authorinitials>
>        <revremark>
>          Changed date format (YYYY-MM-DD)
>       </revremark>
>    </revision>
>
>    <!-- Additional (*earlier*) revision histories go here -->
></revhistory>
>
>% revision history
>% I would like to modify the layout
>% it would be nice if we could inspect the table first;
>% not all columns need to be present
>\defineXMLenvironment[revhistory]
>         {\blank[medium]\bgroup\switchtobodyfont[small]
>         \midaligned{Revision History}
>         \midaligned\bgroup\bTABLE
>         % column headers
>         \bTR \bTD \bf Revision\eTD \bTD \bf Date\eTD \bTD \bf Remarks\eTD 
> \eTR
>         }
>         {\eTABLE
>         \egroup % end midaligned
>         \egroup % end switchtobodyfont
>         }
>\defineXMLpickup[revision]  \bTR \eTR
>\defineXMLpickup[revnumber] \bTD \eTD
>\defineXMLpickup[date]      \bTD \eTD
>\defineXMLpickup[revremark] \bTD \eTD
>
>Zoals het kommentaar al aangeeft heb ik ook geen goede dokumentatie
>kunnen vinden voor de \bTABLE ... \eTABLE konstruktie.
>
>Groeten, Simon
>
>--
>Simon Pepping
>email: spepping@scaprea.hobby.nl

-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                                   fall-back web server: 
www.pragma-pod.nl
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: DocBook probleempje
  2002-02-10 21:04 ` DocBook probleempje Hans Hagen
@ 2002-02-11 21:15   ` Simon Pepping
  2002-02-13 20:15     ` Hans Hagen
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Pepping @ 2002-02-11 21:15 UTC (permalink / raw)


On Sun, Feb 10, 2002 at 10:04:15PM +0100, Hans Hagen wrote:

First the problem in English:

I want to render the revhistory as a table. But it may have a large
range of fields. Preferably I would like to be able to see which
fields occur, and only include those columns.

This code works fine, and it teaches me that it is not necessary to
write to an auxiliary file. All data can be built in memory.

But I want more. The following is an appropriate test text. Each row
may show a different selection from the possible fields. And all rows
together may only use a subset of the set of possible fields. I only
want to include the fields actually used; so I do not want to show the
field authorinitials if that is not used in any of the rows.

<revhistory>
    <revision>
       <revnumber>0.06</revnumber>
       <date>2001-01-08</date>
       <authorinitials>gjf</authorinitials>
        <revremark>
          Changed date format (YYYY-MM-DD)
       </revremark>
    </revision>
    <revision>
       <revnumber>0.07</revnumber>
       <date>2001-01-09</date>
        <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>

> Hi Simon,
> 
> Your problem can be solved in the following way: [i cc to teh list since it 
> may be instructive]
> 
> % output=pdftex
> 
> % This is the first pass: add an \bTD .. \eTD (or \bTH .. eTH) entry
> 
> \def\WhatAHackA#1%
>    {\defineXMLenvironmentsave[#1]
>       {\bTD#1\eTD\defineXMLignore[#1]}
>       \donothing}
> 
> % and this the second pass: actually typeset them
> 
> \def\WhatAHackB#1%
>    {\defineXMLpickup[#1]
>       \bTD
>       \eTD}
> 
> % here we do the two passes (one can add an additional pass
> % over the <revision> element, or even better: store the
> % entries, and flush them when needed skipping empty elements)
> 
> \defineXMLenvironmentsave[revhistory]
>     {\bgroup}
>     {\def\HackList{revnumber,date,revremark,authorinitials}
>      \defineXMLenvironment[revision] \donothing \donothing
>      \processcommacommand[\HackList]\WhatAHackA
>      \bTABLE
>      \bTR\XMLflush{revhistory}\eTR
>      \defineXMLpickup[revision] \bTR \eTR
>      \processcommacommand[\HackList]\WhatAHackB
>      \XMLflush{revhistory}
>      \eTABLE
>      \egroup}
> 

Regards, Simon

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: DocBook probleempje
  2002-02-11 21:15   ` Simon Pepping
@ 2002-02-13 20:15     ` Hans Hagen
  2002-02-14 22:13       ` Simon Pepping
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2002-02-13 20:15 UTC (permalink / raw)
  Cc: ntg-context

At 10:15 PM 2/11/2002 +0100, you wrote:
>On Sun, Feb 10, 2002 at 10:04:15PM +0100, Hans Hagen wrote:
>
>First the problem in English:
>
>I want to render the revhistory as a table. But it may have a large
>range of fields. Preferably I would like to be able to see which
>fields occur, and only include those columns.
>
>This code works fine, and it teaches me that it is not necessary to
>write to an auxiliary file. All data can be built in memory.
>
>But I want more. The following is an appropriate test text. Each row
>may show a different selection from the possible fields. And all rows
>together may only use a subset of the set of possible fields. I only
>want to include the fields actually used; so I do not want to show the
>field authorinitials if that is not used in any of the rows.

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]

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                                   fall-back web server: 
www.pragma-pod.nl
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: DocBook probleempje
  2002-02-13 20:15     ` Hans Hagen
@ 2002-02-14 22:13       ` Simon Pepping
  2002-02-15  7:46         ` Hans Hagen
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Pepping @ 2002-02-14 22:13 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: DocBook probleempje
  2002-02-14 22:13       ` Simon Pepping
@ 2002-02-15  7:46         ` Hans Hagen
  0 siblings, 0 replies; 5+ messages in thread
From: Hans Hagen @ 2002-02-15  7:46 UTC (permalink / raw)
  Cc: ntg-context

At 11:13 PM 2/14/2002 +0100, Simon Pepping wrote:
>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
>}

There are \doifXMLdata and \doifelseXMLdata that can be used for that; 
saves hash entries and looks cleaner

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                                   fall-back web server: 
www.pragma-pod.nl
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-02-15  7:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20020208220553.B384@scaprea>
2002-02-10 21:04 ` DocBook probleempje Hans Hagen
2002-02-11 21:15   ` Simon Pepping
2002-02-13 20:15     ` Hans Hagen
2002-02-14 22:13       ` Simon Pepping
2002-02-15  7:46         ` Hans Hagen

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).