Autogenerating BibTeX citations from ISBN

Looks like it can be done via WorldCat‘s xisbn API.

My approach is something like this:
foo:~ $ curl 'http://xisbn.worldcat.org/webservices/xid/isbn/0521288843?method=getMetadata&format=xml&fl=year,ed,title,author,publisher,city'

which returns an XML block like the following:

<?xml version="1.0" encoding="UTF-8"?>
<rsp xmlns="http://worldcat.org/xid/isbn/" stat="ok">
      <isbn   year="1986" ed="11th printing." title="Evolution and the theory of games"  author="John Maynard Smith."  publisher="Cambridge Univ. Press"  city="Cambridge [u.a.]"   >0521288843</isbn>

A little XSLT, such as that below:

book2bib.xsl

    1 <?xml version="1.0"?>
    2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wc="http://worldcat.org/xid/isbn/" version="1.0">
    3     <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
    4     <xsl:template match="wc:isbn">
    5         <code>
    6     @BOOK{CiteKeyGoesHere,
    7         AUTHOR = "<xsl:value-of select="@author"/>",
    8         TITLE = "<xsl:value-of select="@title"/>",
    9         PUBLISHER = "<xsl:value-of select="@publisher"/>",
   10         ADDRESS = "<xsl:value-of select="@city"/>",
   11         YEAR ="<xsl:value-of select="@year"/>"}
   12 </code>
   13     </xsl:template>
   14 </xsl:stylesheet>
   15

…emits the following:


@BOOK{CiteKeyGoesHere,
AUTHOR = "John Maynard Smith.",
TITLE = "Evolution and the theory of games",
PUBLISHER = "Cambridge Univ. Press",
ADDRESS = "Cambridge [u.a.]",
YEAR ="1986"}

The user will need to supply her own citation key, but many bibliography management tools (such as BibDesk) will do this, or you can use the bibtexformat perl script to insert them for you.

Here’s the whole deal in action. Creating a shell script which takes the ISBN as a parameter and plugs it into something like the following is left as an exercise for the reader.
$ curl -s 'http://xisbn.worldcat.org/webservices/xid/isbn/0521288843?method=getMetadata&format=xml&fl=year,ed,title,author,publisher,city' | xsltproc ~/Dev/book2bib.xsl -

@BOOK{CiteKeyGoesHere,
AUTHOR = “John Maynard Smith.”,
TITLE = “Evolution and the theory of games”,
PUBLISHER = “Cambridge Univ. Press”,
ADDRESS = “Cambridge [u.a.]”,
YEAR =”1986″}

Advertisements
This entry was posted in Books, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s