背景

背景

背景

使用典型的英语标点符号来格式化多段引用:每段开头使用引号,最后一段结尾使用单个结束引号。

问题

考虑以下 XML 元素:

<blockquote>
 <p>Single line quote.</p>
</blockquote>

<blockquote>
 <p>Double line quote, line 1 of 2.</p>
 <p>Double line quote, line 2 of 2.</p>
</blockquote>

<blockquote>
  <p>Dear letter opener,</p>
  <p>Your envelope shredding expediency amazes.</p>
  <p>Signed, CIA</p>
</blockquote>

这些应分别产生:

“单行引文。”

“双行引用,第 1 行,共 1 行。

“双行引述,第 1 行,共 2 行。”

“亲爱的开信人,

“您撕碎信封的技术让人惊讶。

“签名,中央情报局”

问题在于找出什么函数(,,,,,等count())能够区分以下可能性:position()index()first()last()

  • 包含 1 段内容的区块引用
  • 包含 2 段内容的区块引用
  • 包含 3 段或更多段落的区块引用

代码

以下是设置:

% Block elements
\xmlsetsetup{\xmldocument}{blockquote|div|p}{xml:*}
\xmlsetsetup{\xmldocument}{blockquote/p[position()==first() and position()!=last()]}{xml:q:began}
\xmlsetsetup{\xmldocument}{blockquote/p[position()!=first() and position()==last()]}{xml:q:ended}
\xmlsetsetup{\xmldocument}{blockquote/p[position()>first() and position()<last()]}{xml:q:middle}

以下是 XML 设置:

% Indented quotations.
\startxmlsetups xml:blockquote
  \xmlflush{#1}
\stopxmlsetups
 
\startxmlsetups xml:q:began
  \startquotation
    \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:q:middle
  \symbol[leftquotation]\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:q:ended
    \xmlflush{#1}
  \stopquotation
\stopxmlsetups

问题

如何区分这三种可能性以产生所需的行为?

答案1

设置集合:

% Block elements
\xmlsetsetup{\xmldocument}{blockquote|div|p}{xml:*}
\xmlsetsetup{\xmldocument}{blockquote/p}{xml:blockquote:p}
\xmlsetsetup{\xmldocument}{blockquote[count(p)=1]}{xml:blockquote:single}
\xmlsetsetup{\xmldocument}{blockquote[count(p)=2]/p[position()=first()]}{xml:blockquote:began}
\xmlsetsetup{\xmldocument}{blockquote[count(p)=2]/p[position()=last()]}{xml:blockquote:ended}
\xmlsetsetup{\xmldocument}{blockquote[count(p)>2]/p[position()=first()]}{xml:blockquote:began}
\xmlsetsetup{\xmldocument}{blockquote[count(p)>2]/p[position()>first() and position()<last()]}{xml:blockquote:multiple:middle}
\xmlsetsetup{\xmldocument}{blockquote[count(p)>2]/p[position()=last()]}{xml:blockquote:ended}

然后定义不同的场景:

\startxmlsetups xml:p
  \startparagraph
    \xmlflush{#1}
  \stopparagraph
\stopxmlsetups

% Indented quotations.
\startxmlsetups xml:blockquote
  \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:blockquote:p
  \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:blockquote:single
  \startquotation
    \ignorespaces\xmlflush{#1}\removeunwantedspaces
  \stopquotation
\stopxmlsetups

\startxmlsetups xml:blockquote:began
  \startquotation
    \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:blockquote:multiple:middle
    \par\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:blockquote:ended
    \par\xmlflush{#1}
  \stopquotation
\stopxmlsetups

最后,设置引文本身以自动引用每一行:

\setupquotation[
  before={\blank},
  after={\blank},
  repeat=yes,
  middle={\symbol[leftquotation]},
]

存在可以解决的重复问题,并且似乎没有办法控制第一个引号的突出。

相关内容