[NTG-context] XML xmldoif struggle!

Pablo Rodriguez oinos at gmx.es
Wed May 1 13:20:18 CEST 2019


On 4/30/19 9:58 PM, Geert Verhaag wrote:
> [...]
> \startxmlsetups xml:invoice:invoice
>    \xmlfirst{#1}{currency} \par
>    \xmldoif{\xmlfirst{#1}{currency}}{contains(text(),'EURO')} {
>       Euro set! \par
>    }
> [...]
> But the xmldoif command doesn't cause the Euro set be printed?!
>
> What's wrong here? The manual xml-mkiv.pdf doesn't give me any hint on
> how to make this work!

Hi Geert,

the syntax reads \xmldoif{#1}{lpath}{action}. So your conditional may read:

    \xmldoif{#1}{currency[first() and contains(text(),'EURO')]}
        {Euro set!}

In a complete sample (with dollar set first [it won’t show the result
unless you set EURO first]):

  \startbuffer[demo]
  <doc>
    <invoice number="194-002" client="RPMB-0012">
      <currency>DOLLAR</currency>
      <currency>EURO</currency>
    </invoice>
  </doc>
  \stopbuffer

  \startxmlsetups xml:initialize
     \xmlsetsetup{#1}{doc}{xml:*}
  \stopxmlsetups

  \xmlregistersetup{xml:initialize}

  \startxmlsetups xml:doc
    \xmlfirst{#1}{currency} \par
    \xmldoif{#1}{currency[first() and contains(text(),'EURO')]}
        {Euro set!}
  \stopxmlsetups

  \setuppapersize[A8]

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

It is all in xml-mkiv.pdf
(http://www.pragma-ade.com/general/manuals/xml-mkiv.pdf#page=49). I have
just discovered it 😉.

Just in case it helps,

Pablo
--
http://www.ousia.tk


More information about the ntg-context mailing list