(incubating) | The Free and Open Productivity Suite
Announcing Apache OpenOffice 3.4
<xsl:stylesheet xmlns="http://purl.org/NET/xbiblio/citeproc" xmlns:bib="http://purl.org/NET/xbiblio/citeproc" xmlns:cs="http://purl.org/NET/xbiblio/csl" xmlns:db="http://docbook.org/ns/docbook" xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:exist="http://exist.sourceforge.net/NS/exist" xmlns:xdoc="http://www.pnp-software.com/XSLTdoc" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:course="http://purl.org/NET/xbiblio/course" version="2.0" exclude-result-prefixes="db xdoc xhtml mods xs cs exist bib course">
  
<!-- === licensed under CC-GNU GPL; see http://creativecommons.org/licenses/GPL/2.0 === -->
  
  <xdoc:doc type="stylesheet">
    
<xdoc:short>Processes MODS documents into a formatted intermediate representation.</xdoc:short>
    
<xdoc:author>Bruce D’Arcus</xdoc:author>
    
<xdoc:copyright>2004, Bruce D’Arcus</xdoc:copyright>
  
</xdoc:doc>

  
<!-- punctuation variables -->
  
<xsl:variable name="bibref-before">
    
<xsl:text />
  
</xsl:variable>
  
<xsl:variable name="bibref-after">
    
<xsl:text>.</xsl:text>
  
</xsl:variable>
  
<xsl:template match="bib:noname-substitute">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<span class="creator">
      
<xsl:value-of select="$prefix" />
      
<xsl:value-of select="." />
      
<xsl:value-of select="$suffix" />
    
</span>
  
</xsl:template>
  
  <xdoc:doc>The "full" mode renders complete personal names in bibliographies and footnote/endnote
    style ctiations.
</xdoc:doc>

  
<xsl:template match="mods:name" mode="full">
    
<xsl:param name="sort-order" />
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:param name="multi-authors" as="element(cs:multiple-authors)?" tunnel="yes" />
    
<xsl:variable name="multi-author-min" select="if ($multi-authors/@min-authors) then ($multi-authors/@min-authors) else xs:integer('999')" as="xs:integer" />
    
<xsl:variable name="use-multi-author-handling" select="xs:integer(count(../mods:name[mods:role/mods:roleTerm=$primary-contributors])) ge $multi-author-min" as="xs:boolean" />
    
<xsl:value-of select="$prefix" />
    
<xsl:choose>
      
<xsl:when test="$use-multi-author-handling">
        
<xsl:choose>
          
<xsl:when test="position() le xs:integer($multi-authors/@use-first)">
            
<xsl:choose>
              
<xsl:when test="$sort-order='first-author' and parent::mods:mods">
                
<xsl:apply-templates select="mods:namePart[@type='family'] | mods:namePart[not(@type)]" />
                
<xsl:if test="mods:namePart[@type='given']">
                  
<xsl:text></xsl:text>
                  
<xsl:apply-templates select="mods:namePart[@type='given']" />
                
</xsl:if>
              
</xsl:when>
              
              
<xsl:when test="$sort-order='first-author' and position() = 1 and parent::mods:mods">
                
<xsl:apply-templates select="mods:namePart[@type='family'] | mods:namePart[not(@type)]" />
                
<xsl:if test="mods:namePart[@type='given']">
                  
<xsl:text></xsl:text>
                  
<xsl:apply-templates select="mods:namePart[@type='given']" />
                
</xsl:if>
              
</xsl:when>
              
<xsl:when test="$sort-order='all'">
                
<xsl:apply-templates select="mods:namePart[@type='family'] | mods:namePart[not(@type)]" />
                
<xsl:if test="mods:namePart[@type='given']">
                  
<xsl:text></xsl:text>
                  
<xsl:apply-templates select="mods:namePart[@type='given']" />
                
</xsl:if>
                
<xsl:choose>
                  
<xsl:when test="position() = last()" />
                  
<xsl:otherwise></xsl:otherwise>
                
</xsl:choose>
              
</xsl:when>
              
              
<xsl:otherwise>
                
