State Abbreviations

Feb 21, 2012 at 3:39 AM

This might require quite a bit of fiddling by those who know what they're doing, but: I was wondering if there was a way to incorporate automatic switching between the two styles for abbreviating (US) states. For example, Calif. vs. CA, or Mass. vs. MA. Some of my journals require one, some the other. I was thinking it could be done by setting up "look-up tables", perhaps from the full word to a choice of either of those two, and this could all be incorporated into an "option" paramater that you could attach to the "StateProvince" tag. But I don't know how to do any of this; I also don't know where I would put such code in the BibWord template. Any ideas?



Feb 21, 2012 at 6:06 AM

There already exists similar code for handling month names and source types.

If you download the template, you will find an xml part looking like:

        <month number="1">Jan</month>
        <!-- other months -->
        <month number="12">Dec</month>
        <sourcetype type="Art">Art</sourcetype>
        <!-- other source types -->
        <sourcetype type="SoundRecording">Sound Recording</sourcetype>

So you could add a <states> element with the necessary abbreviations. You would then have to write your own format-state template and call that. Something like:

  <state name="alabama">AL</state>
  <state name="california">CA</state>
  <!-- and so on -->

First the calling. Look for a piece of code like this:

<!-- Handle months and months accessed. -->
<xsl:when test="starts-with($name, 'Month') and string($source/*[local-name() = $name])">
  <xsl:call-template name="format-month">

Above it, add something like (untested):

<xsl:when test="$name = 'StateProvince' and string($source/b:StateProvince)">
  <xsl:variable name="state" select="$source/*[local-name() = $name]" />
  <xsl:value-of select="msxsl:node-set($data)/strings/states/state[@name = $state]"/>

You should extend this code to cover your needs: casing, what if names are missing or there is no match, what if you want to be able to disable if for some (option parameter), ...

Feb 21, 2012 at 6:36 PM

Thanks; I'll try that!