OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: MHRA and Docbook XSL


Hi All,
     I just wanted to let everyone know that I have written up a first
crack at MHRA styling in footnotes for Docbook.  It took me a bit to
get back into the swing of XSLT but progress has been made.  I am not
sure if it is proper netiquette but I have attached a copy of the
current working version to my email.
     There are a few limitations at the moment.  Everything is linked
to the book tag at the top of the document and thus can only support
books at the moment.  This is because I couldn't use the ancestor axis
to match the linkend attribute of the biblioref tag to something in
the bibliography as the bibliography is not an ancestor (it is an
ancestral sibling).  I am casting about for ways to allow articles to
join the fun.  Also at the moment, the style only supports three types
of entries: books, journal articles, and articles in a book (called
incollection after BibTeX).  I will probably add other types of
entries as the need arises.  The last thing is that this only supports
output to XSL:FO, which means it only goes to PDF.  I will be working
on other formats once I have doing this in PDF down.
     Anyway, if anyone has any thoughts or feedback, I would be very
grateful to hear them.  Also, I can provide an example bibliography on
request.  Thank you very much for your time.

All the best,
Chris Yocum
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
		xmlns:fo="http://www.w3.org/1999/XSL/Format";
		xmlns:d="http://docbook.org/ns/docbook";
		exclude-result-prefixes="d">

<xsl:template match="biblioref">
  <xsl:variable name="linkend" select="@linkend" />
  <xsl:choose>
    <xsl:when test="/book/bibliography/biblioentry[@id=$linkend]/biblioset[@relation='article']">
      <xsl:call-template name="MHRA.article-ref" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="MHRA.book-ref" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="MHRA.book-ref">
  <xsl:variable name="linkend" select="@linkend" />
  <xsl:variable name="bibentry" select="/book/bibliography/biblioentry[@id=$linkend]" />

  <xsl:choose>
    <xsl:when test="preceding-sibling::biblioref[@linkend=$linkend]">
      <xsl:call-template name="MHRA.book-ref-ibid" />
    </xsl:when>
    <xsl:when test="preceding::biblioref[@linkend=$linkend]">
      <xsl:call-template name="MHRA.book-ref-short" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="MHRA.book-ref-full" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="MHRA.book-ref-ibid">
  <xsl:variable name="linkend" select="@linkend" />
  <xsl:variable name="bibentry" select="/book/bibliography/biblioentry[@id=$linkend]" />

  <xsl:text>ibid., </xsl:text>
  
  <xsl:choose>
    <xsl:when test="@begin=@end">
      <xsl:text>, p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="@begin and not(@end)">
      <xsl:text>, p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="not(@begin) and @end">
      <xsl:text>, p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="@begin and @end">
      <xsl:text>, pp. </xsl:text><xsl:value-of select="@begin" /><xsl:text>-</xsl:text><xsl:value-of select="@end" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>.</xsl:text>
    </xsl:otherwise>
  </xsl:choose>

  <xsl:text>.</xsl:text>
</xsl:template>

<xsl:template name="MHRA.book-ref-short">
  <xsl:variable name="linkend" select="@linkend" />
  <xsl:variable name="bibentry" select="/book/bibliography/biblioentry[@id=$linkend]" />

  <xsl:value-of select="$bibentry/author/surname" />
  <xsl:text>, </xsl:text>
  <fo:inline font-style="italic">
    <xsl:value-of select="$bibentry/title" />
  </fo:inline>

  <xsl:choose>
    <xsl:when test="@begin=@end">
      <xsl:text>, p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="@begin and not(@end)">
      <xsl:text>, p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="not(@begin) and @end">
      <xsl:text>, p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="@begin and @end">
      <xsl:text>, pp. </xsl:text><xsl:value-of select="@begin" /><xsl:text>-</xsl:text><xsl:value-of select="@end" />
    </xsl:when>
  </xsl:choose>

  <xsl:text>.</xsl:text>  
</xsl:template>