<xsl:apply-templates select="mods:namePart[@type='given']" />
                
<xsl:apply-templates select="mods:namePart[@type='family' or not(@type)]" />
              
</xsl:otherwise>
            
</xsl:choose>
          
</xsl:when>
          
<xsl:otherwise>
            
<xsl:if test="position() = last()">
              
<xsl:text> </xsl:text>
              
<xsl:value-of select="$multi-authors" />
            
</xsl:if>
          
</xsl:otherwise>
        
</xsl:choose>
      
</xsl:when>
      
<xsl:otherwise>
        
<xsl:choose>
          
<xsl:when test="$sort-order='first-author' and position() = 1 and parent::mods:mods">
            
<xsl:apply-templates select="mods:namePart[@type='family'] | mods:namePart[not(@type)]" />
            
<xsl:if test="mods:namePart[@type='given']">
              
<xsl:text></xsl:text>
              
<xsl:apply-templates select="mods:namePart[@type='given']" />
            
</xsl:if>
          
</xsl:when>
          
<xsl:when test="$sort-order='all'">
            
<xsl:apply-templates select="mods:namePart[@type='family'] | mods:namePart[not(@type)]" />
            
<xsl:if test="mods:namePart[@type='given']">
              
<xsl:text></xsl:text>
              
<xsl:apply-templates select="mods:namePart[@type='given']" />
            
</xsl:if>
          
</xsl:when>
          
<xsl:otherwise>
            
<xsl:apply-templates select="mods:namePart[@type='given']" />
            
<xsl:apply-templates select="mods:namePart[@type='family' or not(@type)]" />
          
</xsl:otherwise>
        
</xsl:choose>
        
<xsl:choose>
          
<xsl:when test="position() = last()" />
          
<xsl:when test="position() = last() - 1"> and </xsl:when>
          
<xsl:otherwise></xsl:otherwise>
        
</xsl:choose>
      
</xsl:otherwise>
    
</xsl:choose>
    
<xsl:value-of select="$suffix" />
  
</xsl:template>
  
  
<xsl:template match="mods:name[position() gt 1]/mods:role" />
  
<xsl:template match="mods:name[position()=1]/mods:role">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<span class="role">
      
<xsl:choose>
        
<xsl:when test="mods:roleTerm='editor'">
          
<xsl:value-of select="$prefix" />
          
<xsl:choose>
            
<xsl:when test="count(../../mods:name) &gt; 1">
              
<xsl:value-of select="$style-terms/cs:roles/cs:role[@term='editor']/cs:renderas/cs:multiple" />
            
</xsl:when>
            
<xsl:otherwise>
              
<xsl:value-of select="$style-terms/cs:roles/cs:role[@term='editor']/cs:renderas/cs:single" />
            
</xsl:otherwise>
          
</xsl:choose>
          
<xsl:value-of select="$suffix" />
        
</xsl:when>
        
<xsl:when test="mods:roleTerm='translator'">
          
<xsl:value-of select="$prefix" />
          
<xsl:choose>
            
<xsl:when test="count &gt; 1">
              
<xsl:value-of select="$style-terms/cs:roles/cs:role[@term='translator']/cs:renderas/cs:multiple" />
            
</xsl:when>
            
<xsl:otherwise>
              
<xsl:value-of select="$style-terms/cs:roles/cs:role[@term='translator']/cs:renderas/cs:single" />
            
</xsl:otherwise>
          
</xsl:choose>
          
<xsl:value-of select="$suffix" />
        
</xsl:when>
      
</xsl:choose>
    
</span>
  
</xsl:template>
  
  
  <xdoc:doc>The "short" mode renders just family name(s) commom in author-year citations.</xdoc:doc>

  
<xsl:template match="mods:name" mode="short">
    
<xsl:param name="multi-authors" as="element(cs:multiple-authors)" tunnel="yes" />
    
<xsl:variable name="multi-author-use-first" select="$multi-authors/@use-first" as="xs:integer?" />
    
<xsl:variable name="multi-author-min" select="if ($multi-authors/@min-authors) then ($multi-authors/@min-authors) else xs:integer('999')" as="xs:integer" />
    
