% !TEX TS-program = ConTeXt (LuaTeX 1.0.9)
% Copyright 2019 Axel Kielhorn
% Lizenz: CC-BY-SA 4.0 Unported http://creativecommons.org/licenses/by-sa/4.0/deed.de

% Usage:
% context --environment=prozess-style-ecm.tex prozess.xml

\startluacode
settings = {}
docstruktur = {}
doclistfile = "doclist.xml"

cropstring = function(string)
	return utilities.strings.striplines(string, "prune and collapse")
end

doc = xml.load(doclistfile, settings)

for v in xml.collected(doc,"/doclist/psdoc/") do
	print (v)
	print (xml.filter(v,"/docnr/text()"))
	docnr = (xml.filter(v,"/docnr/text()"))
	print (docnr)
	docname = (cropstring(xml.filter(v,"/docname/text()")))
	-- es kann mehrere DOCAN geben!
	docan = (cropstring(xml.filter(v,"/docan/text()")))
	docverantwortlich = (cropstring(xml.filter(v,"/docverantwortlich/text()")))
	docstruktur[docnr]={}
--	docstruktur[docnr]["docname"] = docname
--	docstruktur[docnr]["docan"] = docan
--	docstruktur[docnr]["docverantwortlich"] = docverantwortlich
end
\stopluacode

\language[de]
\setbreakpoints[compound]

\setuphyphenation[method=expanded]

\setuppapersize [A4,landscape][A4,landscape]
\setuplayout    [width=middle,  backspace=2in, cutspace=1in, leftmargin=1.5in,
                 height=middle, topspace=0.75in, bottomspace=0.75in]

\setuppagenumbering[location={footer,right}]

\setupheader[text][start]
\setupfooter[text][start]
%\setupheadertexts[][\date]

 \setupheadertexts[title][\date]
 \setuphead[title]
   [placehead=empty,
    before=,
    after=,
    page=,]

\startxmlsetups xml:prozessb
    \xmlsetsetup{#1}{*}{-}
    \xmlsetsetup{#1}{prozess|pschritt|psindoc|docan|psoutdoc|aschritt|eschritt}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:prozessb}

\startxmlsetups xml:prozess
  \title{\xmltext{#1}{/pnr} \xmltext{#1}{/pname}}
%  \setupheadertexts[\bf\xmltext{#1}{/pnr} \xmltext{#1}{/pname}][\date]
  {\bTABLE
    \setupTABLE[frame=off]
    \setupTABLE[offset=1mm]
    \setupTABLE[c][1][align=right, width=14cm]
    \setupTABLE[c][2][align=left,  width=6cm]
    \setupTABLE[c][3][align=right, width=4cm]
    \bTR \bTD \bfb\xmltext{#1}{/pnr}   \eTD \bTD Version:        \eTD \bTD \bf\xmltext{#1}{/pversion}\eTD \eTR
    \bTR \bTD \bfb\xmltext{#1}{/pname} \eTD \bTD Verantwortlich: \eTD \bTD \bf\xmltext{#1}{/pverantwortlich}\eTD\eTR
  \eTABLE}
  \blank
  \xmlflush{#1}
\stopxmlsetups
