Adding a New Stylesheet
How to add new stylesheet and make it appear "Choose output style" drop down list.
NOTE: At present this can only be done by uploading stylesheet file to a designated directory. In the future we are hoping to allow for external stylesheets to be included via a url.
1.Include the following bit of code in your stylesheet:
<!-- begin including code -->
<xsl:comment>
<!-- name (desc.) that will appear in dropdown list -->
[name]Name of style[/name]
<!-- match the name of the stylesheet (no extention)-->
[output]filename[/output]
</xsl:comment>
<!-- end including code -->
For example, we have a stylesheet that renders text in Harvard Output Style, and the file is called newharvard.xsl. We will use the following bit of text:
[name]Harvard Output Style[/name]
[output]newharvard[/output]
Name of the stylesheet will appear in the dropdown list, filename will be referenced upon its selection.
2. Place file in "stylesheets" directory of heurist folder.
*See instructions below (in detail) for creating stylesheets.
Harvard.xsl (a simple stylesheet)
http://heuristscholar.org/heurist/stylesheets/harvard.xsl
The stylesheet code has been broken in chunks, with explanatory comments below each chunk
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
Stylesheet header. Note that at present we only support XSLT version 1.0
<xsl:include href="helpers/months.xsl"/>
<xsl:include href="helpers/creator.xsl"/>
Formatting templates included (optional).
Months template converts numbers to their text equivalent.
Creator template trims first names to produce initials.
If you choose to leave them out, make sure you replace any calls to those templates (<xsl:call-template name="creator"/> or <xsl:call-template name="months">) throughout the code with <xsl:value-of select="."/>
<xsl:template match="/">
Opening of main (matching all) template
<!-- use the following bit of code to include the stylesheet to display it in Heurist publishing wizard
otherwise it will be ommited-->
<!-- begin including code -->
<xsl:comment>
<!-- name (desc.) that will appear in dropdown list --> [name]Harvard style
bibliography[/name] <!-- match the filename--> [output]harvard[/output] </xsl:comment>
<!-- end including code -->
As described in the comments, the following bit of code tells Heurist to include the stylesheet in its dropdown list of styles.Name must be nested within [name] tag and filename in [output] tag.
<html>
<head>
<style type="text/css">
body {font-family:Verdana,Helvetica,Arial,sans-serif; font-size:11px; }
td { vertical-align: top; padding-bottom: 7px; }
</style>
</head>
<body>
<xsl:attribute name="pub_id">
<xsl:value-of select="/export/@pub_id"/>
</xsl:attribute>
<table>
<xsl:apply-templates select="export/references/reference"/>
</table>
</body>
</html>
</xsl:template>
The rest of the main template. This templates renders the body of the page, <xsl:apply-templates select="export/references/reference"/> calls the record type template(s)
<!-- ================= 42: ARCHIVE RECORD =============================== -->
<xsl:template name="archive" match="reference[reftype/@id=42]">
<tr>
<td>
<!-- if Title are missing, don't print -->
<xsl:if test="detail[@id='160']">
<!-- author(s), year and title -->
<xsl:apply-templates select="pointer[@id=158]" mode="process-creator"/>
<xsl:if test="detail[@id='159']">  <xsl:value-of select="detail[@id = '159']"/>, </xsl:if>
<i>  <xsl:value-of select="detail[@id = '160']"/>
</i>
<!-- type of work -->
<xsl:if test="detail[@id = '175']"> [<xsl:value-of select="detail[@id = '175']"/>].
</xsl:if>
<xsl:if test="detail[@id=187]">
 <xsl:value-of select="detail[@id=187]/@type"/>: <xsl:value-of select="detail[@id=187]"/>.
</xsl:if>
<xsl:if test="detail[@id=198]">
 <xsl:value-of select="detail[@id=198]/@type"/>: <xsl:value-of select="detail[@id=198]"/>.
</xsl:if>
<xsl:if test="url!=''">
 <a href="{url}" target="_blank">web</a>