<xsl:variable name="use-multi-author-handling" select="xs:integer(count(../mods:name[mods:role/mods:roleTerm=$primary-contributors])) ge $multi-author-min" as="xs:boolean" />
    
<xsl:choose>
      
<xsl:when test="$use-multi-author-handling">
        
<xsl:choose>
          
<xsl:when test="position() le xs:integer($multi-authors/@use-first)">
            
<xsl:apply-templates select="mods:namePart[not(@type='given')]" />
            
<xsl:choose>
              
<xsl:when test="position() = last()"> </xsl:when>
              
<xsl:otherwise></xsl:otherwise>
            
</xsl:choose> 
          
</xsl:when>
          
<xsl:otherwise>
            
<xsl:if test="position() = last()">
              
<xsl:text> </xsl:text>
              
<xsl:value-of select="$multi-authors" />
            
</xsl:if>
          
</xsl:otherwise>
        
</xsl:choose>
      
</xsl:when>
      
<xsl:otherwise>
        
<xsl:apply-templates select="mods:namePart[not(@type='given')]" />
        
<xsl:choose>
          
<xsl:when test="position() = last()" />
          
<xsl:when test="position() = last() - 1"> and </xsl:when>
          
<xsl:otherwise></xsl:otherwise>
        
</xsl:choose>        
      
</xsl:otherwise>
    
</xsl:choose>
  
</xsl:template>
  
  
<xsl:template match="mods:namePart[@type='given']">
    
<xsl:for-each select=".">
      
<xsl:choose>
        
<xsl:when test="$style-names/@initialize-with">
          
<xsl:value-of select="substring(.,1,1)" />
        
</xsl:when>
        
<xsl:otherwise>
          
<xsl:value-of select="." />
          
<xsl:text> </xsl:text>
        
</xsl:otherwise>
      
</xsl:choose>
      
<!-- FIX ME: the following presents rendering difficulties in certain styles -->
      
<xsl:value-of select="$style-names/@initialize-with" />
    
</xsl:for-each>
  
</xsl:template>
  
<xsl:template match="mods:namePart[not(@type='given')]">
    
<xsl:apply-templates />
  
</xsl:template>
  
<xsl:template match="bib:year">
    
<xsl:param name="source" />
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<span class="year">
      
<xsl:value-of select="$prefix" />
      
<xsl:apply-templates />
      
<!-- we can access newly creatod key element to append suffix -->
      
<xsl:apply-templates select="../bib:year-suffix" />
      
<xsl:value-of select="$suffix" />
    
</span>
  
</xsl:template>
  
<xsl:template match="bib:year-suffix">
    
<xsl:apply-templates />
  
</xsl:template>
  
  <xdoc:doc>Renders complete title/subtitle combination.</xdoc:doc>

  
<xsl:template match="mods:titleInfo[not(@type='abbreviated')]" mode="full">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:param name="font-style" />
    
<xsl:param name="font-weight" />
    
<xsl:choose>
      
<xsl:when test="../../@bib:refclass='part-inSerial' and not(../../mods:name[mods:role/mods:roleTerm=$primary-contributors])" />
      
<xsl:otherwise>
        
<span class="title">
          
<xsl:value-of select="$prefix" />
          
<xsl:if test="$font-weight">
            
<xsl:attribute name="font-weight">
              
<xsl:value-of select="$font-weight" />
            
</xsl:attribute>
          
</xsl:if>
          
<xsl:if test="$font-style">
            
<xsl:attribute name="font-style">
              
<xsl:value-of select="$font-style" />
            
</xsl:attribute>
          
</xsl:if>
          
<xsl:apply-templates select="mods:title" />
          
<xsl:apply-templates select="mods:subTitle" />
          
<xsl:value-of select="$suffix" />
        
</span>
      
</xsl:otherwise>
    
</xsl:choose>
  
</xsl:template>
  
<xsl:template match="mods:title">
    
<xsl:apply-templates />
  
</xsl:template>
  
<xsl:template match="mods:subTitle">
    
