P4toP5NZETC

Below is the stylesheet used to convert TEI P4 text to TEI P5 text at the NZETC (http://www.nzetc.org/). It is based on a previous stylesheet by Sebastian Rahtz. Many of the extensions to Sebastian's stylesheet are due to data-tidying needed to cope with P5's significantly better checking of content types.

              0000-00-00 </xsl:choose> </xsl:variable> <xsl:variable name="uc">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable> <xsl:variable name="lc">abcdefghijklmnopqrstuvwxyz</xsl:variable> <xsl:template match="*"> <xsl:choose> <xsl:when test="namespace-uri=''"> <xsl:element namespace="http://www.tei-c.org/ns/1.0" name="{local-name(.)}"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> </xsl:element> </xsl:when>  <xsl:copy> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> </xsl:copy> </xsl:otherwise> </xsl:choose> </xsl:template>

<xsl:template match="@*|processing-instruction|comment"> <xsl:copy/> </xsl:template> <xsl:template match="text"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="teiCorpus.2"> <teiCorpus xsi:schemaLocation="http://www.tei-c.org/ns/1.0 nzetc-p5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> </teiCorpus> </xsl:template> <xsl:template match="witness/@sigil"> <xsl:attribute name="xml:id"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template>

<xsl:template match="witList"> <listWit> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> </listWit> </xsl:template> <xsl:template match="TEI.2"> <TEI xsi:schemaLocation="http://www.tei-c.org/ns/1.0 nzetc-p5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> </TEI> </xsl:template> <xsl:template match="xref"> <xsl:element namespace="http://www.tei-c.org/ns/1.0" name="ref"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> </xsl:element> </xsl:template> <xsl:template match="xptr"> <xsl:element namespace="http://www.tei-c.org/ns/1.0" name="ptr"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> </xsl:element> </xsl:template> <xsl:template match="figure/@url"/> <xsl:template match="figure[@url]"> <xsl:apply-templates select="@id"/> <xsl:value-of select="@id"/>/ <xsl:value-of select="@n"/>/ <xsl:value-of select="@url"/> <xsl:apply-templates select="@n|@url"/> <xsl:apply-templates select="@id" mode="graphic"/> <xsl:apply-templates select="*|processing-instruction|comment|text"/> <xsl:text> </xsl:text> </xsl:template> <xsl:template match="figure/@entity"/> <xsl:template match="figure[@entity]"> <xsl:variable name="entity"> <xsl:choose> <xsl:when test="contains(@entity,'.')"> <xsl:value-of select="substring-before(@entity, '.')"/> </xsl:when>  <xsl:value-of select="@entity"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="mimetype"> <xsl:choose> <xsl:when test="contains(@entity,'.gif')"> <xsl:text>image/gif</xsl:text> </xsl:when> <xsl:when test="contains(@entity,'.pdf')"> <xsl:text>application/pdf</xsl:text> </xsl:when> <xsl:when test="contains(@entity,'.jpg')"> <xsl:text>image/jpeg</xsl:text> </xsl:when>  <xsl:text>image/jpeg</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:variable>

<xsl:variable name="url"> <xsl:choose> <xsl:when test="contains(@entity,'.gif')"> <xsl:value-of select="@entity"/> </xsl:when> <xsl:when test="contains(@entity,'.pdf')"> <xsl:value-of select="@entity"/> </xsl:when> <xsl:when test="contains(@entity,'.jpg')"> <xsl:value-of select="@entity"/> </xsl:when>  <xsl:value-of select="concat(@entity,'.jpg')"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:attribute name="xml:id"><xsl:value-of select="@id"/></xsl:attribute> <xsl:attribute name="url"><xsl:value-of select="$url"/></xsl:attribute> <xsl:attribute name="mimeType"><xsl:value-of select="$mimetype"/></xsl:attribute> <xsl:attribute name="xml:id"><xsl:value-of select="concat(@id, '-g')"/></xsl:attribute> <xsl:apply-templates select="@n"/> <xsl:apply-templates select="*|text|comment|processing-instruction"/> </xsl:template> <xsl:template match="event"> <xsl:apply-templates select="@*|*|text|comment|processing-instruction"/> </xsl:template> <xsl:template match="state"> <refState> <xsl:apply-templates select="@*|*|text|comment|processing-instruction"/> </refState> </xsl:template> <xsl:template match="language"> <xsl:element namespace="http://www.tei-c.org/ns/1.0" name="language"> <xsl:if test="@id"> <xsl:attribute name="ident"> <xsl:choose> <xsl:when test="@id='eng'"><xsl:text>en</xsl:text></xsl:when> <xsl:when test="@id='moa'"><xsl:text>mi</xsl:text></xsl:when> <xsl:when test="@id='mao'"><xsl:text>mi</xsl:text></xsl:when> <xsl:when test="@id='rap'"><xsl:text>rap</xsl:text></xsl:when> <xsl:when test="@id='SAMPA'"><xsl:text>x-sampa</xsl:text></xsl:when> <xsl:value-of select="@id"/></xsl:otherwise> </xsl:choose> </xsl:attribute> </xsl:if> <xsl:apply-templates select="*|processing-instruction|comment|text"/> </xsl:element> </xsl:template> <xsl:template match="@date.created"/> <xsl:template match="@date.updated"/> <xsl:template match="refsDecl/@doctype"/> <xsl:template match="dateRange"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> </xsl:template> <xsl:template match="dateRange/@from"> <xsl:copy-of select="."/> </xsl:template> <xsl:template match="dateRange/@to"> <xsl:copy-of select="."/> </xsl:template> <xsl:template match="date/@value|time/@value|docDate/@value">

<xsl:variable name="normal"> <xsl:choose> <xsl:when test="starts-with(.,'0000-')"> <xsl:value-of select="concat('--',substring-after(.,'0000-'))"/> </xsl:when> <xsl:when test="string-length(.)=9 and substring(.,8,1)='-'"> <xsl:value-of select="substring(.,0,8)"/>-0<xsl:value-of select="substring(.,9,1)"/> </xsl:when> <xsl:when test="string-length(.)=9 and not (substring(.,8,1)='-')"> <xsl:value-of select="substring(.,0,6)"/>-0<xsl:value-of select="substring(.,8,1)"/> </xsl:when> <xsl:when test="string-length(.)=10 and contains(.,'-00-00')"> <xsl:value-of select="substring(.,0,4)"/> </xsl:when>  <xsl:value-of select="."/> </xsl:otherwise> </xsl:choose> </xsl:variable>

<xsl:attribute name="when"> <xsl:value-of select="$normal"/> </xsl:attribute> </xsl:template>

<xsl:template match="date[contains(@value,'?')]|dateRange[contains(@to,'?')]|dateRange[contains(@from,'?')]"> <xsl:apply-templates select="*|processing-instruction|comment|text"/> </xsl:template> <xsl:template match="/TEI.2[@id='Auc1873-1909Proc'                         or @id='Auc1911NgaM'                          or @id='Auc1912NgaM'                          or @id='BIM1032Epam'                          or @id='BIM1192Kape'                          or @id='BIM1195Huin'                          or @id='BIM1196Tong'                          or @id='BIM1203Wiki'                          or @id='BIM1204KiaH'                          or @id='BIM1205KoNg'                          or @id='BIM1250Kare'                          or @id='BIM1251Kare'                          or @id='BIM1269Meih'                          or @id='BIM1310TeWa'                          or @id='BIM1336West'                          or @id='BIM1341Panu'                          or @id='BIM1346Tawh'                          or @id='BIM1386Nati'                          or @id='BIM1390Paep'                          or @id='BIM1427Tuu' or @id='BIM1518Ehoa' or @id='BIM1563Hepi' or @id='BIM205KiNg' or @id='BIM496Evid' or @id='BIM521Ngat' or @id='BIM533Kaho' or @id='BIM534Frie' or @id='BIM554Kawa' or @id='BIM577Panu' or @id='BIM588Tawh' or @id='BIM594Furt' or @id='BIM595Ngar' or @id='BIM596Kian' or @id='BIM597KiNg' or @id='BIM623Puka' or @id='BIM635Tino' or @id='BIM636Nati' or @id='BIM646Lett' or @id='BIM658Whak' or @id='BIM666Runa' or @id='BIM673Tumu' or @id='BIM675Kaiw' or @id='BIM678Peti' or @id='BIM685Peti' or @id='BIM689Haer' or @id='BIM694Runa' or @id='BIM697Pueh' or @id='BIM698Wita' or @id='BIM737Kara' or @id='BIM753Heta' or @id='BIM754Kuik' or @id='BIM762Rang' or @id='BIM763Hiri' or @id='BIM764Hira' or @id='BIM765Tami' or @id='BIM767Paor' or @id='BIM781Inoi' or @id='BIM782Kawe' or @id='BIM783Timb' or @id='BIM787Hena' or @id='BIM814Mohi' or @id='BIM825Hepe' or @id='BIM840TeWa' or @id='BIM854Kuin' or @id='BIM859Kawe' or @id='BIM867Tene' or @id='BIM868Panu' or @id='BIM869KiNg' or @id='BIM870Rang' or @id='BIM872Puka' or @id='BIM873TeHa' or @id='BIM874Tika' or @id='BIM875Tomo' or @id='BIM876Hena' or @id='BIM885Peti' or @id='BIM935Nati' or @id='BIM952Panu' or @id='BIMS36Kahi' or @id='BIMs310Chur' or @id='Gov1879Ture' or @id='Gov1880Ture' or @id='Gov1881NgaT' or @id='Gov1903Acts' or @id='Gov1904Acts' or @id='Gov1905Acts' or @id='Gov1906Acts' or @id='Gov1907Acts' or @id='Gov1908Acts' or @id='Gov1909Acts' or @id='Gov1910Acts' or @id='HePPuka' or @id='HuiMaor' or @id='IndRitu' or @id='KawRena' or @id='Kot1894Kore' or @id='Mac01Comp' or @id='Mac02Comp' or @id='MacRepo' or @id='MacWhak' or @id='MaoKore' or @id='MaoPare' or @id='MarKoNg' or @id='MarOutl' or @id='NZGNati' or @id='NZPCorr' or @id='NZPHous' or @id='NZPPeti' or @id='NZPRoya' or @id='NZPa1900NgaK' or @id='NZPa1901NgaK' or @id='NZPa1902NgaK' or @id='NZPa1904-5NgaK' or @id='NZPaV01NgaK' or @id='NZPaV02NgaK' or @id='NZPaV03NgaK' or @id='NZPaV04NgaK' or @id='Nat1876Repo' or @id='Nat1877Repo' or @id='Nat1878Repo' or @id='Nat1879Repo-1' or @id='Nat1879Repo-2' or @id='Nat1880Repo' or @id='Nat1881Repo' or @id='Nat1882Repo' or @id='Nat1883Repo' or @id='Nat1884Repo-2' or @id='Nat1885Repo' or @id='Nat1887Repo-1' or @id='Nat1887Repo-2' or @id='Nat1888Repo' or @id='Nat1889Repo' or @id='Nat1890Repo' or @id='Nat1891Repo-2' or @id='Nat1892Repo' or @id='Nat1893Repo' or @id='Nat1894Repo' or @id='Nat1895Repo' or @id='Nat1896Repo' or @id='Nat1897Repo' or @id='Nat1898Repo' or @id='Nat1899Repo' or @id='Nat1900Repo' or @id='Nat1901Repo' or @id='Nat1902Repo' or @id='Nat1903Repo' or @id='Nat1904Repo' or @id='Nat1905Repo' or @id='Nat1906Repo' or @id='Nat1907Repo' or @id='Nat1908Repo' or @id='PunLett' or @id='SedWhai' or @id='TaiProp' or @id='TeWRetu' or @id='Tur01Nort' or @id='Tur01Plan' or @id='Tur02Nort' or @id='Tur02Plan' or @id='TurEpit' or @id='TurOldP' or @id='TurWhen' or @id='Wai1861Mahi' or @id='Wai1863Mahi' or @id='Wai864Mahi' or @id='Wai1865Mahi' or @id='Wai1872NgaM' or @id='Wai1874NgaM' or @id='Wai1875NgaM' or @id='Wai1887NgaM' or @id='Wai1891NgaM' or @id='Wai1896NgaM' or @id='Wait1872NgaM' or @id='WesRepo' or @id='WhaEasy' ]/text//date/@value"/>

<xsl:template match="@url"> <xsl:attribute name="target"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template>

<xsl:template match="@doc"> <xsl:attribute name="target"> <xsl:value-of select="unparsed-entity-uri(.)"/> </xsl:attribute> </xsl:template> <xsl:template match="@id"> <xsl:choose> <xsl:when test="parent::lang"> <xsl:attribute name="ident"> <xsl:value-of select="."/> </xsl:attribute> </xsl:when>  <xsl:if test=".!=''"> <xsl:attribute name="xml:id"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="@lang"> <xsl:attribute name="xml:lang"> <xsl:choose> <xsl:when test=".='eng'"><xsl:text>en</xsl:text></xsl:when> <xsl:when test=".='moa'"><xsl:text>mi</xsl:text></xsl:when> <xsl:when test=".='rap'"><xsl:text>rap</xsl:text></xsl:when> <xsl:when test=".='SAMPA'"><xsl:text>x-sampa</xsl:text></xsl:when> <xsl:value-of select="."/></xsl:otherwise> </xsl:choose> </xsl:attribute> </xsl:template> <xsl:template match="change/@date"/> <xsl:template match="date/@certainty"> <xsl:attribute name="cert"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> <xsl:template match="variantEncoding/@location|num/@value"> <xsl:copy-of select="."/> </xsl:template>

<xsl:template match="@ana|@active|@adj|@adjFrom|@adjTo|@children|@children|@class|@code|@code|@copyOf|@corresp|@decls|@domains|@end|@exclude|@fVal|@feats|@follow|@from|@hand|@inst|@langKey|@location|@mergedin|@new|@next|@old|@origin|@otherLangs|@parent|@passive|@perf|@prev|@render|@resp|@sameAs|@scheme|@script|@select|@since|@start|@synch|@target|@targetEnd|@to|@to|@value|@value|@who|@wit"> <xsl:attribute name="{name(.)}"> <xsl:call-template name="splitter"> <xsl:with-param name="val"> <xsl:value-of select="."/> </xsl:with-param> </xsl:call-template> </xsl:attribute> </xsl:template> <xsl:template name="splitter"> <xsl:param name="val"/> <xsl:choose> <xsl:when test="not(starts-with($val,'#'))"> <xsl:text>#</xsl:text> </xsl:when> </xsl:choose> <xsl:choose> <xsl:when test="contains($val,' ')"> <xsl:value-of select="substring-before($val,' ')"/> <xsl:text> </xsl:text> <xsl:call-template name="splitter"> <xsl:with-param name="val"> <xsl:value-of select="substring-after($val,' ')"/> </xsl:with-param> </xsl:call-template> </xsl:when>  <xsl:value-of select="$val"/> </xsl:otherwise> </xsl:choose> </xsl:template>

<xsl:template match="hand"> <handNote> <xsl:apply-templates select="@*|*|text|comment|processing-instruction"/> </handNote> </xsl:template>

<xsl:template match="handList"> <handNotes> <xsl:apply-templates select="@*|*|text|comment|processing-instruction"/> </handNotes> </xsl:template>

<xsl:template match="bibl/imprint"> <xsl:apply-templates select="*|text|comment|processing-instruction"/> </xsl:template>

<xsl:template match="editionStmt/editor"> <respStmt> <xsl:apply-templates select="@*[local-name!='role']"/> <xsl:value-of select="@role"/> <xsl:apply-templates/> </respStmt> </xsl:template> <xsl:template match="teiHeader"> <teiHeader> <xsl:apply-templates select="@*|*|comment|processing-instruction"/> <xsl:if test="not(revisionDesc) and (@date.created or @date.updated)"> <revisionDesc> <xsl:if test="@date.updated"> updated <xsl:value-of select="@date.updated"/> Date edited </xsl:if> <xsl:if test="@date.created"> created <xsl:value-of select="@date.created"/> Date created </xsl:if> </revisionDesc> </xsl:if> </teiHeader> </xsl:template> <xsl:template match="revisionDesc"> <revisionDesc> <xsl:apply-templates select="@*|*|comment|processing-instruction"/> </revisionDesc> </xsl:template> <xsl:template match="publicationStmt"> <publicationStmt> <xsl:apply-templates select="@*|*|comment|processing-instruction"/> </publicationStmt> </xsl:template> <xsl:template match="space/@extent"> <xsl:attribute name="quantity"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template>

<xsl:template match="tagsDecl"> <xsl:if test="*"> <tagsDecl> <namespace name="http://www.tei-c.org/ns/1.0"> <xsl:apply-templates select="*|comment|processing-instruction"/> </tagsDecl> </xsl:if> </xsl:template> <xsl:template match="orgName/orgTitle"> <xsl:apply-templates/> </xsl:template>

<xsl:template match="corr[@sic]"> <xsl:value-of select="text" /> <xsl:value-of select="@sic" /> </xsl:template> <xsl:template match="gap/@desc"> <xsl:value-of select="."/> </xsl:template>

<xsl:template match="sic[@corr]"> <xsl:apply-templates/> <xsl:value-of select="@corr" /> </xsl:template> <xsl:template match="abbr[@expan]"> <xsl:apply-templates/> <xsl:value-of select="@expan" /> </xsl:template> <xsl:template match="expan[@abbr]"> <xsl:apply-templates/> <xsl:value-of select="@abbr" /> </xsl:template> <xsl:template match="change"> <xsl:apply-templates select="@*"/> <xsl:apply-templates select="item/@*"/> <xsl:apply-templates select="date"/> <xsl:if test="respStmt/resp"> <xsl:value-of select="respStmt/resp/text"/> </xsl:if> <xsl:for-each select="respStmt/name"> <xsl:apply-templates select="@*|*|comment|processing-instruction|text"/> </xsl:for-each> <xsl:for-each select="item"> <xsl:apply-templates select="*|comment|processing-instruction|text"/> </xsl:for-each> <xsl:apply-templates select="comment"/> </xsl:template>

<xsl:template match="respStmt[resp]"> <respStmt> <xsl:apply-templates select="@*"/> <xsl:choose> <xsl:when test="resp/name"> <xsl:value-of select="resp/text"/> <xsl:for-each select="resp/name"> <xsl:apply-templates/> </xsl:for-each> </xsl:when>  <xsl:apply-templates select="*|comment|processing-instruction|text"/> </xsl:otherwise> </xsl:choose> </respStmt> </xsl:template>

<xsl:template match="q/@direct"/> <xsl:template match="q"> <xsl:apply-templates select="@*|*|comment|processing-instruction|text"/> </xsl:template>

<xsl:template match="@targOrder"> <xsl:if test="not(translate(.,$uc,$lc) ='u')"> <xsl:attribute name="targOrder"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="@opt"> <xsl:if test="not(translate(.,$uc,$lc) ='n')"> <xsl:attribute name="opt"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="@to"> <xsl:if test="not(translate(.,$uc,$lc) ='ditto')"> <xsl:attribute name="to"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="@default"> <xsl:choose> <xsl:when test="translate(.,$uc,$lc)= 'no'"/>  <xsl:attribute name="default"> <xsl:value-of select="."/> </xsl:attribute> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="@part"> <xsl:if test="not(translate(.,$uc,$lc) ='n')"> <xsl:attribute name="part"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="@full"> <xsl:if test="not(translate(.,$uc,$lc) ='yes')"> <xsl:attribute name="full"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="@from"> <xsl:if test="not(translate(.,$uc,$lc) ='root')"> <xsl:attribute name="from"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="@status"> <xsl:choose> <xsl:when test="parent::teiHeader"> <xsl:if test="not(translate(.,$uc,$lc) ='new')"> <xsl:attribute name="status"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:when> <xsl:when test="parent::del"> <xsl:if test="not(translate(.,$uc,$lc) ='unremarkable')"> <xsl:attribute name="status"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:when>  <xsl:attribute name="status"> <xsl:value-of select="."/> </xsl:attribute> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="@place"> <xsl:if test="not(translate(.,$uc,$lc) ='unspecified')"> <xsl:attribute name="place"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="@sample"> <xsl:if test="not(translate(.,$uc,$lc) ='complete')"> <xsl:attribute name="sample"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="@org"> <xsl:if test="not(translate(.,$uc,$lc) ='uniform')"> <xsl:attribute name="org"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="@type"> <xsl:variable name="normal"> <xsl:value-of select="translate(translate(.,'-',''),$uc,$lc)"/> </xsl:variable>

<xsl:variable name="unsub"> <xsl:choose> <xsl:when test="$normal='subsection'">section</xsl:when> <xsl:when test="$normal='subsubsection'">section</xsl:when> <xsl:when test="$normal='subsubsubsection'">section</xsl:when> <xsl:when test="$normal='subsubsubsubsection'">section</xsl:when> <xsl:when test="$normal='subsubsubsubsubsection'">section</xsl:when> <xsl:when test="$normal='subsubsubsubsubsubsection'">section</xsl:when> <xsl:when test="$normal='poem'">verse</xsl:when> <xsl:when test="$normal='poetry'">verse</xsl:when> <xsl:when test="$normal='acknowledgement'">acknowledgements</xsl:when> <xsl:when test="$normal='reference'">references</xsl:when> <xsl:when test="$normal='notes'">note</xsl:when> <xsl:when test="$normal='chpater'">chapter</xsl:when> <xsl:when test="$normal='front cover'">cover</xsl:when> <xsl:when test="$normal='back cover'">cover</xsl:when> <xsl:when test="$normal='author index'">index</xsl:when> <xsl:when test="$normal='subject index'">index</xsl:when> <xsl:when test="$normal='illus'">illustration</xsl:when> <xsl:when test="$normal='article text'">article</xsl:when> <xsl:when test="$normal='cutting from catalogue'">cutting</xsl:when> <xsl:when test="contains(., ' ')"><xsl:value-of select="."/></xsl:when>  <xsl:value-of select="$normal"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:attribute name="type"> <xsl:value-of select="$unsub"/> </xsl:attribute> </xsl:template>

<xsl:template match="@type[contains(.,' ')][not (parent::*/@n)][not (normalize-space(.)='')]"> <xsl:attribute name="n"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template>

<xsl:template match="@type[normalize-space(.)='']"> </xsl:template>

<xsl:template match="title/@type[.='245']"> <xsl:attribute name="type">marc245</xsl:attribute> </xsl:template> <xsl:template match="@anchored"> <xsl:attribute name="anchored"> <xsl:choose> <xsl:when test="translate(.,$uc,$lc)='yes'">true</xsl:when> <xsl:when test="translate(.,$uc,$lc)='no'">false</xsl:when> </xsl:choose> </xsl:attribute> </xsl:template> <xsl:template match="sourceDesc/@default"/> <xsl:template match="@tei"> <xsl:attribute name="tei"> <xsl:choose> <xsl:when test="translate(.,$uc,$lc)='yes'">true</xsl:when> <xsl:when test="translate(.,$uc,$lc)='no'">false</xsl:when> </xsl:choose> </xsl:attribute> </xsl:template> <xsl:template match="textClass/@default|biblFull/@default"> <xsl:attribute name="default"> <xsl:choose> <xsl:when test="translate(.,$uc,$lc)='yes'">true</xsl:when> <xsl:when test="translate(.,$uc,$lc)='no'">false</xsl:when> </xsl:choose> </xsl:attribute> </xsl:template> <xsl:template match="@langKey"/> <xsl:template match="@TEIform"/>

<xsl:template match="@old"/>

<xsl:template match="@mergedin"> <xsl:attribute name="mergedIn"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template>

<xsl:template match="div0|div1|div2|div3|div4|div5|div6"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> </xsl:template>

<xsl:template match="orig[@reg]"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> <xsl:value-of select="@reg"/> </xsl:template>

<xsl:template match="reg[@orig]"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> <xsl:value-of select="@orig"/> </xsl:template>

<xsl:template match="@orig|@reg"/>

<xsl:template match="name[not(@key)]"> <xsl:apply-templates select="@*"/> <xsl:choose> <xsl:when test="@reg"> <xsl:apply-templates select="*|processing-instruction|comment|text"/> <xsl:value-of select="@reg"/> </xsl:when>  <xsl:apply-templates select="*|processing-instruction|comment|text"/> </xsl:otherwise> </xsl:choose> </xsl:template>

<xsl:template match="@scheme[contains (., 'nzetc-subjects')]"> <xsl:attribute name="scheme">http://www.nzetc.org/nzetc-subjects</xsl:attribute> </xsl:template>

<xsl:template match="@scheme[contains (., 'nzetc-mads')]"> <xsl:attribute name="scheme">http://www.nzetc.org/nzetc-mads</xsl:attribute> </xsl:template>

<xsl:template match="keywords[not(@scheme)]"> <xsl:attribute name="scheme">http://www.example.org/folksonomy</xsl:attribute> <xsl:apply-templates select="@*|*|processing-instruction|comment|text"/> </xsl:template>

<xsl:template match="text[not(parent::TEI|parent::TEI.2|parent::group)]"> <floatingText> <xsl:apply-templates select="@*|*|processing-instruction|comment|text"/> </floatingText> </xsl:template>

<xsl:template match="p[text][not(parent::quote)]|div[text][not(parent::quote)]"> <xsl:apply-templates select="@*|*|processing-instruction|comment|text"/> </xsl:template>

<xsl:template match="p[text][parent::quote]|div[text][parent::quote]"> <xsl:apply-templates select="*|processing-instruction|comment|text"/> </xsl:template>

<xsl:template match="figDesc/hi"> <xsl:apply-templates select="@*|*|processing-instruction|comment|text"/> </xsl:template>

<xsl:template match="add[p]"> <xsl:variable name="count" select="count(preceding::add[p])"/> <addSpan> <xsl:attribute name="spanTo">#addSpan-<xsl:value-of select="$count"/></xsl:attribute> <xsl:apply-templates select="@*"/> </addSpan> <xsl:apply-templates select="*|processing-instruction|comment|text"/> <xsl:attribute name="xml:id">addSpan-<xsl:value-of select="$count"/></xsl:attribute> </xsl:template>

<xsl:template match="list[not(node)]"/>

<xsl:template match="title[not(text)][not(child::*)]"/>

<xsl:template match="pb/@n[.=]|div/@n[.=]"/>

<xsl:template match="xref/@type[starts-with(.,'http://')]"> <xsl:attribute name="target"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template>

<xsl:template match="bibl[parent::listBibl][following-sibling::*[1][local-name='pb']]"> <xsl:element name="bibl"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> <xsl:apply-templates select="following-sibling::pb[1]"/> </xsl:element> </xsl:template>

<xsl:template match="listBibl/pb"/>

<xsl:template match="change/item/p"> <xsl:apply-templates select="*|@*|processing-instruction|comment|text"/> </xsl:template>

</xsl:stylesheet>