DOI and URL in CSL 1.0

I started to post this as a question, then solved my own problem, so now I'm posting this to a) share, and b) maybe get a critique of my syntax, in case there's a better way to do this.

My goal was to include URLs in all references in the bibliography, except when the DOI is available. I did it with this "access" macro (the bottom part of which also does something helpful, add [accessed on] for date-less items:

<macro name="access">
<group>
<choose>
<if variable="DOI" match="any">
<group prefix="DOI: ">
<text variable="DOI"></text>
</group>
</if>
<else-if variable="URL" match="any">
<group prefix="Available at ">
<text variable="URL"></text>
</group>
</else-if>
</choose>
<choose>
<if variable="issued" match="none">
<group prefix=" [" suffix="]">
<text term="accessed" text-case="lowercase" suffix=" "/>
<date variable="accessed">
<date-part name="month" suffix=" "/>
<date-part name="day" suffix=", "/>
<date-part name="year"/>
</date>
</group>
</if>
<else-if variable="issued" match="any"/>
</choose>
</group>
</macro>

The result is this:

Stern, N. (2006). The Stern Review: The Economics of Climate Change. London: HM Treasury. Available at http://www.hm-treasury.gov.uk/stern_review_report.htm.

Tol, R.S.J. (2003). “Is the uncertainty about climate change too large for expected cost-benefit analysis?” Climatic Change 56(3), 265–89. DOI: 10.1023/A:1021753906949.

Tol, R.S.J. and Yohe, G.W. (2006). “A Review of the Stern Review.” World Economics 7(4), 233–50. Available at http://www.world-economics-journal.com/Contents/ArticleOverview.aspx?ID=262.

To make this work, you have to check the box in the main Zotero menu to include URLs. If you uncheck it, it'll still include URLs for non-journal/newspaper/magazine articles like Stern, but omit them otherwise.

Improvements on this code welcomed/encouraged... as I mentioned elsewhere, I am a humanities/social sciences person, not a programmer...
  • Tried to embed this, but it didn't seem to work.

    https://gist.github.com/839783
  • Did you activate the macro by putting it in the bibliography?
    Mine is in the very last line before the </layout> tag:

    <text prefix=" " macro="access" suffix="."/>
  • delete
    <else-if variable="issued" match="any"/>
    it doesn't do anything and might actually not be valid.


    also
    <group prefix="Available at ">
    <text variable="URL"></text>
    </group>

    is fine, but the same thing more quickly is
    <text variable="URL" prefix="Available at "/>

    (whether the URL gets included w/o the box checked depends on whether or not there is a page range given).
  • I did a little more refining of my style, taking into account the comments/suggestions made here. Below is a link to the current version, which validates in 1.0 and seems to work like a charm. I was encountering a bug where it was tossing in a URL even if there was a DOI (plus there are situations in which a DOI may exist without a page range), so I re-coded to prevent that.

    git://gist.github.com/855140.git
  • @marionsd

    Thank you so much for your post. I was becoming mad, trying to understand why the URLs of article-journal didn't appear !
Sign In or Register to comment.