* filter contents of xml elements
@ 2009-10-28 15:17 Jelle Huisman
2009-10-28 15:32 ` Taco Hoekwater
0 siblings, 1 reply; 6+ messages in thread
From: Jelle Huisman @ 2009-10-28 15:17 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: filter contents of xml elements
2009-10-28 15:17 filter contents of xml elements Jelle Huisman
@ 2009-10-28 15:32 ` Taco Hoekwater
2009-10-28 15:33 ` Taco Hoekwater
2009-10-28 15:50 ` Jelle Huisman
0 siblings, 2 replies; 6+ messages in thread
From: Taco Hoekwater @ 2009-10-28 15:32 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
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] 6+ messages in thread
* Re: filter contents of xml elements
2009-10-28 15:32 ` Taco Hoekwater
@ 2009-10-28 15:33 ` Taco Hoekwater
2009-10-28 15:50 ` Jelle Huisman
1 sibling, 0 replies; 6+ messages in thread
From: Taco Hoekwater @ 2009-10-28 15:33 UTC (permalink / raw)
To: mailing list for ConTeXt users
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.
___________________________________________________________________________________
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] 6+ messages in thread
* Re: filter contents of xml elements
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
1 sibling, 1 reply; 6+ messages in thread
From: Jelle Huisman @ 2009-10-28 15:50 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
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] 6+ messages in thread
* Re: filter contents of xml elements
2009-10-28 15:50 ` Jelle Huisman
@ 2009-10-28 16:54 ` Hans Hagen
2009-10-28 17:16 ` Jelle Huisman
0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2009-10-28 16:54 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
-----------------------------------------------------------------
___________________________________________________________________________________
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] 6+ messages in thread
* Re: filter contents of xml elements
2009-10-28 16:54 ` Hans Hagen
@ 2009-10-28 17:16 ` Jelle Huisman
0 siblings, 0 replies; 6+ messages in thread
From: Jelle Huisman @ 2009-10-28 17:16 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
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] 6+ messages in thread
end of thread, other threads:[~2009-10-28 17:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-28 15:17 filter contents of xml elements Jelle Huisman
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
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).