From: Jelle Huisman <jelle@jhnet.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: filter contents of xml elements
Date: Wed, 28 Oct 2009 15:17:53 +0000 [thread overview]
Message-ID: <4AE860A1.9000200@jhnet.nl> (raw)
Hi all,
First of all a big thank you to Hans for MkIV xml support which is so
much easier to understand than the MKII based method (or is that just
me?) Anyway, I'm processing a rather messy html file and I would like to
do some conditional processing based on the actual content of the
element. See example below: I have linked <h3> with \subject but I would
like to drop this element if the content of the element matches 'Skip
title'.
Any hints? Thanks!
Jelle
\startbuffer[test]
<html>
<h3>Title 1</h3>
<p>Hello world.</p>
<h3>Skip title</h3>
<p>Hello world!</p>
<h3>Title 2</h3>
<p>Hello world?</p>
<h3>Title 3</h3>
<p>Hello :-)</p>
</html>
\stopbuffer
\startxmlsetups xml:setups
\xmlsetsetup{main}{html|h3|p}{xml:*}
\stopxmlsetups
\xmlregistersetup{xml:setups}
\startxmlsetups xml:html
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:h3
\subject{\xmlflush{#1}} % but drop this if content of element is
'Skip Title'
\stopxmlsetups
\startxmlsetups xml:p
\xmlflush{#1}\par
\stopxmlsetups
\starttext
\xmlprocessbuffer{main}{test}{}
\stoptext
Expected outcome:
Title 1
Hello world.
Hello world!
Title 2
Hello world?
Title 3
Hello :-)
___________________________________________________________________________________
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 reply other threads:[~2009-10-28 15:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-28 15:17 Jelle Huisman [this message]
2009-10-28 15:32 ` Taco Hoekwater
2009-10-28 15:33 ` Taco Hoekwater
2009-10-28 15:50 ` Jelle Huisman
2009-10-28 16:54 ` Hans Hagen
2009-10-28 17:16 ` Jelle Huisman
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=4AE860A1.9000200@jhnet.nl \
--to=jelle@jhnet.nl \
--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).