Table2mediawiki.xslt

This is a fast-and-lousy proof-of-concept stylesheet that reads in a TEI (P5) document and writes out a MediWiki representation of each therein. (Although it deliberately ignores tables that are inside other tables.)

 

  Written: 2009-12-12 Author: Syd Bauman Status: Copyleft 2009 Syd Bauman and the Brown University Women Writers Project Input</xd:b>: A TEI (P5) document</xd:p> Output</xd:b>: a rudimentary representation of each table in the input (that is       not itself inside a table) in the MediaWiki language</xd:p> Known issues</xd:b>: <xd:ul> <xd:li>ignores all attributes except role= of &lt;row></xd:li> <xd:li>only knows about "label" and "data" values of role= of &lt;row></xd:li> <xd:li>no processing of phrase-level elements (yet :-) &#x2014; after all, this is really intended as a proof-of-concept at this point</xd:li> <xd:li>should be parameratized a bit better (e.g., user should be able to specify border=           and cellpadding=)</xd:li> <xd:li>someday should handle multiple wiki-languages</xd:li> </xd:ul> </xd:p> </xd:desc> </xd:doc>

<xsl:output method="text"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:apply-templates select="//tei:table[not( ancestor::tei:table )]"/> </xsl:template>

<xsl:template match="tei:table"> <xsl:apply-templates select="tei:head"/> <xsl:text>{| border="1" cellpadding="2"</xsl:text> <xsl:text>&amp;#x0A;</xsl:text> <xsl:apply-templates select="tei:row"/> <xsl:text>|}</xsl:text> <xsl:text>&amp;#x0A;</xsl:text> <xsl:text>&amp;#x0A;</xsl:text> </xsl:template>

<xsl:template match="tei:row"> <xsl:variable name="sepChar"> <xsl:choose> <xsl:when test="@role='label'">!</xsl:when> <xsl:when test="@role='data' or not(@role)">|</xsl:when> <xsl:otherwise> <xsl:message>warning: unrecognized role= of <xsl:number/> &amp;lt;row>; presuming "data"</xsl:message> <xsl:text>|</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:text>|-</xsl:text> <xsl:text>&amp;#x0A;</xsl:text> <xsl:value-of select="$sepChar"/> <xsl:for-each select="tei:cell"> <xsl:apply-templates select="."/> <xsl:choose> <xsl:when test="following-sibling::tei:cell"> <xsl:value-of select="$sepChar"/> <xsl:value-of select="$sepChar"/> </xsl:when> <xsl:otherwise> <xsl:text>&amp;#x0A;</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template>

<xsl:template match="tei:head"> <xsl:text>|+</xsl:text> <xsl:value-of select="normalize-space(.)"/> <xsl:text>&amp;#x0A;</xsl:text> </xsl:template>

<xsl:template match="tei:cell"> <xsl:text> </xsl:text> <xsl:value-of select="normalize-space(.)"/> <xsl:text> </xsl:text> </xsl:template>

</xsl:stylesheet>