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

如何用XPath 2.0从MARC21-XML中精准提取译者姓名

Correct XPath 2.0 Expression to Extract Translators from MARC21-XML

Let’s fix that XPath to only capture actual translators and avoid pulling in other contributors. The core issue with your original expression was that it didn’t filter based on the contributor’s role code—we just need to add a check for the trl (translator) role in the subfield[@code='4'].

Here’s the refined XPath 2.0 expression:

/record/datafield[@tag='700'][@ind1='1'][@ind2=' '][subfield[@code='4'] = 'trl']/subfield[@code='a']/text()

Breakdown of the expression:

  • /record/datafield[@tag='700'][@ind1='1'][@ind2=' ']: First, we target the 700 datafields (for personal names) that match the indicator values you specified (ind1="1" for direct entry, ind2=" " with no second indicator).
  • [subfield[@code='4'] = 'trl']: This is the critical filter. It ensures we only keep datafields that have a subfield with code="4" (the MARC role code field) whose text is exactly "trl" (the code for "translator").
  • /subfield[@code='a']/text(): Finally, we extract the text content of the subfield with code="a"—which holds the contributor’s name.

How it works with your examples:

  1. Example XML 1: The expression returns only the two translators:

    Wasel, Ulrike
    Timmermann, Klaus
    

    It correctly ignores the datafield with ind2="2" since it doesn’t meet the indicator criteria.

  2. Example XML 2: It still returns the same two translators, and excludes John Doe—his subfield[@code='4'] has "oth" (other role), so he gets filtered out as intended.

Quick note: If your XPath processor requires handling the MARC21 namespace (http://www.loc.gov/MARC21/slim from your XML), you’ll need to bind a namespace prefix (e.g., marc) and adjust the expression to use it:

/marc:record/marc:datafield[@tag='700'][@ind1='1'][@ind2=' '][marc:subfield[@code='4'] = 'trl']/marc:subfield[@code='a']/text()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:12:21