📄 bookcase2bibtex.xsl
字号:
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bc="http://periapsis.org/bookcase/" xmlns:str="http://exslt.org/strings" extension-element-prefixes="str" version="1.0"><!-- ================================================================ Bookcase XSLT file - used for exporting to bibtex format $Id: bookcase2bibtex.xsl,v 1.12 2003/03/22 02:22:53 robby Exp $ Copyright (c) 2003 Robby Stephenson This XSLT stylesheet is designed to be used with XML data files from the 'Bookcase' application, which can be found at: http://www.periapsis.org/bookcase/ ================================================================--><!-- is this the right mimetype? maybe text/bib? --><xsl:output method="text" media-type="text/x-bibtex"/><xsl:strip-space elements="*"/><xsl:param name="version"/><xsl:variable name="current-syntax" select="'2'"/><!--make lowercase easier --><xsl:variable name="lc" select="'abcdefghijklmnopqrstuvwxyz'"/><xsl:variable name="uc" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/><xsl:variable name="endl"><xsl:text></xsl:text></xsl:variable><xsl:template match="/"> <xsl:text>@COMMENT{Generated by Bookcase </xsl:text> <xsl:value-of select="$version"/> <xsl:text>}</xsl:text> <xsl:value-of select="$endl"/> <xsl:apply-templates select="bc:bookcase"/></xsl:template><xsl:template match="bc:bookcase"> <xsl:if test="not(@syntaxVersion = $current-syntax)"> <xsl:message> <xsl:text>This stylesheet was designed for Bookcase DTD version </xsl:text> <xsl:value-of select="$current-syntax"/> <xsl:text>,</xsl:text> <xsl:value-of select="$endl"/> <xsl:text>but the data file is version </xsl:text> <xsl:value-of select="@syntaxVersion"/> <xsl:text>.</xsl:text> </xsl:message> </xsl:if> <xsl:apply-templates select="bc:collection/bc:book"/></xsl:template><xsl:template match="bc:book"> <!-- year might have multiple values, show publication year is present otherwise, show first copyright year --> <xsl:variable name="year"> <xsl:choose> <xsl:when test="bc:pub_year"> <xsl:value-of select="bc:pub_year"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="bc:cr_years/bc:cr_year[1]"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:text>@book{</xsl:text> <xsl:choose> <xsl:when test="bc:bibtex-id"> <xsl:value-of select="bc:bibtex-id"/> </xsl:when> <xsl:otherwise> <xsl:call-template name="make-key"> <xsl:with-param name="author" select="bc:authors/bc:author[1]"/> <xsl:with-param name="title" select="bc:title"/> <xsl:with-param name="year" select="$year"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'author'"/> <xsl:with-param name="field-value"> <xsl:for-each select="bc:authors/bc:author"> <xsl:value-of select="."/> <xsl:if test="not(position() = last())"> <xsl:text> and </xsl:text> </xsl:if> </xsl:for-each> </xsl:with-param> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'title'"/> <xsl:with-param name="field-value" select="bc:title"/> </xsl:call-template> <!-- TODO: format this correctly, should be an ordinal with first letter capitalized --> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'edition'"/> <xsl:with-param name="field-value" select="bc:edition"/> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'publisher'"/> <xsl:with-param name="field-value" select="bc:publisher"/> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'year'"/> <xsl:with-param name="field-value" select="$year"/> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'isbn'"/> <xsl:with-param name="field-value" select="bc:isbn"/> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'lccn'"/> <xsl:with-param name="field-value" select="bc:lccn"/> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'series'"/> <xsl:with-param name="field-value" select="bc:series"/> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'number'"/> <xsl:with-param name="field-value" select="bc:series_num"/> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'keywords'"/> <xsl:with-param name="field-value"> <xsl:for-each select="bc:keywords/bc:keyword"> <xsl:value-of select="translate(., $uc, $lc)"/> <xsl:if test="not(position() = last())"> <xsl:text>, </xsl:text> </xsl:if> </xsl:for-each> </xsl:with-param> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'language'"/> <xsl:with-param name="field-value"> <xsl:for-each select="bc:languages/bc:language"> <xsl:value-of select="translate(., $uc, $lc)"/> <xsl:if test="not(position() = last())"> <xsl:text>, </xsl:text> </xsl:if> </xsl:for-each> </xsl:with-param> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'price'"/> <xsl:with-param name="field-value" select="bc:price"/> </xsl:call-template> <xsl:call-template name="bibtex-line"> <xsl:with-param name="field-name" select="'note'"/> <xsl:with-param name="field-value" select="bc:comments"/> </xsl:call-template> <xsl:value-of select="$endl"/> <xsl:text>}</xsl:text> <xsl:value-of select="$endl"/></xsl:template><!-- TODO: figure out how to make this unique --><!-- format is (last name of first author)-(initials of title)(year) --><xsl:template name="make-key"> <xsl:param name="author"/> <xsl:param name="title"/> <xsl:param name="year"/> <xsl:variable name="word1"> <xsl:choose> <xsl:when test="contains($author, ',')"> <xsl:variable name="before-comma" select="substring-before($author, ',')"/> <xsl:variable name="words" select="str:tokenize($before-comma, ' ')"/> <xsl:value-of select="translate($words[last()], $uc, $lc)"/> </xsl:when> <xsl:otherwise> <xsl:variable name="words" select="str:tokenize($author, ' ')"/> <xsl:value-of select="translate($words[last()], $uc, $lc)"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="word2"> <xsl:for-each select="str:tokenize($title, ' ')"> <xsl:value-of select="translate(substring(., 1, 1), $uc, $lc)"/> </xsl:for-each> </xsl:variable> <xsl:value-of select="concat($word1, '-', $word2, $year)"/></xsl:template><xsl:template name="bibtex-line"> <xsl:param name="field-name"/> <xsl:param name="field-value"/> <xsl:if test="normalize-space($field-value)"> <xsl:text>,</xsl:text> <xsl:value-of select="$endl"/> <xsl:text> </xsl:text> <xsl:value-of select="$field-name"/> <xsl:text> = {</xsl:text> <xsl:value-of select="normalize-space($field-value)"/> <xsl:text>}</xsl:text> </xsl:if></xsl:template></xsl:stylesheet><!-- Local Variables: --><!-- sgml-indent-step: 1 --><!-- sgml-indent-data: 1 --><!-- End: -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -