[NTG-context] XML processing instructions

denis.maier at unibe.ch denis.maier at unibe.ch
Mon May 2 09:48:28 CEST 2022

That was too quick, sorry.

Hi Duncan,

I have used context’s own injectors for this :

<?context-directive injector addlinetopage ?>

\startsetups xml:directive:injector:addlinetopage

Or, for your line break example :

<?context-directive injector newline ?>

\startsetups xml:directive:injector:newline

Also, I have learned that you can just use arbitrary context code in xml:



         <?context-directive tex command \inframed{xxx} ?>
         <?context-directive tex command \page ?>
         <?context-directive tex command \crlf ?>


Von: Maier, Denis Christian (UB)
Gesendet: Montag, 2. Mai 2022 09:45
An: 'mailing list for ConTeXt users' <ntg-context at ntg.nl>
Cc: Duncan Hothersall <dh at capdm.com>
Betreff: AW: [NTG-context] XML processing instructions

Von: ntg-context <ntg-context-bounces at ntg.nl<mailto:ntg-context-bounces at ntg.nl>> Im Auftrag von Duncan Hothersall via ntg-context
Gesendet: Montag, 2. Mai 2022 09:20
An: mailing list for ConTeXt users <ntg-context at ntg.nl<mailto:ntg-context at ntg.nl>>
Cc: Duncan Hothersall <dh at capdm.com<mailto:dh at capdm.com>>
Betreff: [NTG-context] XML processing instructions

I have a big set of existing XML books (held in a derivative of DocBook) which I'm looking to start processing directly with ConTeXt. (Up to now I have a system which converts the XML into ConTeXt code which is then processed, but this is inefficient and lots of the code is now unsupported.)

I've had some success producing output, but my first real sticking point has come with processing instructions. The existing XML contains lots of processing instructions of the form
<?capdm whatever?>, some of which can be conditional and introduce new data etc. But I'd be happy at this stage if I could just process the most basic one of them, which is used to introduce a line stop in a running paragraph of text.

My best guess at how to do this was to use the lxml.preprocessor function to convert the processing instruction into an element, and then process the element as normal. But (a) my attempt didn't work, and (b) there may well be a better way.

Minimal working example below, except that obviously the processing instruction bit doesn't work!

Thanks for any help or insights.



  <para>A paragraph with<?capdm force_line_stop?>a processing instruction.</para>

\startxmlsetups xml:demo:base

\startxmlsetups xml:demo:book

\startxmlsetups xml:demo:para

 function lxml.preprocessor(data,settings)
  return string.find(data,"<?capdm *force_line_stop?>")
   and string.gsub(data,"<?capdm *force_line_stop?>","<capdmlinestop></capdmlinestop/>")
   or data

\startxmlsetups xml:demo:capdmlinestop


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20220502/b24e0984/attachment.htm>

More information about the ntg-context mailing list