1

我正在使用w3c bibtex 转换来生成一个 bibtex 文件,但不幸的是它正在为同一年的论文生成重复的作者密钥。

  • 琼斯:2012
  • 琼斯:2012

bibtex-label问题模板在xslt中命名。

我如何添加每个作者每年的计数值,以便 bibtex-label 看起来像这样:

  • 琼斯:2012a
  • 琼斯:2012b

我找不到任何关于做这类事情的好资源,特别是对于非 xml 输出。

示例输入(来自此处):

<rdf:RDF xmlns="http://www.w3.org/2001/02pd/rec54#"
    xmlns:contact="http://www.w3.org/2000/10/swap/pim/contact#"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:doc="http://www.w3.org/2000/10/swap/pim/doc#"
    xmlns:mat="http://www.w3.org/2002/05/matrix/vocab#"
    xmlns:org="http://www.w3.org/2001/04/roadmap/org#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rec="http://www.w3.org/2001/02pd/rec54#">

    <REC rdf:about="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001">
        <dc:date>1998-10-01</dc:date>
        <dc:title>Document Object Model (DOM) Level 1</dc:title>
        <doc:versionOf rdf:resource="http://www.w3.org/TR/REC-DOM-Level-1"/>
        <editor rdf:parseType="Resource">
            <contact:fullName>Arnaud Le Hors</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Scott Isaacs</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Steve Byrne</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Mike Champion</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Gavin Nicol</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Lauren Wood</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Ian Jacobs</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Robert Sutor</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Jonathan Robie</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Chris Wilson</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Vidur Apparao</contact:fullName>
        </editor>
        <org:deliveredBy rdf:parseType="Resource">
            <contact:homePage rdf:resource="http://www.w3.org/DOM/Group/"/>
        </org:deliveredBy>
        <mat:hasErrata rdf:resource="http://www.w3.org/DOM/updates/REC-DOM-Level-1-19981001-errata.html"/>
    </REC>


    <REC rdf:about="http://www.w3.org/TR/1998/REC-html40-19980424">
        <rdf:type rdf:resource="http://www.w3.org/2001/02pd/rec54#Superseded"/>
        <dc:date>1998-04-24</dc:date>
        <dc:title>HTML 4.0 Specification</dc:title>
        <doc:versionOf rdf:resource="http://www.w3.org/TR/html40"/>
        <editor rdf:parseType="Resource">
            <contact:fullName>Arnaud Le Hors</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>Ian Jacobs</contact:fullName>
        </editor>
        <editor rdf:parseType="Resource">
            <contact:fullName>David Raggett</contact:fullName>
        </editor>
        <previousEdition rdf:resource="http://www.w3.org/TR/REC-html40-971218"/>
        <org:deliveredBy rdf:parseType="Resource">
            <contact:homePage rdf:resource="http://www.w3.org/MarkUp/"/>
        </org:deliveredBy>
        <mat:hasErrata rdf:resource="http://www.w3.org/MarkUp/html40-updates/REC-html40-19980424-errata.html"/>
    </REC>

</rdf:RDF>

示例输出(完整):

@TechReport{LeHors:1998,
  author = {Arnaud Le Hors and Scott Isaacs and Steve Byrne and Mike Champion and Gavin Nicol and Lauren Wood and Ian Jacobs and Robert Sutor and Jonathan Robie and Chris Wilson and Vidur Apparao},
  title  = {{Document Object Model (DOM) Level 1}},
  note = {\url{http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001}. Latest version available at \url{http://www.w3.org/TR/REC-DOM-Level-1}},
  year = {1998},
  month = nov,
  bibsource = "http://www.w3.org/2002/01/tr-automation/tr.rdf",
  type = "Recommendation",
  institution = "W3C",
}

@TechReport{LeHors:1998,
  author = {Arnaud Le Hors and Ian Jacobs and David Raggett},
  title  = {{HTML 4.0 Specification}},
  note = {\url{http://www.w3.org/TR/1998/REC-html40-19980424}. Latest version available at \url{http://www.w3.org/TR/html40}},
  year = {1998},
  month = apr,
  bibsource = "http://www.w3.org/2002/01/tr-automation/tr.rdf",
  type = "Recommendation",
  institution = "W3C",
}

期望的输出:

@TechReport{LeHors:1998a,
  author = {Arnaud Le Hors and Scott Isaacs and Steve Byrne and Mike Champion and Gavin Nicol and Lauren Wood and Ian Jacobs and Robert Sutor and Jonathan Robie and Chris Wilson and Vidur Apparao},
  title  = {{Document Object Model (DOM) Level 1}},
  note = {\url{http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001}. Latest version available at \url{http://www.w3.org/TR/REC-DOM-Level-1}},
  year = {1998},
  month = nov,
  bibsource = "http://www.w3.org/2002/01/tr-automation/tr.rdf",
  type = "Recommendation",
  institution = "W3C",
}

@TechReport{LeHors:1998b,
  author = {Arnaud Le Hors and Ian Jacobs and David Raggett},
  title  = {{HTML 4.0 Specification}},
  note = {\url{http://www.w3.org/TR/1998/REC-html40-19980424}. Latest version available at \url{http://www.w3.org/TR/html40}},
  year = {1998},
  month = apr,
  bibsource = "http://www.w3.org/2002/01/tr-automation/tr.rdf",
  type = "Recommendation",
  institution = "W3C",
}
4

1 回答 1

1

首先,为了简化safeSurnametranslate函数的函数,您可以在 XSLT 顶部定义两个变量,如下所示

<xsl:variable name="nameIn" 
   select="'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.- 0123456789ñÑçÇáéíóúÃÉÃÓÚäëïöüÄËÃÖÜ'" />
<xsl:variable name="nameOut" 
   select="'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

然后,这将允许您编写更具可读性的代码来获取格式化的姓氏

<xsl:variable name="safeSurname" select="translate($surname, $nameIn, $nameOut)" />

当您看到生成后缀的代码时会变得更加清晰,这可以使用xsl:number函数来计算具有匹配年份和姓氏的前面兄弟姐妹的数量。注意使用format属性来输出字母而不是数字:

<xsl:number 
   value="count(preceding-sibling::rec:REC
      [substring-before(dc:date/text(), '-') = $date]
      [translate(substring-after(rec:editor[1]/contact:fullName, ' '), $nameIn, $nameOut) = $safeSurname]
   ) + 1" 
   format="a"/>

在此代码中, $date是当前REC元素的年份。

这是bibtex-label的完整匹配模板。注意我已经删除了对dc:date模板的调用,模式为 bibtex-year,只是为了将代码全部保存在一个模板中。

<xsl:template match="*" mode="bibtex-label">
  <xsl:variable name="surname" select="substring-after(rec:editor[1]/contact:fullName, ' ')"/>
  <xsl:variable name="safeSurname" select="translate($surname, $nameIn, $nameOut)" />
  <xsl:variable name="date"  select="substring-before(dc:date/text(), '-')"/>
  <xsl:value-of select="concat($safeSurname, ':', $date)" />
  <xsl:number value="count(preceding-sibling::rec:REC[substring-before(dc:date/text(), '-') = $date][translate(substring-after(rec:editor[1]/contact:fullName, ' '), $nameIn, $nameOut) = $safeSurname]) + 1" format="a"/>
</xsl:template>
于 2012-08-27T08:37:33.300 回答