ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* XML processing instructions
@ 2022-05-02  7:19 Duncan Hothersall via ntg-context
  2022-05-02  7:33 ` Duncan Hothersall via ntg-context
  2022-05-02  7:44 ` Denis Maier via ntg-context
  0 siblings, 2 replies; 12+ messages in thread
From: Duncan Hothersall via ntg-context @ 2022-05-02  7:19 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Duncan Hothersall


[-- Attachment #1.1: Type: text/plain, Size: 1887 bytes --]

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.

Duncan


MWE:
------

\startbuffer[demo]
<book>
  <para>A paragraph with<?capdm force_line_stop?>a processing
instruction.</para>
</book>
\stopbuffer

\startxmlsetups xml:demo:base
 \xmlsetsetup{#1}{*}{xml:demo:*}
\stopxmlsetups
\xmlregisterdocumentsetup{demo}{xml:demo:base}

\startxmlsetups xml:demo:book
 \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:demo:para
 \xmlflush{#1}\endgraf
\stopxmlsetups

\startluacode
 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
 end
\stopluacode

\startxmlsetups xml:demo:capdmlinestop
 \crlf
 \xmlflush{#1}
\stopxmlsetups

\setupbodyfont[modern]
\starttext
\xmlprocessbuffer{demo}{demo}{}
\stoptext

------

[-- Attachment #1.2: Type: text/html, Size: 2656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: XML processing instructions
  2022-05-02  7:19 XML processing instructions Duncan Hothersall via ntg-context
@ 2022-05-02  7:33 ` Duncan Hothersall via ntg-context
  2022-05-02  7:44 ` Denis Maier via ntg-context
  1 sibling, 0 replies; 12+ messages in thread
From: Duncan Hothersall via ntg-context @ 2022-05-02  7:33 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Duncan Hothersall


[-- Attachment #1.1: Type: text/plain, Size: 2651 bytes --]

Apologies, there are two rogue * in the lxml.preprocessor code, but even
when they are removed it doesn't work.

On Mon, 2 May 2022 at 08:19, Duncan Hothersall <dh@capdm.com> wrote:

> 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.
>
> Duncan
>
>
> MWE:
> ------
>
> \startbuffer[demo]
> <book>
>   <para>A paragraph with<?capdm force_line_stop?>a processing
> instruction.</para>
> </book>
> \stopbuffer
>
> \startxmlsetups xml:demo:base
>  \xmlsetsetup{#1}{*}{xml:demo:*}
> \stopxmlsetups
> \xmlregisterdocumentsetup{demo}{xml:demo:base}
>
> \startxmlsetups xml:demo:book
>  \xmlflush{#1}
> \stopxmlsetups
>
> \startxmlsetups xml:demo:para
>  \xmlflush{#1}\endgraf
> \stopxmlsetups
>
> \startluacode
>  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
>  end
> \stopluacode
>
> \startxmlsetups xml:demo:capdmlinestop
>  \crlf
>  \xmlflush{#1}
> \stopxmlsetups
>
> \setupbodyfont[modern]
> \starttext
> \xmlprocessbuffer{demo}{demo}{}
> \stoptext
>
> ------
>


-- 
Duncan Hothersall, Operations Director
CAPDM Limited - Online Program Enablers
0131 677 2400  www.capdm.com
Registered in Scotland: SC168970       VAT: 682 846 983
Registered address: 20 Forth Street Edinburgh EH1 3LH UK
<https://maps.google.com/?q=22+Forth+Street,+Edinburgh,+EH1+3LH,+UK&entry=gmail&source=g>

Capture, author, publish, deliver and manage your learning materials.


*Sign up to the CAPDM newsletter here <http://eepurl.com/bqzBQn>*

[-- Attachment #1.2: Type: text/html, Size: 4264 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: XML processing instructions
  2022-05-02  7:19 XML processing instructions Duncan Hothersall via ntg-context
  2022-05-02  7:33 ` Duncan Hothersall via ntg-context
@ 2022-05-02  7:44 ` Denis Maier via ntg-context
  2022-05-02  7:48   ` Denis Maier via ntg-context
  1 sibling, 1 reply; 12+ messages in thread
From: Denis Maier via ntg-context @ 2022-05-02  7:44 UTC (permalink / raw)
  To: ntg-context; +Cc: denis.maier


[-- Attachment #1.1: Type: text/plain, Size: 2468 bytes --]

Hi Duncan,

I have used context’s own injectors for this :

<?context-directive injector addlinetopage ?>

\startsetups xml:directive:injector:addlinetopage
  \adaptlayout[lines=+1]
\stopsetups

Or, for your line break example :

Von: ntg-context <ntg-context-bounces@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@ntg.nl>
Cc: Duncan Hothersall <dh@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.

Duncan


MWE:
------

\startbuffer[demo]
<book>
  <para>A paragraph with<?capdm force_line_stop?>a processing instruction.</para>
</book>
\stopbuffer

\startxmlsetups xml:demo:base
 \xmlsetsetup{#1}{*}{xml:demo:*}
\stopxmlsetups
\xmlregisterdocumentsetup{demo}{xml:demo:base}

\startxmlsetups xml:demo:book
 \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:demo:para
 \xmlflush{#1}\endgraf
\stopxmlsetups

\startluacode
 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
 end
\stopluacode

\startxmlsetups xml:demo:capdmlinestop
 \crlf
 \xmlflush{#1}
\stopxmlsetups

\setupbodyfont[modern]
\starttext
\xmlprocessbuffer{demo}{demo}{}
\stoptext

------

[-- Attachment #1.2: Type: text/html, Size: 6789 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: XML processing instructions
  2022-05-02  7:44 ` Denis Maier via ntg-context
@ 2022-05-02  7:48   ` Denis Maier via ntg-context
  2022-05-02  8:24     ` Duncan Hothersall via ntg-context
  0 siblings, 1 reply; 12+ messages in thread
From: Denis Maier via ntg-context @ 2022-05-02  7:48 UTC (permalink / raw)
  To: ntg-context; +Cc: denis.maier


[-- Attachment #1.1: Type: text/plain, Size: 3276 bytes --]

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
  \adaptlayout[lines=+1]
\stopsetups

Or, for your line break example :

<?context-directive injector newline ?>

\startsetups xml:directive:injector:newline
  \crlf
\stopsetups

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

\def\xmltexdirective#1#2{\doif{#1}{command}{#2}}

\xmlinstalldirective{tex}{xmltexdirective}

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

Best,
Denis

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


Von: ntg-context <ntg-context-bounces@ntg.nl<mailto:ntg-context-bounces@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@ntg.nl<mailto:ntg-context@ntg.nl>>
Cc: Duncan Hothersall <dh@capdm.com<mailto:dh@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.

Duncan


MWE:
------

\startbuffer[demo]
<book>
  <para>A paragraph with<?capdm force_line_stop?>a processing instruction.</para>
</book>
\stopbuffer

\startxmlsetups xml:demo:base
 \xmlsetsetup{#1}{*}{xml:demo:*}
\stopxmlsetups
\xmlregisterdocumentsetup{demo}{xml:demo:base}

\startxmlsetups xml:demo:book
 \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:demo:para
 \xmlflush{#1}\endgraf
\stopxmlsetups

\startluacode
 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
 end
\stopluacode

\startxmlsetups xml:demo:capdmlinestop
 \crlf
 \xmlflush{#1}
\stopxmlsetups

\setupbodyfont[modern]
\starttext
\xmlprocessbuffer{demo}{demo}{}
\stoptext

------

[-- Attachment #1.2: Type: text/html, Size: 10837 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: XML processing instructions
  2022-05-02  7:48   ` Denis Maier via ntg-context
@ 2022-05-02  8:24     ` Duncan Hothersall via ntg-context
  2022-05-03  7:30       ` Duncan Hothersall via ntg-context
  0 siblings, 1 reply; 12+ messages in thread
From: Duncan Hothersall via ntg-context @ 2022-05-02  8:24 UTC (permalink / raw)
  To: denis.maier; +Cc: Duncan Hothersall, mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 4164 bytes --]

Many thanks Denis. Very useful tip on the injectors and generalised command
usage. That will definitely come in useful.

My problem is that I already have a lot of XML data with the existing
processing instructions in it. I know I could use an external preprocess in
something like Python to change them into injectors before they are fed
into ConTeXt, but I was hoping there was a way to handle them directly as
part of the ConTeXt / lua process.

Thanks again though.

Duncan




On Mon, 2 May 2022, 08:48 , <denis.maier@unibe.ch> wrote:

> 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
>
>   \adaptlayout[lines=+1]
>
> \stopsetups
>
>
>
> Or, for your line break example :
>
>
>
> <?context-directive injector newline ?>
>
>
>
> \startsetups xml:directive:injector:newline
>
>   \crlf
>
> \stopsetups
>
>
>
> Also, I have learned that you can just use arbitrary context code in xml:
>
>
>
> \def\xmltexdirective#1#2{\doif{#1}{command}{#2}}
>
>
>
> \xmlinstalldirective{tex}{xmltexdirective}
>
>
>
>          <?context-directive tex command \inframed{xxx} ?>
>
>          <?context-directive tex command \page ?>
>
>          <?context-directive tex command \crlf ?>
>
>
>
> Best,
>
> Denis
>
>
>
> *Von:* Maier, Denis Christian (UB)
> *Gesendet:* Montag, 2. Mai 2022 09:45
> *An:* 'mailing list for ConTeXt users' <ntg-context@ntg.nl>
> *Cc:* Duncan Hothersall <dh@capdm.com>
> *Betreff:* AW: [NTG-context] XML processing instructions
>
>
>
>
>
> *Von:* ntg-context <ntg-context-bounces@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@ntg.nl>
> *Cc:* Duncan Hothersall <dh@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.
>
>
>
> Duncan
>
>
>
>
>
> MWE:
>
> ------
>
>
>
> \startbuffer[demo]
> <book>
>   <para>A paragraph with<?capdm force_line_stop?>a processing
> instruction.</para>
> </book>
> \stopbuffer
>
> \startxmlsetups xml:demo:base
>  \xmlsetsetup{#1}{*}{xml:demo:*}
> \stopxmlsetups
> \xmlregisterdocumentsetup{demo}{xml:demo:base}
>
> \startxmlsetups xml:demo:book
>  \xmlflush{#1}
> \stopxmlsetups
>
> \startxmlsetups xml:demo:para
>  \xmlflush{#1}\endgraf
> \stopxmlsetups
>
> \startluacode
>  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
>  end
> \stopluacode
>
> \startxmlsetups xml:demo:capdmlinestop
>  \crlf
>  \xmlflush{#1}
> \stopxmlsetups
>
> \setupbodyfont[modern]
> \starttext
> \xmlprocessbuffer{demo}{demo}{}
> \stoptext
>
>
>
> ------
>

[-- Attachment #1.2: Type: text/html, Size: 9709 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: XML processing instructions
  2022-05-02  8:24     ` Duncan Hothersall via ntg-context
@ 2022-05-03  7:30       ` Duncan Hothersall via ntg-context
  0 siblings, 0 replies; 12+ messages in thread
From: Duncan Hothersall via ntg-context @ 2022-05-03  7:30 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Duncan Hothersall


[-- Attachment #1.1: Type: text/plain, Size: 5729 bytes --]

Just following up on my own question in case anybody else is interested, I
realised that the logic of my preprocessor code wasn't the problem, it was
just my ignorance of lua and character escaping. Both ? and * are special
characters in string.gsub expressions, so they need to be escaped with the
lua escape character which is % (which sends my editor haywire because it
thinks I am putting in a TeX comment, but never mind!).

So my now working code to translate historic processing instructions into
directives without a separate pass is:

\startluacode
function lxml.preprocessor(data)
 data = string.gsub(data, '<%?capdm %*force_line_stop%?>',
'<?context-directive injector newline ?>')
 return data
end
\stopluacode

\startsetups xml:directive:injector:newline
 \crlf
\stopsetups

Duncan

On Mon, 2 May 2022 at 09:24, Duncan Hothersall <dh@capdm.com> wrote:

> Many thanks Denis. Very useful tip on the injectors and generalised
> command usage. That will definitely come in useful.
>
> My problem is that I already have a lot of XML data with the existing
> processing instructions in it. I know I could use an external preprocess in
> something like Python to change them into injectors before they are fed
> into ConTeXt, but I was hoping there was a way to handle them directly as
> part of the ConTeXt / lua process.
>
> Thanks again though.
>
> Duncan
>
>
>
>
> On Mon, 2 May 2022, 08:48 , <denis.maier@unibe.ch> wrote:
>
>> 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
>>
>>   \adaptlayout[lines=+1]
>>
>> \stopsetups
>>
>>
>>
>> Or, for your line break example :
>>
>>
>>
>> <?context-directive injector newline ?>
>>
>>
>>
>> \startsetups xml:directive:injector:newline
>>
>>   \crlf
>>
>> \stopsetups
>>
>>
>>
>> Also, I have learned that you can just use arbitrary context code in xml:
>>
>>
>>
>> \def\xmltexdirective#1#2{\doif{#1}{command}{#2}}
>>
>>
>>
>> \xmlinstalldirective{tex}{xmltexdirective}
>>
>>
>>
>>          <?context-directive tex command \inframed{xxx} ?>
>>
>>          <?context-directive tex command \page ?>
>>
>>          <?context-directive tex command \crlf ?>
>>
>>
>>
>> Best,
>>
>> Denis
>>
>>
>>
>> *Von:* Maier, Denis Christian (UB)
>> *Gesendet:* Montag, 2. Mai 2022 09:45
>> *An:* 'mailing list for ConTeXt users' <ntg-context@ntg.nl>
>> *Cc:* Duncan Hothersall <dh@capdm.com>
>> *Betreff:* AW: [NTG-context] XML processing instructions
>>
>>
>>
>>
>>
>> *Von:* ntg-context <ntg-context-bounces@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@ntg.nl>
>> *Cc:* Duncan Hothersall <dh@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.
>>
>>
>>
>> Duncan
>>
>>
>>
>>
>>
>> MWE:
>>
>> ------
>>
>>
>>
>> \startbuffer[demo]
>> <book>
>>   <para>A paragraph with<?capdm force_line_stop?>a processing
>> instruction.</para>
>> </book>
>> \stopbuffer
>>
>> \startxmlsetups xml:demo:base
>>  \xmlsetsetup{#1}{*}{xml:demo:*}
>> \stopxmlsetups
>> \xmlregisterdocumentsetup{demo}{xml:demo:base}
>>
>> \startxmlsetups xml:demo:book
>>  \xmlflush{#1}
>> \stopxmlsetups
>>
>> \startxmlsetups xml:demo:para
>>  \xmlflush{#1}\endgraf
>> \stopxmlsetups
>>
>> \startluacode
>>  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
>>  end
>> \stopluacode
>>
>> \startxmlsetups xml:demo:capdmlinestop
>>  \crlf
>>  \xmlflush{#1}
>> \stopxmlsetups
>>
>> \setupbodyfont[modern]
>> \starttext
>> \xmlprocessbuffer{demo}{demo}{}
>> \stoptext
>>
>>
>>
>> ------
>>
>

-- 
Duncan Hothersall, Operations Director
CAPDM Limited - Online Program Enablers
0131 677 2400  www.capdm.com
Registered in Scotland: SC168970       VAT: 682 846 983
Registered address: 20 Forth Street Edinburgh EH1 3LH UK
<https://maps.google.com/?q=22+Forth+Street,+Edinburgh,+EH1+3LH,+UK&entry=gmail&source=g>

Capture, author, publish, deliver and manage your learning materials.


*Sign up to the CAPDM newsletter here <http://eepurl.com/bqzBQn>*

[-- Attachment #1.2: Type: text/html, Size: 12360 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: XML Processing Instructions
  2002-03-24 21:23     ` Simon Pepping
@ 2002-03-24 22:50       ` Michael Wiedmann
  0 siblings, 0 replies; 12+ messages in thread
From: Michael Wiedmann @ 2002-03-24 22:50 UTC (permalink / raw)


* Simon Pepping <spepping@scaprea.hobby.nl> [020324 22:23]:
...
> specification. <?line-break?> is a perfectly legal PI. Perhaps Hans
> can take this into account in the scanning of PIs.

This would be good, but does not have high priority for me.

Michael
-- 
mw@miwie.in-berlin.de                              http://www.miwie.org
mw@miwie.org


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: XML Processing Instructions
  2002-03-23 13:28   ` Michael Wiedmann
  2002-03-23 10:08     ` Hans Hagen
@ 2002-03-24 21:23     ` Simon Pepping
  2002-03-24 22:50       ` Michael Wiedmann
  1 sibling, 1 reply; 12+ messages in thread
From: Simon Pepping @ 2002-03-24 21:23 UTC (permalink / raw)


On Sat, Mar 23, 2002 at 02:28:55PM +0100, Michael Wiedmann wrote:
> * Simon Pepping <spepping@scaprea.hobby.nl> [020321 20:36]:
> 
> in contrary e.g. to the handling of PIs in DocBook DSSSL styleheets
> *and* against my understanding of the definition for PIs, ConTeXt forces
> to use a 'data' field in PIs (like <?line-break true?>) though
> <?line-break?> alone should be sufficient. ConText stops processing the
> current element content in the last case.

There is a strong tendency to view PI as <?pi-name pi-data?>. See e.g.
the xml-stylesheet PI specification
(http://www.w3.org/TR/xml-stylesheet). This is not supported by any
specification. <?line-break?> is a perfectly legal PI. Perhaps Hans
can take this into account in the scanning of PIs.

Simon

-- 
Simon Pepping
email: spepping@scaprea.hobby.nl


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: XML Processing Instructions
  2002-03-21 19:36 ` Simon Pepping
@ 2002-03-23 13:28   ` Michael Wiedmann
  2002-03-23 10:08     ` Hans Hagen
  2002-03-24 21:23     ` Simon Pepping
  0 siblings, 2 replies; 12+ messages in thread
From: Michael Wiedmann @ 2002-03-23 13:28 UTC (permalink / raw)


* Simon Pepping <spepping@scaprea.hobby.nl> [020321 20:36]:
... 
> \defineXMLprocessor[some-pi] \dosomepi
> \def\dosomepi#1{(Some PI: #1)}
... 
> That is because context expects a form like <?pi-name pi-data?>. The
> data are inserted as a single token after the defined XML processor,
> and thus can be picked up by it as an argument. If no processor is
> defined, the data is ignored.

Thanks Simon, it works like you pointed out, *but*:

in contrary e.g. to the handling of PIs in DocBook DSSSL styleheets
*and* against my understanding of the definition for PIs, ConTeXt forces
to use a 'data' field in PIs (like <?line-break true?>) though
<?line-break?> alone should be sufficient. ConText stops processing the
current element content in the last case.

Or do I still miss something.

Michael
-- 
mw@miwie.in-berlin.de                              http://www.miwie.org
mw@miwie.org


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: XML Processing Instructions
  2002-03-23 13:28   ` Michael Wiedmann
@ 2002-03-23 10:08     ` Hans Hagen
  2002-03-24 21:23     ` Simon Pepping
  1 sibling, 0 replies; 12+ messages in thread
From: Hans Hagen @ 2002-03-23 10:08 UTC (permalink / raw)
  Cc: NTG ConTeXt

At 02:28 PM 3/23/2002 +0100, Michael Wiedmann wrote:
>* Simon Pepping <spepping@scaprea.hobby.nl> [020321 20:36]:
>...
> > \defineXMLprocessor[some-pi] \dosomepi
> > \def\dosomepi#1{(Some PI: #1)}
>...
> > That is because context expects a form like <?pi-name pi-data?>. The
> > data are inserted as a single token after the defined XML processor,
> > and thus can be picked up by it as an argument. If no processor is
> > defined, the data is ignored.
>
>Thanks Simon, it works like you pointed out, *but*:
>
>in contrary e.g. to the handling of PIs in DocBook DSSSL styleheets
>*and* against my understanding of the definition for PIs, ConTeXt forces
>to use a 'data' field in PIs (like <?line-break true?>) though
><?line-break?> alone should be sufficient. ConText stops processing the
>current element content in the last case.
>
>Or do I still miss something.

ok, i'll see if i can fix that

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                                   fall-back web server: 
www.pragma-ade.nl
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: XML Processing Instructions
  2002-03-18 20:11 XML Processing Instructions Michael Wiedmann
@ 2002-03-21 19:36 ` Simon Pepping
  2002-03-23 13:28   ` Michael Wiedmann
  0 siblings, 1 reply; 12+ messages in thread
From: Simon Pepping @ 2002-03-21 19:36 UTC (permalink / raw)


On Mon, Mar 18, 2002 at 09:11:36PM +0100, Michael Wiedmann wrote:
> How do I best handle - non ConTeXt related - XML Processing
> Instructions?

\defineXMLenvironment[phrase] {Phrase: } {}
\defineXMLprocessor[some-pi] \dosomepi
\def\dosomepi#1{(Some PI: #1)}

\starttext
\startXMLdata
<phrase>foo foo foo <?some-pi do this?> bla bla bla</phrase>
\stopXMLdata
\stoptext

> Given:
> 
> <phrase>foo foo foo <?some-pi?> bla bla bla</phrase>
> 
> and a mapping of
> 
> \defineXMLenvironment[phrase] \em
> 
> the rendering stops right after the last "foo".
> 
> I just want ConTeXt to ignore the PI.

That is because context expects a form like <?pi-name pi-data?>. The
data are inserted as a single token after the defined XML processor,
and thus can be picked up by it as an argument. If no processor is
defined, the data is ignored.

Simon

-- 
Simon Pepping
email: spepping@scaprea.hobby.nl


^ permalink raw reply	[flat|nested] 12+ messages in thread

* XML Processing Instructions
@ 2002-03-18 20:11 Michael Wiedmann
  2002-03-21 19:36 ` Simon Pepping
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Wiedmann @ 2002-03-18 20:11 UTC (permalink / raw)


How do I best handle - non ConTeXt related - XML Processing
Instructions?

Given:

<phrase>foo foo foo <?some-pi?> bla bla bla</phrase>

and a mapping of

\defineXMLenvironment[phrase] \em

the rendering stops right after the last "foo".

I just want ConTeXt to ignore the PI.

Michael
-- 
mw@miwie.in-berlin.de                              http://www.miwie.org
mw@miwie.org


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-05-03  7:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-02  7:19 XML processing instructions Duncan Hothersall via ntg-context
2022-05-02  7:33 ` Duncan Hothersall via ntg-context
2022-05-02  7:44 ` Denis Maier via ntg-context
2022-05-02  7:48   ` Denis Maier via ntg-context
2022-05-02  8:24     ` Duncan Hothersall via ntg-context
2022-05-03  7:30       ` Duncan Hothersall via ntg-context
  -- strict thread matches above, loose matches on Subject: below --
2002-03-18 20:11 XML Processing Instructions Michael Wiedmann
2002-03-21 19:36 ` Simon Pepping
2002-03-23 13:28   ` Michael Wiedmann
2002-03-23 10:08     ` Hans Hagen
2002-03-24 21:23     ` Simon Pepping
2002-03-24 22:50       ` Michael Wiedmann

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).