On 8/19/2020 6:10 PM, Pablo Rodriguez wrote:
Dear list,

I have the following sample:

   \startbuffer[demo]
   <html>
     <body>
       <div id="First">
         <p>This is
           <span class="special">One of the best</span> a paragraph.</p>
         <p>This is another paragraph.</p>
         <p>This is another
           <span class="special">Two of the best</span> paragraph.</p>
         <p>This is another
           <span class="special">Three</span> paragraph.</p>
         <p>This is another
           <span class="special">Four of five</span> paragraph.</p>
       </div>
     </body>
   </html>
   \stopbuffer

   \startxmlsetups xml:initialize
     \xmlsetsetup{#1}{html}{xml:gen}
   \stopxmlsetups

   \xmlregistersetup{xml:initialize}

   \startxmlsetups xml:gen
      \xmlfilter{#1}{/**/div/command(xml:special)}
   \stopxmlsetups

   \startxmlsetups xml:special
     %~ \startitem
     \cldcontext{string.gsub(lxml.flush([[#1]]),
        " of the ", "")}\stopitem
   \stopxmlsetups

   \starttext
     \xmlprocessbuffer{main}{demo}{}
   \stoptext

Is there any way to remove " of " and " of the " in the filtered content
(xml:special)?

Sorry, Lua code is crap for sure.
\startbuffer[demo]
  <html>
    <body>
      <div id="First">
<p>This is <span class="special">One of the best</span> a paragraph.</p>
        <p>This is another paragraph.</p>
<p>This is another <span class="special">Two of the best</span> paragraph.</p> <p>This is another <span class="special">Three</span> paragraph.</p> <p>This is another <span class="special">Four of five</span> paragraph.</p>
      </div>
      <div id="Second">
<p>This is <span class="special">One of the best</span> a paragraph.</p>
        <p>This is another paragraph.</p>
<p>This is another <span class="special">Two of the best</span> paragraph.</p> <p>This is another <span class="special">Three</span> paragraph.</p> <p>This is another <span class="special">Four of five</span> paragraph.</p>
      </div>
    </body>
  </html>
\stopbuffer

\startxmlsetups xml:initialize
    \xmlsetsetup{#1}{html}{xml:gen}
    \xmlsetsetup{#1}{span[@class='special']}{xml:span:special}
\stopxmlsetups

\xmlregistersetup{xml:initialize}

\startxmlsetups xml:gen
    \startitemize
        \xmlfilter{#1}{/**/div/command(xml:special)}
    \stopitemize
\stopxmlsetups

\startxmlsetups xml:special
    \startitem
        <\xmlflush{#1}>
    \stopitem
\stopxmlsetups

\startxmlsetups xml:span:special
    (\cldcontext{(string.gsub([[\xmlraw{#1}{.}]]," of the ", ""))})
\stopxmlsetups

\starttext
    \xmlprocessbuffer{main}{demo}{}
\stoptext

Or make a finalizer as Taco posted.

Hans



-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to