DateAndTime.xslt

From TEIWiki
Jump to navigation Jump to search

Simple stylesheet adjusts the attributes of <date> and elements.

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

<!-- Tiny XSLT 1.0 stylesheet that reads in a TEI (P4) file and writes out the -->
<!-- same file with the attributes of <date> and <time> adjusted to P5 flavor: -->
<!-- value= -> when=     -->
<!-- certainty= -> cert= -->
<!-- zone= is dropped    -->
<!-- The output of this stylesheet is not P5-conformant XML; in fact, even the -->
<!-- elements we are changing may not be valid P5. This is because although we -->
<!-- move all the bits of information to the right place, it may still be in   -->
<!-- the wrong format. E.g., a <date value="ca.1948" certainty="moderate"> will-->
<!-- become <date when="ca.1948" cert="moderate">, which has 2 invalid at-     -->
<!-- tributes. -->

<!-- Copyleft 2008 Syd Bauman and the Brown University Women Writers Project -->

<!-- written 2008-05-02 -->

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <!-- Anything that isn't matched below just gets copied over -->
  <xsl:import href="Copy-All.xsl"/>
  
  <!-- housekeeping: -->
  <xsl:output method="xml" encoding="UTF-8" cdata-section-elements="eg"/>
  
  <!-- for value= of either <date> or <time> ... -->
  <xsl:template match="date/@value|time/@value">
    <!-- ... convert to when= with same value -->
    <xsl:attribute name="when"><xsl:value-of select="."/></xsl:attribute>
  </xsl:template>
  
  <!-- for certainty= of <date> ... -->
  <xsl:template match="date/@certainty">
    <!-- ... convert to cert= with same value -->
    <xsl:attribute name="cert"><xsl:value-of select="."/></xsl:attribute>
  </xsl:template>
  
  <!-- for zone= of <time> ... -->
  <xsl:template match="time/@zone">
    <!-- ... ignore it, and advise user we've done so -->
    <xsl:message>WARNING: zone= attribute of <time> is being dropped!</xsl:message>
  </xsl:template>
  
</xsl:stylesheet>