<xsl:text></xsl:text>
    
<xsl:apply-templates />
  
</xsl:template>
  
<xsl:template match="mods:originInfo">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:if test="mods:place">
      
<span class="origin">
        
<xsl:value-of select="$prefix" />
        
<xsl:apply-templates />
        
<xsl:value-of select="$suffix" />
      
</span>
    
</xsl:if>
  
</xsl:template>
  
<xsl:template match="mods:publisher">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<span class="publisher">
      
<xsl:value-of select="$prefix" />
      
<xsl:apply-templates />
      
<xsl:value-of select="$suffix" />
    
</span>
  
</xsl:template>
  
<xsl:template match="mods:place">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<span class="place">
      
<xsl:value-of select="$prefix" />
      
<xsl:apply-templates select="mods:placeTerm" />
      
<xsl:value-of select="$suffix" />
    
</span>
  
</xsl:template>
  
<!-- the following templates need to be combined -->
  
<xsl:template match="mods:detail[@type='volume']">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:variable name="type" select="@type" />
    
<span class="volume">
      
<xsl:value-of select="$prefix" />
      
<xsl:value-of select="$locators/cs:locator[@unit=$type]/cs:renderas/cs:single" />
      
<xsl:value-of select="mods:number" />
      
<xsl:value-of select="$suffix" />
    
</span>
  
</xsl:template>
  
<xsl:template match="mods:detail[@type='issue']">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:variable name="type" select="@type" />
    
<span class="issue">
      
<xsl:value-of select="$prefix" />
      
<xsl:value-of select="$locators/cs:locator[@unit=$type]/cs:renderas/cs:single" />
      
<xsl:value-of select="mods:number" />
      
<xsl:value-of select="$suffix" />
    
</span>
  
</xsl:template>
  
<xsl:template match="mods:detail[@type='file']">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:variable name="type" select="@type" />
    
<span class="file">
      
<xsl:value-of select="$prefix" />
      
<xsl:value-of select="$locators/cs:locator[@unit=$type]/cs:renderas/cs:single" />
      
<xsl:value-of select="mods:number" />
      
<xsl:value-of select="$suffix" />
    
</span>
  
</xsl:template>
  
<xsl:template match="mods:detail[@type='paragraph']">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:variable name="type" select="@type" />
    
<xsl:value-of select="$prefix" />
    
<xsl:value-of select="$locators/cs:locator[@unit=$type]/cs:renderas/cs:single" />
    
<xsl:value-of select="mods:number" />
    
<xsl:value-of select="$suffix" />
  
</xsl:template>
  
<xsl:template match="mods:extent">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:variable name="unit" select="@unit" />
    
<span class="locator">
      
<xsl:value-of select="$prefix" />
      
<xsl:value-of select="$locators/cs:locator[@unit=$unit]/cs:renderas/cs:multiple" />
      
<xsl:value-of select="mods:start" />
      
<xsl:if test="mods:end">
        
<xsl:text></xsl:text>
        
<xsl:value-of select="bib:number-condense(mods:start,mods:end)" />
      
</xsl:if>
      
<xsl:value-of select="$suffix" />
    
</span>
  
</xsl:template>
  
<xsl:template match="mods:typeOfResource | mods:issuance" />
  
<xsl:template match="mods:genre">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:variable name="genre" select="." />
    
<span class="genre">
      
<xsl:value-of select="$prefix" />
      
<xsl:value-of select="$style-terms/cs:genres/cs:genre[@term=$genre]/cs:renderas" />
      
<xsl:value-of select="$suffix" />
    
</span>
  
</xsl:template>
  
<xsl:template match="mods:location">
    
<xsl:param name="source" />
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:value-of select="$prefix" />
    
<span class="availability">
      
<xsl:apply-templates />
    
</span>
    
<xsl:value-of select="$suffix" />
  
</xsl:template>
  
<xsl:template match="mods:url">
    
<xsl:value-of select="." />
    
<xsl:if test="@dateLastAccessed">
      
<xsl:text> [accessed on </xsl:text>
      
<xsl:apply-templates select="./@dateLastAccessed" />
      
<xsl:text>]</xsl:text>
    
