You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在CSL文件中设置首次文内引用的cs:if判断条件?

CSL文内引用规则配置问题

我正在尝试创建一个CSL文件,要求首次文内引用显示作者姓名,后续所有文内引用显示贡献者姓名(若不存在贡献者则仍显示作者姓名)。请问在<cs:if>块中需要设置何种判断条件才能实现这一需求?

以下是我的CSL文件中引用部分的代码片段:

<citation>
  <sort />
  <layout>
    <choose>
      <!-- 我需要获取下一行的判断条件 -->
      <if match="CONDITIONAL FOR FIRST IN-TEXT CITATION">
        <text macro="author-short"/>
      </if>
      <else>
        <choose>
          <!-- 若存在贡献者,后续引用使用贡献者信息;否则使用短作者信息 -->
          <if match="any" variable="contributor">
            <text macro="author-contrib"/>
          </if>
          <else>
            <text macro="author-short"/>
          </else>
        </choose>
      </else>
    </choose>
  </layout>
</citation>

解决方案

要判断是否为首次文内引用,需要使用CSL的position属性配合match="first",具体判断条件为:

<if match="first" position="citation">

这个条件会检测当前引用是否是该文献在整个文档中的首次文内引用:

  • 首次引用时,执行<text macro="author-short"/>显示作者姓名;
  • 非首次引用时进入else分支,先检查是否存在contributor变量,存在则显示贡献者信息,不存在则仍显示作者姓名。

修正后的完整代码片段:

<citation>
  <sort />
  <layout>
    <choose>
      <if match="first" position="citation">
        <text macro="author-short"/>
      </if>
      <else>
        <choose>
          <if match="any" variable="contributor">
            <text macro="author-contrib"/>
          </if>
          <else>
            <text macro="author-short"/>
          </else>
        </choose>
      </else>
    </choose>
  </layout>
</citation>

内容的提问来源于stack exchange,提问作者Alex Essilfie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 23:51:15