One way would be to do the search in Lua; when you have multiple searches to perform, that may be the easiest way to go. For example: \startxmlsetups xml:test \xmlsetsetup{#1}{*}{-} \xmlsetsetup{#1}{doc|element}{xml:*} \stopxmlsetups \xmlregisterdocumentsetup{test}{xml:test} \startxmlsetups xml:doc \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:element \xmlfunction {#1} {element} \stopxmlsetups \startluacode function xml.functions.element (t) if t.at.class and t.at.class:find ("abc") then context.startcolor { "blue" } lxml.flush (t) context.stopcolor () else context.startcolor { "red" } lxml.flush (t) context.stopcolor () end end \stopluacode \startbuffer[test] <?xml version="1.0" encoding="UTF-8"?> <doc> <element class="abcdefg">Yes</element> <element>No</element> </doc> \stopbuffer \starttext \xmlprocessbuffer{test}{test}{} \stoptext Hope that gets you started. Thomas
On 24. Aug 2023, at 16:11, denis.maier@unibe.ch wrote:
Hi, I’m trying to check whether an attribute contains (or, actually starts with) a given string. I’ve tried a whole bunch of different combinations, but I’ve had no luck so far. Minimal example below. Anyone has a hint? Best, Denis %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \startxmlsetups xml:test \xmlsetsetup{#1}{*}{-} \xmlsetsetup{#1}{doc|element}{xml:*} \stopxmlsetups \xmlregisterdocumentsetup{test}{xml:test} \startxmlsetups xml:doc \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:element \xmlfilter{#1}{./find(attribute('class'), 'abc')/command(xml:whatever)} \xmldoifelse{#1}{./attribute('class')/contains('abc')} {Yes}{No} \stopxmlsetups \startxmlsetups xml:whatever Yes \stopxmlsetups \startbuffer[test] <?xml version="1.0" encoding="UTF-8"?> <doc> <element class="abcdefg">Yes</element> <element>No</element> </doc> \stopbuffer \starttext \xmlprocessbuffer{test}{test}{} \stoptext