From: "Thomas A. Schmitz" <thomas.schmitz@uni-bonn.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: filtering xml
Date: Tue, 22 Feb 2011 08:34:59 +0100 [thread overview]
Message-ID: <4B867345-2129-4D86-A8E1-2CBF7DD53469@uni-bonn.de> (raw)
In-Reply-To: <4D62E943.1090107@wxs.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
___________________________________________________________________________________
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
___________________________________________________________________________________
next prev parent reply other threads:[~2011-02-22 7:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-21 19:11 Thomas Schmitz
2011-02-21 22:37 ` Hans Hagen
2011-02-22 7:34 ` Thomas A. Schmitz [this message]
2011-02-22 8:59 ` Hans Hagen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B867345-2129-4D86-A8E1-2CBF7DD53469@uni-bonn.de \
--to=thomas.schmitz@uni-bonn.de \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).