ConTeXt XML: Nested section elements
One option is to map the <section>
tags to \startsectionlevel
macros, which can be nested:
\starttext
\startstructurelevel[title=Section heading]
Some text
\startstructurelevel[title=Subsection heading]
More text
\stopstructurelevel
\stopstructurelevel
\stoptext
The default mapping is that the first level maps to a chapter, the second level maps to a section, and so on. You can change this setting using:
\definesectionlevels
[default]
[
section,
subsection,
subsubsection,
subsubsubsection,
]
With the above setup, the first level \startstructurelevel
is mapped to \startsection
, the second level \startstructurelevel
is mapped to \startsubsection
and so on until four nested levels.
You can change the style of the document using normal setup commands that change the style of \startsection
etc. Here is an example:
\definesectionlevels
[default]
[
section,
subsection,
subsubsection,
subsubsubsection,
]
\setuphead[section][color=blue]
\setuphead[subsection][color=red]
\starttext
\startstructurelevel[title=Section heading]
Some text
\startstructurelevel[title=Subsection heading]
More text
\stopstructurelevel
\stopstructurelevel
\stoptext
which gives
Based on Aditya's input I can now come up with this solution:
\startbuffer[test]
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.0 20120330//EN"
"JATS-journalpublishing1.dtd">
<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="1.0" article-type="other">
<front>
</front>
<body>
<sec id="section-heading">
<title>Section Heading</title>
<p>Some Text</p>
<sec id="subsection-heading">
<title>Subsection Heading</title>
<p>More Text</p>
</sec>
</sec>
</body>
<back>
</back>
</article>
\stopbuffer
\startxmlsetups xml:jatssetups
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{article|body|sec|p}{xml:*}
\stopxmlsetups
\xmlregistersetup{xml:jatssetups}
\startxmlsetups xml:article
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:body
\startdocument
\xmlflush{#1}
\stopdocument
\stopxmlsetups
\startxmlsetups xml:p
\xmlflush{#1}\par
\stopxmlsetups
% Sections
\startxmlsetups xml:sec
\startstructurelevel [title=\xmlfilter{#1}{/title/command(xml:sec:title)}]
\xmlflush{#1}
\stopstructurelevel
\stopxmlsetups
\startxmlsetups xml:sec:title
\xmlflush{#1}
\stopxmlsetups
\definestructurelevels [default] [section,subsection,subsubsection]
\setuphead [section] [style=\bf]
\setuphead [subsection] [style=\em]
\xmlprocessbuffer{main}{test}{}