Using the "extra" field to add more info. (Citation count)

Hi all,

I'm doing something non-standard and want to add "Number of citations: X" to the end of my bibliography.

So it would look like:


McInnis, M. D., & Nelson, L. P. (2011). Shaping the body politic: Art and political formation in early america. Charlottesville, VA: University of Virginia Press. Number of citations: X.

I wanted to pull "X" variable from the "extra" field since that seems unused.

Can I just add

<text variable="extra" prefix="Citations: "/>

To somewhere in the publisher macro? (I tried and didn't work and I guess I've got the wrong placement). Should I just place it inside all the if/then statements? Zotero didn't like what I did and said my CSL wasn't a Zotero CSL.

Any suggestions? I just want to have some text like "Cited" XX "times" with the XX coming from a field in Zotero. Thanks!

Here's the code.

<macro name="publisher">
<choose>
<if type="report" match="any">
<group delimiter=": ">
<text variable="publisher-place"/>
<text variable="publisher"/>
</group>
</if>
<else-if type="thesis" match="any">
<group delimiter=", ">
<text variable="publisher"/>
<text variable="publisher-place"/>
</group>
</else-if>
<else-if type="post-weblog webpage" match="none">
<group delimiter=", ">
<choose>
<if variable="event" type="speech" match="none">
<text variable="genre"/>
</if>
</choose>
<choose>
<if type="article-journal article-magazine" match="none">
<group delimiter=": ">
<choose>
<if variable="publisher-place">
<text variable="publisher-place"/>
</if>
<else>
<text variable="event-place"/>
</else>
</choose>
<text variable="publisher"/>
</group>
</if>
</choose>
</group>
</else-if>
</choose>
</macro>
  • Zotero's "Extra" is mapped to "note" in CSL.
    See here for a complete mapping:
    http://aurimasv.github.io/z2csl/typeMap.xml#map-journalArticle

    With that this will work, just make sure you don't place it inside some if condition that's may not be met.
  • Ah! So any field I can use instead? And what would be the code?
  • sorry, that may not have been clear. If you just change what you have above to
    <text variable="note" prefix="Citations: "/>
    this will work.
  • ah! okay. And in terms of placement, I'm just putting it right after every text variable line up there. Let me try!
  • I am no longer getting an error message, but also not seeing the extra field printed in the bibliography. I changed the Publisher macro;

    <macro name="publisher">
    <choose>
    <if type="report" match="any">
    <group delimiter=": ">
    <text variable="publisher-place"/>
    <text variable="publisher"/>
    <text variable="note" prefix="Citations: "/>
    </group>
    </if>
    <else-if type="thesis" match="any">
    <group delimiter=", ">
    <text variable="publisher"/>
    <text variable="publisher-place"/>
    <text variable="note" prefix="Citations: "/>
    </group>
    </else-if>
    <else-if type="post-weblog webpage" match="none">
    <group delimiter=", ">
    <choose>
    <if variable="event" type="speech" match="none">
    <text variable="genre"/>
    </if>
    </choose>
    <choose>
    <if type="article-journal article-magazine" match="none">
    <group delimiter=": ">
    <choose>
    <if variable="publisher-place">
    <text variable="publisher-place"/>
    <text variable="note" prefix="Citations: "/>
    </if>
    <else>
    <text variable="event-place"/>
    <text variable="note" prefix="Citations: "/>
    </else>
    </choose>
    <text variable="publisher"/>
    <text variable="note" prefix="Citations: "/>
    </group>
    </if>
    </choose>
    </group>
    </else-if>
    </choose>
    </macro>
  • Oh wait, I now see it but it is repeated. And also prints it before "retrieved from". Okay closer. I think it falls through both if-thens.

    Doe, J. (2015b, August 13). Jane De's Plight. New York Times. Citations: 2: Citations: 2. Retrieved from http://www.nytimes.com/2015/08/14/janedoesplight.
  • Try this instead:
    <macro name="publisher">
    <group delimiter=". ">
    <choose>
    <if type="report" match="any">
    <group delimiter=": ">
    <text variable="publisher-place"/>
    <text variable="publisher"/>
    </group>
    </if>
    <else-if type="thesis" match="any">
    <group delimiter=", ">
    <text variable="publisher"/>
    <text variable="publisher-place"/>
    </group>
    </else-if>
    <else-if type="post-weblog webpage" match="none">
    <group delimiter=", ">
    <choose>
    <if variable="event" type="speech" match="none">
    <text variable="genre"/>
    </if>
    </choose>
    <choose>
    <if type="article-journal article-magazine" match="none">
    <group delimiter=": ">
    <choose>
    <if variable="publisher-place">
    <text variable="publisher-place"/>
    </if>
    <else>
    <text variable="event-place"/>
    </else>
    </choose>
    <text variable="publisher"/>
    </group>
    </if>
    </choose>
    </group>
    </else-if>
    </choose>
    <text variable="note" prefix="Citations: "/>
    </group>
    </macro>

    The problem are the various nested if conditionals here to fit APAs (I assume) rather convoluted requirements. Easier if -- since you want this for all item types I assume -- you take this out of any if/else-if conditional entirely.
  • oh, and if placing it before the "Retrieved" bit is an issue, include it in a similar fashion at the end of the access (or whatever it's called in that style) macro instead.
    Or even in the bibliography as the last element, with prefix=". "
  • Thanks. I had it exactly like where yours was first, but got an error message. Let me try yours.

    *goes and tries*

    Same error message. Not Zotero CSL file. My version works but just repeats due to the if-then structure.
  • (Also this version doesn't produce "Citations:X").
  • can I see whole style (gist.github.com also makes it easier to see code bc it preserves indentation)?
    I tested my code above pasted into APA and that definitely works.
    Otherwise try
    <text macro="access" prefix=" "/>
    <text macro="original-date" prefix=" "/>
    <text variable="note" prefix=". Citations: "/>
    </layout>

    all the way at the bottom. That would be the easiest solution.
  • Sure. It's APA with one minor modification (I sort bibliography reverse chronologically). Thanks.

    https://gist.github.com/anonymous/ef4a084053c6e6455a7c

    I am fine with APA. Sort order change is easy to do. I just would like to have a place which says "number of citations:" X, preferably at the end of citation after the "retrieved from" and everything at the very very end.
  • edited August 30, 2015
    What you have works for me, but try
    https://gist.github.com/adam3smith/90273f809beb82a6e91b/raw/5c07534a332ee9db4150fba5d4ccae9229fe8d3a/unc-cv-cite.csl (direct download link), which will actually place the citation count at the end.
  • Perfect. I will only change the chronology of the biblio and this is PERFECT. Thanks a lot.
  • Two quick notes for future reference for anyone else finding this:
    1. The universal way of adding the extra field at the end of every bibliography entry for any style is to add
    <text variable="note" prefix=". "/> in the third last line of the style, right above </layout> You can then add anything else you want to the prefix field. See the general instructions on modifying styles here.

    2. In case you or anyone wants to use this as part of an online CV based on the Zotero API, it's now possible to use any style hosted online (e.g. a link to the raw github version) to get formatted Zotero reference lists. API basics here. An example request could look like this: https://api.zotero.org/users/475425/items/X42A7DEE?format=bib&style=https://raw.githubusercontent.com/citation-style-language/styles/master/apa.csl
Sign In or Register to comment.