From jelle@jhnet.nl Wed Oct 28 16:16:46 2009 From: Jelle Huisman To: ntg-context@ntg.nl Subject: [NTG-context] filter contents of xml elements Date: Wed, 28 Oct 2009 15:17:53 +0000 Message-ID: <4AE860A1.9000200@jhnet.nl> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7049789465071062216==" --===============7049789465071062216== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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

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]

Title 1

Hello world.

Skip title

Hello world!

Title 2

Hello world?

Title 3

Hello :-)

\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 :-) --===============7049789465071062216==-- From taco@elvenkind.com Wed Oct 28 16:31:30 2009 From: Taco Hoekwater To: ntg-context@ntg.nl Subject: Re: [NTG-context] filter contents of xml elements Date: Wed, 28 Oct 2009 16:32:41 +0100 Message-ID: <4AE86419.7060401@elvenkind.com> In-Reply-To: <4AE860A1.9000200@jhnet.nl> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8117352150622521349==" --===============8117352150622521349== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Jelle Huisman wrote: > Any hints? Thanks! The next does not deserve a price for elegance, but because \xmlflush is expandable (this is its best feature, I think!) you can use the traditional tex toolkit macros: \startxmlsetups xml:h3 \doifinstringelse{Skip title}{\xmlflush{#1}} {} {\subject{\xmlflush{#1}}} \stopxmlsetups I'm fairly certain that there are nicer solutions, however. Best wishes, Taco --===============8117352150622521349==-- From taco@elvenkind.com Wed Oct 28 16:32:27 2009 From: Taco Hoekwater To: ntg-context@ntg.nl Subject: Re: [NTG-context] filter contents of xml elements Date: Wed, 28 Oct 2009 16:33:39 +0100 Message-ID: <4AE86453.1040707@elvenkind.com> In-Reply-To: <4AE86419.7060401@elvenkind.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0581275371325738424==" --===============0581275371325738424== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Taco Hoekwater wrote: > > Jelle Huisman wrote: >> Any hints? Thanks! > > The next does not deserve a price for elegance, but because Hm, and that should have been prize, not price. --===============0581275371325738424==-- From jelle@jhnet.nl Wed Oct 28 16:49:10 2009 From: Jelle Huisman To: ntg-context@ntg.nl Subject: Re: [NTG-context] filter contents of xml elements Date: Wed, 28 Oct 2009 15:50:18 +0000 Message-ID: <4AE8683A.4040406@jhnet.nl> In-Reply-To: <4AE86419.7060401@elvenkind.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8423296804316101047==" --===============8423296804316101047== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On 28/10/2009 15:32, Taco Hoekwater wrote: > The next does not deserve a price for elegance, but because > \xmlflush is expandable (this is its best feature, I think!) > you can use the traditional tex toolkit macros: > > \startxmlsetups xml:h3 > \doifinstringelse{Skip title}{\xmlflush{#1}} > {} > {\subject{\xmlflush{#1}}} > \stopxmlsetups > > I'm fairly certain that there are nicer solutions, however. > Thanks Taco, this works, I owe you a beer at next year's ConTeXt meeting! I'm still interested in a 'proper' xml (= non-TeX) based solution, anyone? Jelle --===============8423296804316101047==-- From pragma@wxs.nl Wed Oct 28 17:53:53 2009 From: Hans Hagen To: ntg-context@ntg.nl Subject: Re: [NTG-context] filter contents of xml elements Date: Wed, 28 Oct 2009 17:54:57 +0100 Message-ID: <4AE87761.5010401@wxs.nl> In-Reply-To: <4AE8683A.4040406@jhnet.nl> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5240239149075762446==" --===============5240239149075762446== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Jelle Huisman wrote: > On 28/10/2009 15:32, Taco Hoekwater wrote: >> The next does not deserve a price for elegance, but because >> \xmlflush is expandable (this is its best feature, I think!) >> you can use the traditional tex toolkit macros: >> >> \startxmlsetups xml:h3 >> \doifinstringelse{Skip title}{\xmlflush{#1}} >> {} >> {\subject{\xmlflush{#1}}} >> \stopxmlsetups >> >> I'm fairly certain that there are nicer solutions, however. >> > > Thanks Taco, this works, I owe you a beer at next year's ConTeXt > meeting! I'm still interested in a 'proper' xml (= non-TeX) based > solution, anyone? \startxmlsetups xml:h3 \xmldoifnot {#1} {[text()='Skip title']} { \subject{\xmlflush{#1}} } \stopxmlsetups or: \xmlsetsetup {main} {h3[text()='Skip title']} {-} ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- --===============5240239149075762446==-- From jelle@jhnet.nl Wed Oct 28 18:15:35 2009 From: Jelle Huisman To: ntg-context@ntg.nl Subject: Re: [NTG-context] filter contents of xml elements Date: Wed, 28 Oct 2009 17:16:33 +0000 Message-ID: <4AE87C71.6080306@jhnet.nl> In-Reply-To: <4AE87761.5010401@wxs.nl> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7219071030429420061==" --===============7219071030429420061== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On 28/10/2009 16:54, Hans Hagen wrote: > \startxmlsetups xml:h3 > \xmldoifnot {#1} {[text()='Skip title']} { > \subject{\xmlflush{#1}} > } > \stopxmlsetups > > or: > > \xmlsetsetup {main} {h3[text()='Skip title']} {-} OK thanks, that's even better. Jelle --===============7219071030429420061==--