<xsl:template name="MHRA.book-ref-full">
  <xsl:variable name="linkend" select="@linkend" />
  <xsl:variable name="bibentry" select="/book/bibliography/biblioentry[@id=$linkend]" />
  
  <xsl:choose>
    <xsl:when test="$bibentry/authorgroup">
      <xsl:for-each select="$bibentry/authorgroup/author">
	<xsl:value-of select="$bibentry/author/personname/firstname" />
	<xsl:text> </xsl:text>
	<xsl:value-of select="$bibentry/author/personname/surname" />
	
	<xsl:if test="not(last())">
	  <xsl:text> and </xsl:text>
	</xsl:if>
      </xsl:for-each>
    </xsl:when>
    
    <xsl:otherwise>
      <xsl:value-of select="$bibentry/author/personname/firstname" />
      <xsl:text> </xsl:text>
      <xsl:value-of select="$bibentry/author/personname/surname" />
    </xsl:otherwise>
  </xsl:choose>
  <xsl:text>, </xsl:text>
  <fo:inline font-style="italic">
    <xsl:value-of select="$bibentry/title" />
    <xsl:if test="$bibentry/subtitle">
      <xsl:text>: </xsl:text>
      <xsl:value-of select="$bibentry/subtitle" />
    </xsl:if>
  </fo:inline>
  <xsl:text> (</xsl:text>
  <xsl:value-of select="$bibentry/address" />
  <xsl:text>: </xsl:text>
  <xsl:value-of select="$bibentry/publishername" />
  <xsl:text>, </xsl:text>
  <xsl:value-of select="$bibentry/copyright/year" />
  <xsl:text>)</xsl:text>

  <xsl:choose>
    <xsl:when test="@begin=@end">
      <xsl:text>, p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="@begin and not(@end)">
      <xsl:text>, p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="not(@begin) and @end">
      <xsl:text>, p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="@begin and @end">
      <xsl:text>, pp. </xsl:text><xsl:value-of select="@begin" /><xsl:text>-</xsl:text><xsl:value-of select="@end" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>.</xsl:text>
    </xsl:otherwise>
  </xsl:choose>

</xsl:template>

<xsl:template name="MHRA.article-ref">
  <xsl:variable name="linkend" select="@linkend" />
  <xsl:variable name="bibentry" select="/book/bibliography/biblioentry[@id=$linkend]" />
  
  <xsl:choose>
    <xsl:when test="preceding-sibling::biblioref[@linkend=$linkend]">
      <xsl:call-template name="MHRA.article-ibid" />
    </xsl:when>

    <xsl:when test="preceding::biblioref[@linkend=$linkend]">
      <xsl:call-template name="MHRA.article-short" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:choose>
	<xsl:when test="$bibentry/biblioset[@relation='journal']">
	  <xsl:call-template name="MHRA.article-ref-journal" />
	</xsl:when>
	
	<xsl:when test="$bibentry/biblioset[@relation='incollection']">
	  <xsl:call-template name="MHRA.article-ref-incollection" />
	</xsl:when>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="MHRA.article-ibid">
  <xsl:variable name="linkend" select="@linkend" />
  <xsl:variable name="bibentry" select="/book/bibliography/biblioentry[@id=$linkend]" />

  <xsl:text>ibid., </xsl:text>
  
  <xsl:choose>
    <xsl:when test="@begin=@end">
      <xsl:text>p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="@begin and not(@end)">
      <xsl:text>p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="not(@begin) and @end">
      <xsl:text>p. </xsl:text><xsl:value-of select="@begin" />
    </xsl:when>
    <xsl:when test="@begin and @end">
      <xsl:text>pp. </xsl:text><xsl:value-of select="@begin" /><xsl:text>-</xsl:text><xsl:value-of select="@end" />
    </xsl:when>
  </xsl:choose>

  <xsl:text>.</xsl:text>

</xsl:template>

