On Feb 21, 2011, at 11:37 PM, Hans Hagen wrote: > On 21-2-2011 8:11, Thomas Schmitz wrote: >> Hi all, >> >> this must be easy, but I don't find the solution. Given an xml structure >> like this: >> >> <X> >> <A>dog</A> >> <A><B>cat</B></A> >> <A><B>mouse</B></A> >> </X> >> >> which \xmlfilter expression do I need to get the first <A> element which >> has a subelement <B>? I.e., the filter should only return "cat," not >> "dog" or "mouse." There can be 0 or more elements without <B> before and >> after the one I want to retrieve. >> >> Sorry if this is elementary, but I looked at xml-mkiv.pdf and mk.pdf and >> couldn't find an answer. > > "A/B[1]" > Sorry, I guess I wasn't clear enough. Here's a fuller example:
\startbuffer[test] <A> <B>cat</B> <B><C>dog</C></B> <B><C>mouse</C></B> <B><C>donkey</C></B> <B>giraffe</B> </A> \stopbuffer \startxmlsetups xml:testsetups \xmlsetsetup{\xmldocument}{A|B|C}{xml:*} \stopxmlsetups \xmlregistersetup{xml:testsetups} \startxmlsetups xml:A \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:B \xmlfilter{#1}{/C[1]/command(xml:C:first)} \stopxmlsetups \startxmlsetups xml:C:first \color[red]{\xmlflush{#1}} \stopxmlsetups \startxmlsetups xml:C \xmlflush{#1} \stopxmlsetups \starttext \xmlprocessbuffer{main}{test}{} \stoptext Suppose I want the first <A><B> subelement in red, all the other <A><B> subelements in blue? Right now, I get all the B's in red. Thanks, as always Thomas ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________