Hi all, I thought I had done this and it was easy, but I can't find a solution: I want to test whether a xml tag has an attribute and vary the typeset content accordingly. There used to be \xmldoifelseempty, but that has been commented out (lxml-ini.mkiv). What else could I use? Here's a small test that shows what I'm trying to do: \startbuffer[test] <a> <b>some text</b> <b important="different">more text</b> </a> \stopbuffer \startxmlsetups xml:testsetups \xmlsetsetup{\xmldocument}{a|b}{xml:*} \stopxmlsetups \xmlregistersetup{xml:testsetups} \startxmlsetups xml:a \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:b \xmldoifelse{#1}{./[@important]} %\doifemptyelse{\expanded{\xmlatt{#1}{important}}} {\color[darkred]{NOTEMPTY: \xmlatt{#1}{important}}\par} {\color[darkblue]{EMPTY: \xmlflush{#1}\par}} \stopxmlsetups \starttext \xmlprocessbuffer{main}{test}{} \stoptext Hints appreciated! All best Thomas
On 13-12-2010 8:58, Thomas Schmitz wrote:
Hi all,
I thought I had done this and it was easy, but I can't find a solution: I want to test whether a xml tag has an attribute and vary the typeset content accordingly. There used to be \xmldoifelseempty, but that has been commented out (lxml-ini.mkiv). What else could I use? Here's a small test that shows what I'm trying to do:
\startbuffer[test] <a> <b>some text</b> <b important="different">more text</b> </a> \stopbuffer
\startxmlsetups xml:testsetups \xmlsetsetup{\xmldocument}{a|b}{xml:*} \stopxmlsetups
\xmlregistersetup{xml:testsetups}
\startxmlsetups xml:a \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:b \xmldoifelse{#1}{./[@important]} %\doifemptyelse{\expanded{\xmlatt{#1}{important}}}
something like this: \doifelse {\xmlatt{#1}{important}} {} { \color[darkblue]{EMPTY: \xmlflush{#1}} } { \color[darkred]{NOTEMPTY: \xmlatt{#1}{important}} } \par or (untested): \xmldoifelse{#1}{./[@important=='']) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hans, thanks a lot!
On Mon, 13 Dec 2010 21:17:23 +0100
Hans Hagen
something like this:
\doifelse {\xmlatt{#1}{important}} {} { \color[darkblue]{EMPTY: \xmlflush{#1}} } { \color[darkred]{NOTEMPTY: \xmlatt{#1}{important}} } \par Yes, this works!
or (untested): \xmldoifelse{#1}{./[@important==''])
This doesn't, for some reason. But I'm glad to see that my syntax wasn't too far off. Thanks a lot, and all best! Thomas
participants (2)
-
Hans Hagen
-
Thomas Schmitz