<xsl:template name="MHRA.article-ref-journal">
  <xsl:variable name="linkend" select="@linkend" />
  <xsl:variable name="bibentry-article" select="/book/bibliography/biblioentry[@id=$linkend]/biblioset[@relation='article']" />
  <xsl:variable name="bibentry-journal" select="/book/bibliography/biblioentry[@id=$linkend]/biblioset[@relation='journal']" />

  <xsl:value-of select="$bibentry-article/author/personname/firstname" />
  <xsl:text> </xsl:text>
  <xsl:value-of select="$bibentry-article/author/personname/surname" />
  <xsl:text>, ‘</xsl:text>
  <xsl:value-of select="$bibentry-article/title" />
  <xsl:if test="$bibentry-article/subtitle" >
    <xsl:value-of select="$bibentry-article/subtitle" />
  </xsl:if>
  <xsl:text>’, </xsl:text>
  <fo:inline font-style="italic">
    <xsl:value-of select="$bibentry-journal/title" />
  </fo:inline>
  <xsl:text>, </xsl:text>
  <xsl:value-of select="$bibentry-journal/volumenum" />
  <xsl:text>(</xsl:text>
  <xsl:value-of select="$bibentry-journal/date" />
  <xsl:text>), </xsl:text>
  <xsl:value-of select="$bibentry-article/pagenums"/>

  <xsl:choose>
    <xsl:when test="@begin and @end">
      <xsl:text> (</xsl:text>
      <xsl:text>pp. </xsl:text>
      <xsl:value-of select="@begin" />
      <xsl:text>-</xsl:text>
      <xsl:value-of select="@end" />
      <xsl:text>)</xsl:text>
      <xsl:text>.</xsl:text>
    </xsl:when>

    <xsl:when test="@begin and not(@end)">
      <xsl:text> (</xsl:text>
      <xsl:text>p. </xsl:text>
      <xsl:value-of select="@begin" />
      <xsl:text>)</xsl:text>
      <xsl:text>.</xsl:text>
    </xsl:when>

    <xsl:when test="not(@begin) and @end">
      <xsl:text> (</xsl:text>
      <xsl:text>p. </xsl:text>
      <xsl:value-of select="@end" />
      <xsl:text>)</xsl:text>
      <xsl:text>.</xsl:text>
    </xsl:when>
  </xsl:choose>
</xsl:template>

<xsl:template name="MHRA.article-ref-incollection">
  <xsl:variable name="linkend" select="@linkend" />
  <xsl:variable name="bibentry-article" select="/book/bibliography/biblioentry[@id=$linkend]/biblioset[@relation='article']" />
  <xsl:variable name="bibentry-incollection" select="/book/bibliography/biblioentry[@id=$linkend]/biblioset[@relation='incollection']" />

  <xsl:value-of select="$bibentry-article/author/personname/firstname" />
  <xsl:text> </xsl:text>
  <xsl:value-of select="$bibentry-article/author/personname/surname" />
  <xsl:text>, ‘</xsl:text>
  <xsl:value-of select="$bibentry-article/title" />
  <xsl:if test="$bibentry-article/subtitle">
    <xsl:text>: </xsl:text>
    <xsl-value-of select="$bibentry-article/subtitle" />
  </xsl:if>
  <xsl:text>’ in </xsl:text>
  <fo:inline font-style="italic">
    <xsl:value-of select="$bibentry-incollection/title" />
  </fo:inline>
  <xsl:text>, ed. by </xsl:text>

  <xsl:choose>
    <xsl:when test="$bibentry-incollection/authorgroup">
      <xsl:for-each select="$bibentry-incollection/authorgroup/editor">
	<xsl:value-of select="$bibentry-incollection/editor/personname/firstname" />
      <xsl:text> </xsl:text>
      <xsl:value-of select="$bibentry-incollection/editor/personname/surname" />
      </xsl:for-each>
      <xsl:if test="not(last())">
	<xsl:text> and </xsl:text>
      </xsl:if>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$bibentry-incollection/editor/personname/firstname" />
      <xsl:text> </xsl:text>
      <xsl:value-of select="$bibentry-incollection/editor/personname/surname" />
    </xsl:otherwise>
  </xsl:choose>

  <xsl:text> (</xsl:text>
  <xsl:value-of select="$bibentry-incollection/address" />
  <xsl:text>: </xsl:text>
  <xsl:value-of select="$bibentry-incollection/publishername" />
  <xsl:text>, </xsl:text>
  <xsl:value-of select="$bibentry-incollection/date" />
  <xsl:text>), pp. </xsl:text>
  <xsl:value-of select="$bibentry-article/pagenums" />

  <xsl:choose>
    <xsl:when test="@begin and @end">
      <xsl:text> (pp. </xsl:text>
      <xsl:value-of select="@begin" />
      <xsl:text>-</xsl:text>
      <xsl:value-of select="@end" />
      <xsl:text>).</xsl:text>
    </xsl:when>
    <xsl:when test="@begin and not(@end)">
      <xsl:text> (p. </xsl:text>
      <xsl:value-of select="@begin" />
      <xsl:text>).</xsl:text>
    </xsl:when>
    <xsl:when test="@begin=@end">
      <xsl:text> (p. </xsl:text>
      <xsl:value-of select="@begin" />
      <xsl:text>).</xsl:text>
    </xsl:when>
    <xsl:when test="not(@begin) and @end">
      <xsl:text> (p. </xsl:text>
      <xsl:value-of select="@end" />
      <xsl:text>).</xsl:text>
    </xsl:when>
  </xsl:choose>
</xsl:template>
</xsl:stylesheet>


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]