ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* filtering xml
@ 2011-02-21 19:11 Thomas Schmitz
  2011-02-21 22:37 ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Schmitz @ 2011-02-21 19:11 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: filtering xml
  2011-02-21 19:11 filtering xml Thomas Schmitz
@ 2011-02-21 22:37 ` Hans Hagen
  2011-02-22  7:34   ` Thomas A. Schmitz
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2011-02-21 22:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Thomas Schmitz

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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: filtering xml
  2011-02-21 22:37 ` Hans Hagen
@ 2011-02-22  7:34   ` Thomas A. Schmitz
  2011-02-22  8:59     ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas A. Schmitz @ 2011-02-22  7:34 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: filtering xml
  2011-02-22  7:34   ` Thomas A. Schmitz
@ 2011-02-22  8:59     ` Hans Hagen
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2011-02-22  8:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Thomas A. Schmitz

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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-22  8:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-21 19:11 filtering xml Thomas Schmitz
2011-02-21 22:37 ` Hans Hagen
2011-02-22  7:34   ` Thomas A. Schmitz
2011-02-22  8:59     ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).