</xsl:if>
  
</xsl:template>
  
<xsl:template match="mods:physicalLocation">
    
<xsl:value-of select="." />
  
</xsl:template>
  
<!-- TODO: date handling probably needs to be redone as a function -->
  
<xsl:template match="mods:url/@dateLastAccessed">
    
<xsl:variable name="current" select="current()" />
    
<xsl:variable name="month-part" select="$month-format[xs:integer(substring($current,6,2))]" />
    
<xsl:variable name="day-part">
      
<xsl:choose>
        
<xsl:when test="substring(.,9,1) = '0'">
          
<xsl:value-of select="substring(.,10,1)" />
        
</xsl:when>
        
<xsl:otherwise>
          
<xsl:value-of select="substring(.,9,2)" />
        
</xsl:otherwise>
      
</xsl:choose>
    
</xsl:variable>
    
<span class="date-accessed">
      
<xsl:if test="substring(.,6,2)">
        
<xsl:text />
        
<xsl:value-of select="$month-part" />
      
</xsl:if>
      
<xsl:if test="substring(.,9,2)">
        
<xsl:text> </xsl:text>
        
<xsl:value-of select="$day-part" />
      
</xsl:if>
      
<xsl:if test="substring(.,6,2)">
        
<xsl:text />
      
</xsl:if>
      
<xsl:if test="../@dateLastAccessed">
        
<xsl:text></xsl:text>
        
<xsl:value-of select="substring(.,1,4)" />
      
</xsl:if>
    
</span>
  
</xsl:template>
  
  <xdoc:doc>configures month formatting based on CSL definition</xdoc:doc>

  
<xsl:variable name="month-format" as="element()*">
    
<xsl:sequence select="$styles/cs:citationstyle/cs:content/cs:dates/cs:months/cs:month" />
  
</xsl:variable>
  
<xsl:template match="mods:date | mods:dateIssued" mode="month">
    
<xsl:param name="source" />
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:variable name="current" select="current()" />
    
<xsl:choose>
      
<xsl:when test="current() castable as xs:gYearMonth or current() castable as xs:date">
        
<xsl:variable name="month-part" select="$month-format[xs:integer(substring($current,6,2))]" />
        
<span class="month">
          
<xsl:apply-templates select="$prefix" />
          
<xsl:value-of select="$month-part" />
          
<xsl:apply-templates select="$suffix" />
        
</span>
      
</xsl:when>
    
</xsl:choose>
  
</xsl:template>
  
<xsl:template match="mods:date | mods:dateIssued" mode="day">
    
<xsl:param name="source" />
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<xsl:variable name="day-part">
      
<xsl:choose>
        
<xsl:when test="substring(.,9,1) = '0'">
          
<xsl:value-of select="substring(.,10,1)" />
        
</xsl:when>
        
<xsl:otherwise>
          
<xsl:value-of select="substring(.,9,2)" />
        
</xsl:otherwise>
      
</xsl:choose>
    
</xsl:variable>
    
<xsl:if test="current() castable as xs:date">
      
<span class="day">
        
<xsl:value-of select="$prefix" />
        
<xsl:value-of select="$day-part" />
        
<xsl:value-of select="$suffix" />
      
</span>
    
</xsl:if>
  
</xsl:template>
  
<xsl:template match="mods:note[@type='citation']">
    
<xsl:param name="prefix" />
    
<xsl:param name="suffix" />
    
<span class="note">
      
<xsl:value-of select="$prefix" />
      
<xsl:value-of select="." />
      
<xsl:value-of select="$suffix" />
    
</span>
  
</xsl:template>
  
<xsl:template match="mods:physicalDescription | mods:note[not(@type='citation')]" />
</xsl:stylesheet>






































v

Apache Feather

Copyright & License | Privacy | Contact Us

Apache and the Apache feather logos are trademarks of The Apache Software Foundation. OpenOffice.org and the seagull logo are registered trademarks of The Apache Software Foundation. Other names appearing on the site may be trademarks of their respective owners.

Apache OpenOffice is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.