</xsl:if>
<xsl:call-template name="output_weblink"/>
</xsl:if>
</td>
</tr>
</xsl:template>
Record Type - specific template (as indicated by "match" attribute value "reference[reftype/@id=42]"). Within the template, pointers and details are rendered between appropriate HTML tags and characters.
<!-- ================= DEFAULT =============================== -->
<xsl:template name="default" match="reference">
<tr>
<td>
<xsl:if test="pointer[@id=158] != ''">
<!-- creator -->
<xsl:apply-templates select="pointer[@id=158]" mode="process-creator"/>
</xsl:if>
<xsl:if test="detail[@id=159]">
<!-- year -->  <xsl:value-of select="detail[@id=159]"/>, </xsl:if>
<!-- title -->  <xsl:if test="detail[@id=160] != ''">
<i>
<xsl:value-of select="detail[@id=160]"/>
</i> </xsl:if>
<xsl:if test="detail[@id=187]">
 <xsl:value-of select="detail[@id=187]/@type"/>: <xsl:value-of select="detail[@id=187]"/>.
</xsl:if>
<xsl:if test="detail[@id=198]">
 <xsl:value-of select="detail[@id=198]/@type"/>: <xsl:value-of select="detail[@id=198]"/>.
</xsl:if>
<xsl:if test="url!=''">
 <a href="{url}" target="_blank">web</a>
</xsl:if>
<xsl:call-template name="output_weblink"/> [no bibliographic data] </td>
</tr>
</xsl:template>
This template is important, as it is a generic template for all record types that haven't had a template constructed for them explicitly. (Note the "match" attribute equals "reference"only, as opposing to the template above).
The call to output_weblink template (<xsl:call-template name="output_weblink"/>) is also optional and can be replaced with <xsl:value-of select="detail[@id={ID}]"/> with required HTML.
In this stylesheet the order of templates within it is irrelevant.
<!-- ================= HELPER TEMPLATES =============================== -->
<!-- modify series that have no value with more appropriate "unknown series" -->
<xsl:template match="pointer">
<xsl:choose>
<xsl:when test="contains(title, '(series =)')">
<xsl:variable name="series">(series =)</xsl:variable>
<xsl:variable name="newseries">(series = Unknown Series)</xsl:variable>
<xsl:value-of select="substring-before(title, $series)"/>
<xsl:value-of select="$newseries"/>
<xsl:value-of select="substring-after(title, $series)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="title"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="pointer" mode="process-creator">
<!-- for more then 1 author, output authors in the following format: Author 1, Author 2 & Author 3 -->
<xsl:choose>
<xsl:when test="count(../pointer[@id=158]) >1">
<xsl:choose>
<xsl:when test="position()=last()"> & <xsl:call-template name="creator"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="position()=last()-1">
<xsl:call-template name="creator"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="creator"/>, </xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="creator"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="date">
<!-- template for date format -->
<xsl:param name="num_var"/>
<xsl:value-of select="format-number($num_var, '##-##-####')"/>
</xsl:template>
<xsl:template name="date_form" mode="date" match="detail">
<xsl:value-of select="day"/> <xsl:call-template name="months">
<xsl:with-param name="mnth">
<xsl:value-of select="month"/>
</xsl:with-param>
</xsl:call-template> <xsl:value-of select="year"/>
</xsl:template>
<xsl:template name="output_weblink">
<!-- this template chooses to apply weblink rendering tempate (see below) for images, files and links, based on the appropriate detail types -->
<xsl:if test="detail[@id=221] ">
<xsl:apply-templates mode="weblink_content" select="detail[@id=221]"/>
</xsl:if>
<xsl:if test="detail[@id=222] ">
<xsl:apply-templates mode="weblink_content" select="detail[@id=222]"/>
</xsl:if>
<xsl:if test="detail[@id=223] ">
<xsl:apply-templates mode="weblink_content" select="detail[@id=223]"/>
</xsl:if>
<xsl:if test="detail[@id=224] ">
<xsl:apply-templates mode="weblink_content" select="detail[@id=224]"/>
</xsl:if>
<xsl:if test="detail[@id=231] ">
<xsl:apply-templates mode="weblink_content" select="detail[@id=231]"/>
</xsl:if>
<xsl:if test="detail[@id=256] ">
<xsl:apply-templates mode="weblink_content" select="detail[@id=256]"/>
</xsl:if>
<xsl:if test="detail[@id=268] ">
<xsl:apply-templates mode="weblink_content" select="detail[@id=268]"/>
</xsl:if>
<xsl:if test="detail[@id=304] ">
<xsl:apply-templates mode="weblink_content" select="detail[@id=304]"/>
</xsl:if>
</xsl:template>
<xsl:template name="weblink_content" match="detail" mode="weblink_content">
<!-- this template renders web links for images, pdf files and other files -->
<xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:variable name="filename">
<xsl:value-of select="translate(file_orig_name, $ucletters, $lcletters)"/>
</xsl:variable>
<xsl:if test="$filename">
<xsl:choose>
<xsl:when
test="contains($filename, '.png') or contains($filename, '.gif') or contains($filename, '.jpg') or contains($filename, '.jpeg') or contains($filename, '.bmp')">
 <a href="{file_fetch_url}" target="_blank">image</a> </xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains($filename, '.pdf')">
 <a href="{file_fetch_url}" target="_blank">pdf</a></xsl:when>
