Janus.xslt

From TEIWiki
Jump to navigation Jump to search

This stylesheet converts the so-called "janus" elements into proper P5 <choice>s. That is all.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <!-- Tiny XSLT 1.0 stylesheet that reads in a TEI P4:2004 file (or -->
  <!-- any other TEI P4-like file, really) and writes out the same file -->
  <!-- with the "janus" elements (<abbr expan=>, <expan abbr=>; <sic corr=>, -->
  <!-- <corr sic=>; <orig reg=>, <reg orig=>) converted into <choice> -->
  <!-- elements. -->

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

  <!-- The output of this stylesheet is not P5-comnpliant XML; it is just -->
  <!-- the same P4 document with <choice> instead of the so-called janus tags. -->

  <!-- Written 2006-09-15 by Syd Bauman -->
  <!-- Updated 2014-12-25 per Keith Handley: fix obvious copy-and-paste errors -->

  <xsl:import href="Copy-All.xsl"/>

  <xsl:output method="xml" encoding="UTF-8" cdata-section-elements="eg"/>

  <xsl:template match="abbr[@expan]">
    <xsl:element name="choice">
      <xsl:element name="abbr">
        <xsl:apply-templates select="./@*[local-name()!='expan']"/>
        <xsl:apply-templates select="./child::node()"/>
      </xsl:element>
      <xsl:element name="expan">
        <xsl:value-of select="@expan"/>
      </xsl:element>
    </xsl:element>
  </xsl:template>

  <xsl:template match="expan[@abbr]">
    <xsl:element name="choice">
      <xsl:element name="expan">
        <xsl:apply-templates select="./@*[local-name()!='abbr']"/>
        <xsl:apply-templates select="./child::node()"/>
      </xsl:element>
      <xsl:element name="abbr">
        <xsl:value-of select="@abbr"/>
      </xsl:element>
    </xsl:element>
  </xsl:template>

  <xsl:template match="sic[@corr]">
    <xsl:element name="choice">
      <xsl:element name="sic">
        <xsl:apply-templates select="./@*[local-name()!='corr']"/>
        <xsl:apply-templates select="./child::node()"/>
      </xsl:element>
      <xsl:element name="corr">
        <xsl:value-of select="@corr"/>
      </xsl:element>
    </xsl:element>
  </xsl:template>

  <xsl:template match="corr[@sic]">
    <xsl:element name="choice">
      <xsl:element name="corr">
        <xsl:apply-templates select="./@*[local-name()!='sic']"/>
        <xsl:apply-templates select="./child::node()"/>
      </xsl:element>
      <xsl:element name="sic">
        <xsl:value-of select="@sic"/>
      </xsl:element>
    </xsl:element>
  </xsl:template>

  <xsl:template match="orig[@reg]">
    <xsl:element name="choice">
      <xsl:element name="orig">
        <xsl:apply-templates select="./@*[local-name()!='reg']"/>
        <xsl:apply-templates select="./child::node()"/>
      </xsl:element>
      <xsl:element name="reg">
        <xsl:value-of select="@reg"/>
      </xsl:element>
    </xsl:element>
  </xsl:template>

  <xsl:template match="reg[@orig]">
    <xsl:element name="choice">
      <xsl:element name="reg">
        <xsl:apply-templates select="./@*[local-name()!='orig']"/>
        <xsl:apply-templates select="./child::node()"/>
      </xsl:element>
      <xsl:element name="orig">
        <xsl:value-of select="@orig"/>
      </xsl:element>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>