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. Thanks Thomas
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]" ----------------------------------------------------------------- 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 -----------------------------------------------------------------
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
On 22-2-2011 8:34, Thomas A. Schmitz wrote:
xml blob
\xmlsetsetup{#1}{B/C/..[1]}{xml:C:first} select all B select all C in found B's select first in all found \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{#1}{A|B|C}{xml:*} \xmlsetsetup{#1}{B/C/..[1]}{xml:C:first} \stopxmlsetups \xmlregistersetup{xml:testsetups} \startxmlsetups xml:A \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:B \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:C:first \color[red]{\xmlflush{#1}} \stopxmlsetups \startxmlsetups xml:C \xmlflush{#1} \stopxmlsetups \starttext \xmlprocessbuffer{main}{test}{} \stoptext ----------------------------------------------------------------- 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 -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
Thomas A. Schmitz
-
Thomas Schmitz