Difference between revisions of "DateStructLess.xslt"

From TEIWiki
Jump to navigation Jump to search
m (try to get < to behave properly when copied-and-pasted)
m (use when= not value= on output, and don't generate precision= as it no longer exists)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
A stylesheet to convert P4 <dateStruct> and <timeStruct> elements into P5 <date> and <time> elements. The version of P5 converted to is the one in the trunk of the Sourceforge subversion repository as of 2006-05-25. It is very likely to change soon.
+
A stub of a stylesheet to convert P4 <dateStruct> and <timeStruct> elements into P5 <date> and <time> elements (it doesn't handle children elements yet).
<pre><nowiki>
+
<pre><nowiki><?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
 
  
 
<!-- Tiny XSLT 1.0 stylesheet that reads in a TEI (P4) file and writes out the same -->
 
<!-- Tiny XSLT 1.0 stylesheet that reads in a TEI (P4) file and writes out the same -->
Line 19: Line 18:
  
 
<!-- Copyleft 2006 Syd Bauman and the Text Encoding Initiative Consortium -->
 
<!-- Copyleft 2006 Syd Bauman and the Text Encoding Initiative Consortium -->
 +
 +
<!-- updated 2008-05-02 by Syd Bauman: use when= not value= on output; no -->
 +
<!-- precision= attribute anymore (but may be coming back soon). -->
  
 
<xsl:stylesheet version="1.0"
 
<xsl:stylesheet version="1.0"
Line 32: Line 34:
 
       <!-- global attrs -->
 
       <!-- global attrs -->
 
       <xsl:apply-templates select="@id|@xml:id|@n|@lang|@xml:lang|@rend"/>
 
       <xsl:apply-templates select="@id|@xml:id|@n|@lang|@xml:lang|@rend"/>
      <!-- attrs common to P4 'temporalExpr' and P5 'att.datePart' -->
 
      <xsl:apply-templates select="@value"/>
 
 
       <!-- attrs common to P4 <dateStruct> and P5 <date> -->
 
       <!-- attrs common to P4 <dateStruct> and P5 <date> -->
 
       <xsl:apply-templates select="@calendar"/>
 
       <xsl:apply-templates select="@calendar"/>
 
       <!-- attrs that change between P4 <dateStruct> and P5 <date> -->
 
       <!-- attrs that change between P4 <dateStruct> and P5 <date> -->
       <xsl:if test="@exact">
+
       <xsl:if test="@value">
         <xsl:attribute name="precision">
+
         <xsl:attribute name="when"><xsl:value-of select="@value"/></xsl:attribute>
          <xsl:value-of select="./@exact"/>
 
        </xsl:attribute>
 
 
       </xsl:if>
 
       </xsl:if>
       <!-- attrs not available -->
+
       <!-- attrs that get lost in translation -->
       <xsl:for-each select="@key|@reg|@type|@full">
+
       <xsl:for-each select="@exact|@key|@reg|@type|@full">
 
         <xsl:message>
 
         <xsl:message>
 
           <xsl:text>WARNING: </xsl:text>
 
           <xsl:text>WARNING: </xsl:text>
Line 49: Line 47:
 
           <xsl:text>="</xsl:text>
 
           <xsl:text>="</xsl:text>
 
           <xsl:value-of select="normalize-space(current())"/>
 
           <xsl:value-of select="normalize-space(current())"/>
           <xsl:text>" attribute of &amp;lt;dateStruct> element is being dropped!</xsl:text>
+
           <xsl:text>" attribute of &lt;dateStruct> element is being dropped!</xsl:text>
 
         </xsl:message>
 
         </xsl:message>
 
       </xsl:for-each>
 
       </xsl:for-each>
Line 62: Line 60:
 
       <!-- global attrs -->
 
       <!-- global attrs -->
 
       <xsl:apply-templates select="@id|@xml:id|@n|@lang|@xml:lang|@rend"/>
 
       <xsl:apply-templates select="@id|@xml:id|@n|@lang|@xml:lang|@rend"/>
       <!-- attrs common to P4 'temporalExpr' and P5 'att.timePart' -->
+
       <!-- attrs that change between P4 <timeStruct> and P5 <time> -->
       <xsl:apply-templates select="@value"/>
+
       <xsl:if test="@value">
       <!-- attrs not available -->
+
        <xsl:attribute name="when"><xsl:value-of select="@value"/></xsl:attribute>
 +
      </xsl:if>
 +
       <!-- attrs that get lost in translation -->
 
       <xsl:for-each select="@key|@reg|@zone|@type|@full">
 
       <xsl:for-each select="@key|@reg|@zone|@type|@full">
 
         <xsl:message>
 
         <xsl:message>
Line 71: Line 71:
 
           <xsl:text>="</xsl:text>
 
           <xsl:text>="</xsl:text>
 
           <xsl:value-of select="normalize-space(.)"/>
 
           <xsl:value-of select="normalize-space(.)"/>
           <xsl:text>" attribute of &amp;lt;timeStruct> element is being dropped!</xsl:text>
+
           <xsl:text>" attribute of &lt;timeStruct> element is being dropped!</xsl:text>
 
         </xsl:message>
 
         </xsl:message>
 
       </xsl:for-each>
 
       </xsl:for-each>
Line 79: Line 79:
 
   </xsl:template>
 
   </xsl:template>
 
    
 
    
</xsl:stylesheet>
+
</xsl:stylesheet></nowiki></pre>
</nowiki></pre>
 
 
[[Category:P4toP5]]
 
[[Category:P4toP5]]
 
[[User:Syd|Syd]] 07:47, 26 May 2006 (BST)
 
[[User:Syd|Syd]] 07:47, 26 May 2006 (BST)

Latest revision as of 15:43, 4 May 2008

A stub of a stylesheet to convert P4 <dateStruct> and <timeStruct> elements into P5 <date> and

<?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 <dateStruct> and <timeStruct> elements converted to P5 <date> and -->
<!-- <time> elements respectively. -->

<!-- We handle the xml:id= and xml:lang= attributes in addition to the expected P4 -->
<!-- attributes in case we are somewhere in a P4->P5 pipeline in which that has -->
<!-- already been done. -->

<!-- The exact= attribute of p4:dateStruct is converted to the precision= attribute -->
<!-- of p5:date. This is likely to produce invalid results, as the values of the -->
<!-- latter must conform to a short enumerated list. -->

<!-- Note that this stylesheet does not (yet) handle the changes in the attributes -->
<!-- of the children of <dateStruct> and <timeStruct>. -->

<!-- Copyleft 2006 Syd Bauman and the Text Encoding Initiative Consortium -->

<!-- updated 2008-05-02 by Syd Bauman: use when= not value= on output; no -->
<!-- precision= attribute anymore (but may be coming back soon). -->

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

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

  <!-- match <dateStruct>, output <date> with attrs adjusted -->
  <xsl:template match="dateStruct">
    <xsl:element name="date">
      <!-- global attrs -->
      <xsl:apply-templates select="@id|@xml:id|@n|@lang|@xml:lang|@rend"/>
      <!-- attrs common to P4 <dateStruct> and P5 <date> -->
      <xsl:apply-templates select="@calendar"/>
      <!-- attrs that change between P4 <dateStruct> and P5 <date> -->
      <xsl:if test="@value">
        <xsl:attribute name="when"><xsl:value-of select="@value"/></xsl:attribute>
      </xsl:if>
      <!-- attrs that get lost in translation -->
      <xsl:for-each select="@exact|@key|@reg|@type|@full">
        <xsl:message>
          <xsl:text>WARNING: </xsl:text>
          <xsl:value-of select="name(.)"/>
          <xsl:text>="</xsl:text>
          <xsl:value-of select="normalize-space(current())"/>
          <xsl:text>" attribute of <dateStruct> element is being dropped!</xsl:text>
        </xsl:message>
      </xsl:for-each>
      <xsl:apply-templates
        select="./*|./text()|./comment()|./processing-instruction()"/>
    </xsl:element>
  </xsl:template>

  <!-- match <timeStruct>, output <time> with attrs adjusted -->
  <xsl:template match="timeStruct">
    <xsl:element name="time">
      <!-- global attrs -->
      <xsl:apply-templates select="@id|@xml:id|@n|@lang|@xml:lang|@rend"/>
      <!-- attrs that change between P4 <timeStruct> and P5 <time> -->
      <xsl:if test="@value">
        <xsl:attribute name="when"><xsl:value-of select="@value"/></xsl:attribute>
      </xsl:if>
      <!-- attrs that get lost in translation -->
      <xsl:for-each select="@key|@reg|@zone|@type|@full">
        <xsl:message>
          <xsl:text>WARNING: </xsl:text>
          <xsl:value-of select="name(.)"/>
          <xsl:text>="</xsl:text>
          <xsl:value-of select="normalize-space(.)"/>
          <xsl:text>" attribute of <timeStruct> element is being dropped!</xsl:text>
        </xsl:message>
      </xsl:for-each>
      <xsl:apply-templates
        select="./*|./text()|./comment()|./processing-instruction()"/>
    </xsl:element>
  </xsl:template>
  
</xsl:stylesheet>

Syd 07:47, 26 May 2006 (BST)