<xsl:otherwise>
 <a href="{file_fetch_url}" target="_blank">file</a> </xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
These "helper" templates tidy up the layout by further formatting the output. Their purpose is outlined in comments within the templates. The
</xsl:stylesheet>
Closing tag of the styleseet.
wiki-simpe.xsl (a very simple stylesheet)
http://heuristscholar.org/heurist/stylesheets/wiki-simple.xsl
(The similar approach is used in stylesheets for Archaeology website, main one called reftype_renderer.xsl)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<!-- use the following bit of code to include the stylesheet to display it in Heurist publishing wizard
otherwise it will be ommited-->
<!-- begin including code -->
<xsl:comment>
<!-- name (desc.) that will appear in dropdown list -->
[name]PBwiki[/name]
<!-- match the name of the stylesheet-->
[output]wiki-simple[/output]
</xsl:comment>
<!-- end including code -->
<html>
<head>
<style type="text/css">
body {font-family:Verdana,Helvetica,Arial,sans-serif; font-size:11px; }
td { vertical-align: top; }
#displaycontent table td {
border:0px;
}
</style>
</head>
<body>
<xsl:attribute name="pub_id">
<xsl:value-of select="/export/@pub_id"/>
</xsl:attribute>
<table border="0" >
<xsl:apply-templates select="export/references/reference"/>
</table>
</body>
</html>
</xsl:template>
The beginning contains the header, including code and main template which are almost identical to harvard.xsl
<xsl:template match="reference">
<tr><td style="padding-bottom: 8px;">
<xsl:if test="detail[@id='160']">
<b>
<xsl:choose>
<xsl:when test="url != ''">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="url"/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:call-template name="print_consolidated_title"></xsl:call-template>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="print_consolidated_title"></xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</b>
<br></br>
<a style=" font-family:Verdana,Helvetica,Arial,sans-serif; font-size:10px;" target="_new" href="wiki/{id}">[view details]</a> <a style=" font-family:Verdana,Helvetica,Arial,sans-serif; font-size:10px;" target="_new"
href="/heurist/edit?bib_id={id}">[edit]</a>
</xsl:if>
</td></tr>
</xsl:template>
The reference- matching template matches all references regardless of their record type. This behaviour, of course, can be overridden with record type-specific templates, as it is done in harvard.xsl. Note that the web link <a style=" font-family:Verdana,Helvetica,Arial,sans-serif; font-size:10px;" target="_new" href="wiki/{id}"> is ancored to a page, that will be rendered with another stylesheet called wiki.xsl, with an {id} parameter passed to it.
<xsl:template name="print_consolidated_title">
<xsl:value-of select="title"/>
</xsl:template>
</xsl:stylesheet>
A little helper template (a call to which can easily be replaced by <xsl:value-of select="title"/>), the closing stylesheet tag, est voila!
wiki.xsl (a sister stylesheet of wiki-simple.xsl)
http://heuristscholar.org/heurist/stylesheets/wiki.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="arg"/>
<xsl:template match="/">
<html>
<head>
<style type="text/css">
body {font-family:Verdana,Helvetica,Arial,sans-serif; font-size:12px; background: #EAF3D9;}
td { vertical-align: top; }
a:hover {
text-decoration:none;
}
a {
color:#0367AD;
text-decoration:underline;
}
.reftype {
color: #999999;
padding-right: 10px;
}
</style>
</head>
<body>
<xsl:attribute name="pub_id">
<xsl:value-of select="/export/@pub_id"/>
</xsl:attribute>
<table border="0" >
<xsl:choose>
<xsl:when test="number($arg) > 0">
<xsl:apply-templates select="export/references/reference[id=$arg]"/>
</xsl:when>
<xsl:when test="string(number($arg)) = 'NaN'">
<xsl:apply-templates select="export/references/reference">
<xsl:with-param name="style" select="$arg"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="export/references/reference"/>
</xsl:otherwise>
</xsl:choose>
</table>
</body>
</html>
</xsl:template>
The header, minus including code (that is because the wiki.xsl is not to be called from the dropdown list in heurist publishing wizard, but instead it is called from page rendered with wiki-simple.xsl, see example above). Also note <xsl:param name="arg"/> which is a url parameter passed from page rendered with wiki-simple.xsl (recall the link href="wiki/{id}).
Further down in the main template in the select statement (highlighted) a record (reference) with specified id is matched.
<xsl:template match="reference">
<tr>
<td>
<xsl:if test="detail[@id='160']">
<!--logo image -->
<xsl:if test="detail[@id=222]">
<div style="float: right;">
<xsl:for-each select="detail[@id=222]">
<img src="{file_thumb_url}"/>
</xsl:for-each>
</div>
</xsl:if>
<b>
<xsl:choose>
<xsl:when test="url != ''">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="url"/>
</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:call-template name="print_title"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="print_title"/>
</xsl:otherwise>
</xsl:choose>
</b>
<br/>
<a style=" font-family:Verdana,Helvetica,Arial,sans-serif; font-size:10px;"
target="_new" href="wiki/{id}">[view details]</a> <a
style=" font-family:Verdana,Helvetica,Arial,sans-serif; font-size:10px;"
target="_new" href="/heurist/edit?bib_id={id}">
[edit] </a>
<br/>
<xsl:if
test="pointer[@id=244]/detail[@id=160] or detail[@id='181'] or detail[@id=277]">
<xsl:call-template name="organisation">
<xsl:with-param name="parent-org">
<xsl:value-of select="pointer[@id=244]/detail[@id=160]"/>
</xsl:with-param>
<xsl:with-param name="location">
<xsl:value-of select="detail[@id='181']"/>
</xsl:with-param>
<xsl:with-param name="country">
<xsl:value-of select="detail[@id=277]"/>
</xsl:with-param>
</xsl:call-template>
<br/>
</xsl:if>
<xsl:value-of select="detail[@id='303']"/>
</xsl:if>
</td>
</tr>
<tr>
<td>  </td>
</tr>
</xsl:template>
<!-- detail output template -->
<xsl:template match="reference[id=$arg]">
<tr>
<td class="reftype">
<img>
<xsl:attribute name="src">http://heuristscholar.org/reftype/<;xsl:value-of
select="reftype/@id"/>.gif</xsl:attribute>
</img>
</td>
<td style="font-weight: bold;">
<a style="float: right;" target="_new"
href="/heurist/bibedit.php?bib_id={id}">
<img style="border: none;"
src="/heurist/edit_pencil_16x16.gif"/>
</a>
<xsl:value-of select="title"/>
</td>
</tr>
<tr>
<td class="reftype">
<nobr>Reference type</nobr>
</td>
<td>
<xsl:value-of select="reftype"/>
</td>
</tr>
<xsl:if test="url != ''">
<tr>
<td class="reftype">URL</td>
<td>
<a href="{url}">
<xsl:choose>
<xsl:when test="string-length(url) > 50">
<xsl:value-of select="substring(url, 0, 50)"/> ... </xsl:when>
<xsl:otherwise>
<xsl:value-of select="url"/>
</xsl:otherwise>
</xsl:choose>
</a>
</td>
</tr>
</xsl:if>
<xsl:if test="detail[@id=203]">
<!--organisation type -->
<tr>
<td class="reftype">
<xsl:call-template name="title_grouped">
<xsl:with-param name="name">
<xsl:value-of select="detail[@id=203]/@name"/>
</xsl:with-param>
<xsl:with-param name="type">
<xsl:value-of select="detail[@id=203]/@type"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td>
<xsl:for-each select="detail[@id=203]">
<xsl:value-of select="."/>
<br/>
</xsl:for-each>
</td>
</tr>
</xsl:if>
<!-- list reftypes and data-->
<xsl:for-each select="detail[@id!=222 and @id!=223 and @id!=224 and @id!=203]">
<tr>
<td class="reftype">
<nobr>
<xsl:choose>
<xsl:when test="string-length(@name)">
<xsl:value-of select="@name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@type"/>
</xsl:otherwise>
</xsl:choose>
</nobr>
</td>
<td>
<xsl:choose>
<!-- 268 = Contact details URL, 256 = Web links -->
<xsl:when test="@id=268 or @id=256 or starts-with(text(), 'http')">
<a href="{text()}">
<xsl:choose>
<xsl:when test="string-length() > 50">
<xsl:value-of select="substring(text(), 0, 50)"/> ... </xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()"/>
</xsl:otherwise>
</xsl:choose>
</a>
</xsl:when>
<!-- 221 = AssociatedFile, 231 = Associated File -->
<xsl:when test="@id=221 or @id=231">
<a href="{file_fetch_url}">
<xsl:value-of select="file_orig_name"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()"/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
<!-- director-->
<tr>
<td class="reftype">
<xsl:call-template name="title_grouped">
<xsl:with-param name="name">
<xsl:value-of select="pointer[@id=315]/@name"/>
</xsl:with-param>
<xsl:with-param name="type">
<xsl:value-of select="pointer[@id=315]/@type"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td>
<xsl:apply-templates select="pointer[@id=315]"/>
</td>
</tr>
<!-- staff-->
<tr>
<td class="reftype">
<xsl:call-template name="title_grouped">
<xsl:with-param name="name">
<xsl:value-of select="pointer[@id=316]/@name"/>
</xsl:with-param>
<xsl:with-param name="type">
<xsl:value-of select="pointer[@id=316]/@type"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td>
<xsl:apply-templates select="pointer[@id=316]"/>
</td>
</tr>
<!-- research projects-->
<tr>
<td class="reftype">
<xsl:call-template name="title_grouped">
<xsl:with-param name="name">
<xsl:value-of select="pointer[@id=264]/@name"/>
</xsl:with-param>
<xsl:with-param name="type">
<xsl:value-of select="pointer[@id=264]/@type"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td>
<xsl:apply-templates select="pointer[@id=264]"/>
</td>
</tr>
<xsl:if test="notes != ' ' ">
<tr>
<td class="reftype">Notes</td>
<td>
<xsl:value-of select="notes"/>
</td>
</tr>
</xsl:if>
<xsl:if test="detail[@id=222 or @id=223 or @id=224]">
<tr>
<td class="reftype">Images</td>
<td>
<!-- 222 = Logo image, 223 = Thumbnail, 224 = Images -->
<xsl:for-each select="detail[@id=222 or @id=223 or @id=224]">
<a href="{file_fetch_url}">
<img src="{file_thumb_url}" border="0"/>
</a>    </xsl:for-each>
</td>
</tr>
</xsl:if>
</xsl:template>
The generic reference-match template as well as the referene match with $arg parameter provided
<xsl:template match="pointer">
<xsl:call-template name="content_group"/>
</xsl:template>
<xsl:template name="content_group">
<xsl:choose>
<xsl:when test="url !='' ">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="url"/>
</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="title"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="title"/>
</xsl:otherwise>
</xsl:choose>
<br/>
</xsl:template>
<xsl:template name="title_grouped">
<xsl:param name="name"/>
<xsl:param name="type"/>
<nobr>
<xsl:choose>
<xsl:when test="string-length($name)">
<xsl:value-of select="$name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$type"/>
</xsl:otherwise>
</xsl:choose>
</nobr>
</xsl:template>
<xsl:template name="print_title">
<xsl:choose>
<xsl:when test="detail[@id='179']">
<xsl:choose>
<!-- output acronym if its not already part of the title -->
<xsl:when test="contains(detail[@id='160'], detail[@id='179'])">
<xsl:value-of select="detail[@id='160']"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="detail[@id='160']"/> (<xsl:value-of
select="detail[@id = '179']"/>) </xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="detail[@id = '160']"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="organisation">
<xsl:param name="parent-org"/>
<xsl:param name="location"/>
<xsl:param name="country"/>
<xsl:if test="$parent-org">
<xsl:value-of select="$parent-org"/>,  </xsl:if>
<xsl:if test="$location">
<xsl:value-of select="$location"/>,  </xsl:if>
<xsl:if test="$country">
<xsl:value-of select="$country"/>,  </xsl:if>
</xsl:template>
</xsl:stylesheet>
"Helper" templates and stylesheet closing tag.