ConTeXt:两列可选 XML

ConTeXt:两列可选 XML

我有以下 XML 数据:

\startbuffer[demo]
<?xml version="1.0" encoding="UTF-8"?>
<Book>
<Reading>
<Header>Foo</Header>
<Source>From Source #1</Source>
<Line>Line #1</Line>
<Line>Line #2</Line>
<Line>Line #3</Line>
</Reading>
<Reading>
<Header>Bar</Header>
<Line>Line #4</Line>
<Line>Line #5</Line>
<Line>Line #6</Line>
</Reading>
</Book>
\stopbuffer

\startxmlsetups xml:initialize
    \xmlsetsetup{#1}{Book|Reading|Header|Source|Line}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:initialize}

我想将<Header>and<Source>放在两列中,但正如您在第二次阅读中看到的那样,有时没有来源。我定义了一个\ReadingHeaderand 打算使用:

\startxmlsetups xml:Reading
    \startReadingHeader
    \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:Source
    \xmlflush{#1}
    \stopReadingHeader
\stopxmlsetups

...但如果没有,这将不起作用<Source>。我确信我做错了。正确的方法是什么?

答案1

取决于<source>缺少时所需的输出是什么。您可以使用\xmlfilter{#1}{...}\xmldoif...等。以下是一个例子:

\startbuffer[demo]
<?xml version="1.0" encoding="UTF-8"?>
<Book>
<Reading>
<Header>Foo</Header>
<Source>From Source #1</Source>
<Line>Line #1</Line>
<Line>Line #2</Line>
<Line>Line #3</Line>
</Reading>
<Reading>
<Header>Bar</Header>
<Line>Line #4</Line>
<Line>Line #5</Line>
<Line>Line #6</Line>
</Reading>
</Book>
\stopbuffer

\startxmlsetups xml:initialize
  \xmlsetsetup{#1}{*}{-}
  \xmlsetsetup{#1}{Book|Reading}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:initialize}

\startxmlsetups xml:Book
  \startdocument
    \xmlflush{#1}
  \stopdocument
\stopxmlsetups

\definemixedcolumns[ReadingHeader][balance=yes]

\startxmlsetups xml:Reading
  \startReadingHeader
    \xmlfilter{#1}{/Header/command(xml:Header)}
    \column
    \xmlfilter{#1}{/Source/command(xml:Source)}
  \stopReadingHeader
    \xmlfilter{#1}{/Line/command(xml:Line)}
\stopxmlsetups

\startxmlsetups xml:Source
  [\xmlflush{#1}]
\stopxmlsetups

\startxmlsetups xml:Header
    \bold{\xmlflush{#1}}\space
\stopxmlsetups

\startxmlsetups xml:Line
    \xmlflush{#1}
\stopxmlsetups

\xmlprocessbuffer{main}{demo}{}

这使

在此处输入图片描述

相关内容