![](https://secure.gravatar.com/avatar/532990f0c5a8331f60e3d0e1173292a6.jpg?s=120&d=mm&r=g)
Ok, I've found a way, see below.
But maybe someone has some nice lua (or other) tricks to share... (I'm not sure accessing t.dt[1] is particularly safe when operating on nested structures.)
Best,
Denis
\startbuffer[test]
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<chapter>
<title>A short title</title>
<p>asdf asdf asdf jklö jklö jklö</p>
</chapter>
<chapter>
<title>A longer title bla bla bla bla bla bla bla bla</title>
<p>
asdf asdf asdf jklö jklö jklö
</p>
</chapter>
</doc>
\stopbuffer
\startxmlsetups xml:test
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{doc|chapter|p}{xml:*}
\stopxmlsetups
\xmlregisterdocumentsetup{test}{xml:test}
\startxmlsetups xml:doc
\xmlflush{#1}
\stopxmlsetups
\setuphead[chapter][expansion=yes] % make sure the stuff gets expanded on time
\startxmlsetups xml:chapter
\startchapter
[
title={\xmlfilter{#1}{/title/command(xml:chapter:title)}},
marking={\xmlfilter{#1}{/title/command(xml:chapter:title:marking)}},
]
\xmlflush{#1}
\stopchapter
\stopxmlsetups
\startxmlsetups xml:p
\xmlflush{#1}\par
\stopxmlsetups
\startluacode
function xml.functions.getMarking(t)
_,n = t.dt[1]:gsub("%S+","")
if n > 10 then
local words = {}
for word in t.dt[1]:gmatch("%S+") do table.insert(words, word) end
local resWords = {}
resWords = { unpack( words, 1, 7 ) }
res = table.concat(resWords, " ") .. " ..."
else
res = t.dt[1]
end
context(res)
end
\stopluacode
\startxmlsetups xml:chapter:title:marking
\xmlfunction{#1}{getMarking}
\stopxmlsetups
\startxmlsetups xml:chapter:title
\xmlflush{#1}
\stopxmlsetups
\setupheadertexts[chapter]
\starttext
\xmlprocessbuffer{test}{test}{}
\stoptext
Von: denis.maier@unibe.ch