Hello, I'm trying to add new templates (xmlsetups) from the XML document itself.
See the attached MWE. - the XML document is a simple XHTML file- in the "head" element there's a "script" element with the "type" attribute set to "text/vnd.context", whose contents are then passed to \xmlcontext
- the "body" element has a "data-xmlsetups" attribute whose value should tell which xmlsetups is to be applied on the body contents (it's defined in the "script" element above)
If it worked, the resulting PDF should show the body element, followed by a "Hello world!" paragraph written in red. But it does not work, because there's something I'm missing in the redefinition and application of xmlsetups.
To try the MWE, type: context --environment=nested-xmlsetup.tex --forcexml nested-xmlsetup.xhtml Massi
\startxmlsetups html \xmlsetsetup{#1}{{html|head}}{html:flush} \xmlsetsetup{#1}{{html head script}}{html:script:context} \xmlsetsetup{#1}{{html body}}{html:body} \xmlsetsetup{#1}{p}{html:p} \stopxmlsetups \startxmlsetups html:flush \xmlflush{#1} \stopxmlsetups \startluacode function xml.functions.parseScript(s) local mimetype = s and s.at and s.at.type if mimetype and mimetype == "text/vnd.context" then lxml.context(s) end end function xml.functions.flushBody(b) local xmlsetups = b and b.at and b.at["data-xmlsetups"] if xmlsetups then lxml.tobuffer(b, ".", "body") context("\\typebuffer[body]") context.xmlprocessbuffer("body", "body", xmlsetups) else lxml.flush(b) end end \stopluacode \startxmlsetups html:script:context \xmlfunction{#1}{parseScript} \stopxmlsetups \startxmlsetups html:body \starttext \xmlfunction{#1}{flushBody} \stoptext \stopxmlsetups \startxmlsetups html:p \dontleavehmode\xmlflush{#1}\par \stopxmlsetups \xmlregistersetup{html}
nested-xmlsetup.xhtml
Description: application/xhtml
___________________________________________________________________________________ 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 ___________________________________________________________________________________