sort-order

I bought a license of Oxygen in the hopes it makes writing stylesheets
a bit easier. Anyway, I managed to figure out how to handle numbered
citations. Here’s a start.

First, a test doc:

<?xml version="1.0" encoding="utf-8"?> Test Introduction A citation with page number detail: . Some more citations: . A citation ... in a footnote .

… and the stylesheet:===

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xmlns:mods="http://www.loc.gov/mods/v3"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:db="http://docbook.org/docbook-ng"
xmlns:bib=“http://www.example.org/bib"
xmlns:exist=“http://exist.sourceforge.net/NS/exist"
exclude-result-prefixes=“db mods exist”>
<xsl:output method=“xhtml” encoding=“utf-8” indent=“yes”/>
<xsl:strip-space elements=”*”/>

<xsl:param name=“citeclass”>note</xsl:param>
<xsl:param name=“sort_order-bib”>cited</xsl:param>
<xsl:param name=“biboutfile”/>

<xsl:variable name=“citerefs” select="//db:biblioref/@linkend"/>
<xsl:variable name=“cite-position”>
bib:refs
bib:all
<xsl:for-each select="$citerefs">
<bib:ref position="{position()}" id="{generate-id()}“
key=”{.}"/>
</xsl:for-each>
</bib:all>
bib:unique
<xsl:for-each-group select="$citerefs" group-by=".">
<bib:ref position="{position()}" id="{generate-id()}“
key=”{.}"/>
</xsl:for-each-group>
</bib:unique>
</bib:refs>
</xsl:variable>

<xsl:variable name=“citekeys”>
xsl:text(</xsl:text>
<xsl:for-each-group select="$citerefs" group-by=".">
<xsl:if test=“position() > 1”>,%20</xsl:if>
xsl:text’</xsl:text>
<xsl:value-of select="."/>
xsl:text’</xsl:text>
</xsl:for-each-group>
xsl:text)</xsl:text>
</xsl:variable>

<xsl:variable name=“bibrecord"
select=“doc(concat(“http://localhost:8080/exist/servlet/db/biblio?
”,
”_query=declare%20namespace%20mods=%22http://www.loc.gov/mods/
v3%22;”, “%20for%20$citekey%20in%20”, $citekeys,

“%20return%20/mods:modsCollection/mods:
mods[@ID=$citekey]”))"/>

<xsl:variable name=“raw-biblist”>

<xsl:copy-of select="$bibrecord/exist:result/mods:mods"/>

</xsl:variable>

<xsl:variable name=“formatted-biblist”>
xsl:choose
<xsl:when test="$citeclass=‘note’">
<xsl:for-each
select="$raw-biblist/mods:modsCollection/mods:mods">
<xsl:variable name=“id” select="@ID" />
<xsl:variable name=“number”>
<xsl:value-of

select="$cite-position/bib:refs/bib:unique/bib:ref[@key=$id]/@position"
/>
</xsl:variable>
xsl:choose
<xsl:when test="$sort_order-bib=‘cited’">
xsl:perform-sort
<xsl:sort select="$number" />


<xsl:value-of select="$number" />
xsl:text. </xsl:text>
<xsl:apply-templates select=“mods:titleInfo”/>
<xsl:apply-templates select=“mods:name”/>


</xsl:perform-sort>
</xsl:when>
xsl:otherwise


<xsl:apply-templates select=“mods:titleInfo”/>
<xsl:apply-templates select=“mods:name”/>


</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:template match="/">


Testing




xsl:apply-templates/


<xsl:copy-of select="$formatted-biblist"/>




<xsl:if test="$biboutfile">
<xsl:result-document href="{$biboutfile}">
<xsl:copy-of select="$raw-biblist"/>
</xsl:result-document>
</xsl:if>
</xsl:template>
<xsl:template match=“mods:titleInfo”>

<xsl:apply-templates select=“mods:title”/>
<xsl:apply-templates select=“mods:subTitle”/>

</xsl:template>
<xsl:template match=“mods:title”>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match=“mods:subTitle”>
xsl:text: </xsl:text>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match=“mods:name”>
xsl:text, </xsl:text>

<xsl:apply-templates select=“mods:namePart[@type=‘family’]”/>

</xsl:template>
<xsl:template match=“mods:namePart”>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match=“db:article”>
<xsl:apply-templates select=“db:info”/>
<xsl:apply-templates select=“db:section”/>
</xsl:template>
<xsl:template match=“db:section”>
xsl:apply-templates/
</xsl:template>
<xsl:template match=“db:article/db:info”/>
<xsl:template match=“db:info/db:title”>


xsl:apply-templates/


</xsl:template>
<xsl:template match=“db:para”>


xsl:apply-templates/


</xsl:template>


<xsl:template match=“db:citation”>
xsl:text[</xsl:text>
<xsl:for-each select=“db:biblioref”>
<xsl:apply-templates select="."/>
<xsl:if test=“not(position() = last())”>
xsl:text, </xsl:text>
</xsl:if>
</xsl:for-each>
xsl:text]</xsl:text>
</xsl:template>
<xsl:template match=“db:biblioref”>
<xsl:variable name=“linkend” select="@linkend"/>
<xsl:value-of
select="$cite-position/bib:refs/bib:unique/bib:ref[@key=$linkend]/
@position"/>
</xsl:template>
</xsl:stylesheet>

Result:

<?xml version="1.0" encoding="utf-8"?><html

xmlns="http://www.w3.org/1999/xhtml"
xmlns:bib=“http://www.example.org/bib”>

   <title>Testing</title>
</head>
<body>
   <div id="content">
      <div id="main-content">
         <h2>Introduction</h2>
         <p>A citation with page number detail: [1].</p>
         <p>Some more citations: [2, 3, 4]. A citation
            <p>... in a footnote [2]</p>.
         </p>
      </div>
      <div id="bibliography">
         <p id="Veer1996a">1. <span class="title">Riots and Rituals:  

The Construction of Violence and Public Space in Hindu
Nationalism, van der Veer


2. Review of Moral
Economy and Popular Protest
, Tilly


3. For a New
Regional Geography 1
, Thrift


4. Senators Stamp
OK on Anti-Terrorism Laws




This still leaves some questions, though:

  1. what should the output actually look like? Should the above be
    just an

      element and allow the browser to number the bib list?
      That has advantages, but may not be as reliable (??). (in any case, the
      citations should be linked to the bib entries)
  2. I think this suggests the stylesheets need a “sort_order-bib"
    top-level parameter – as I have here – with options of “as cited” and
    "author-year” (and maybe “citekey”; am not sure if some bibs are sorted
    on that or not).

  3. I don’t know if my solution to the above problem is generalizable
    to footnote/endnote and its first/subsequent problem.

  4. I don’t know how to collapse the number ranges. So, (perhaps with
    a parameter option) “[2, 3, 4]” would become “[2-4]”.

Bruce