<
xsl:
stylesheet xmlns:xd="
http://www.pnp-software.com/XSLTdoc"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="
http://exslt.org/common"
xmlns:tei="
http://www.tei-c.org/ns/1.0"
version="
1.0"
extension-element-prefixes="
exsl"
exclude-result-prefixes="
tei xd exsl">
<
xd:
doc type="
stylesheet">
<
xd:
short>
Convert TEI header to HTML.</
xd:
short>
<
xd:
author>
Tomaž Erjavec tomaz.erjavec@ijs.si</
xd:
author>
<
xd:
date>
2009-04-29</
xd:
date>
<
xd:
detail>
This library is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software Foundation;
either version 2.1 of the License, or (at your option) any later version. This library is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even thee
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details. You should have received a copy of the GNU Lesser
General Public License along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA </
xd:
detail>
</
xd:
doc>
<
xd:
doc>
If set, show also tags</
xd:
doc>
<
xsl:
param name="
debug" />
<
xd:
doc>
CSS to use</
xd:
doc>
<
xsl:
param name="
cssFile">
ezrc.css</
xsl:
param>
<
xd:
doc>
Localisation language</
xd:
doc>
<
xsl:
param name="
localisation">
sl</
xsl:
param>
<
xd:
doc>
Output language</
xd:
doc>
<
xsl:
param name="
language"
select="
$localisation" />
<
xd:
doc>
TEI file with localisations</
xd:
doc>
<
xsl:
param name="
localisation-file">
teiLocalise-sl.xml</
xsl:
param>
<
xd:
doc>
TEI document with localisations</
xd:
doc>
<
xsl:
variable name="
tei-localisation"
select="
document($localisation-file)" />
<
xd:
doc>
URL with TEI element documentation</
xd:
doc>
<
xsl:
param name="
tei-url">
http://www.tei-c.org/release/doc/tei-p5-doc/en/html/</
xsl:
param>
<
xd:
doc>
Title of HTML page</
xd:
doc>
<
xsl:
param name="
html-title">
<
xsl:
choose>
<
xsl:
when test="
$localisation = 'sl'">
<
xsl:
text>
Kolofon TEI</
xsl:
text>
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
text>
TEI Header</
xsl:
text>
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
param>
<
xd:
doc>
URL for access of NUK holdings via COBISS/IZUM, needs COBISS ID for valid URL</
xd:
doc>
<
xsl:
param name="
COBISS-URL">
<
xsl:
text>
http://cobiss.izum.si/scripts/cobiss?command=DISPLAY&base=50001&rid=</
xsl:
text>
</
xsl:
param>
<
xsl:
output method="
html"
encoding="
utf-8"
indent="
yes" />
<
xsl:
key name="
id"
match="
tei:*"
use="
@xml:id" />
<
xsl:
key name="
corresp"
match="
tei:*"
use="
@corresp" />
<
xd:
doc>
<
xd:
short>
HTML structure and start table</
xd:
short>
</
xd:
doc>
<
xsl:
template match="
/">
<
HTML>
<
HEAD>
<
TITLE>
<
xsl:
value-of select="
$html-title" />
</
TITLE>
<
meta http-equiv="
Content-Type"
content="
text/html; charset=utf-8" />
<
xsl:
if test="
normalize-space($cssFile)">
<
LINK rel="
stylesheet"
type="
text/css"
href="
{$cssFile}" />
</
xsl:
if>
</
HEAD>
<
BODY>
<
xsl:
apply-templates select="
//tei:teiHeader" />
<
HR />
</
BODY>
</
HTML>
</
xsl:
template>
<
xsl:
template match="
tei:teiHeader">
<
H1>
<
xsl:
call-template name="
gi-gloss">
<
xsl:
with-param name="
gi"
select="
name()" />
</
xsl:
call-template>
</
H1>
<
TABLE border="
1">
<
xsl:
apply-templates select="
//tei:teiHeader/tei:*" />
</
TABLE>
</
xsl:
template>
<
xd:
doc>
<
xd:
short>
Output one element, if in appropriate language.</
xd:
short>
</
xd:
doc>
<
xsl:
template match="
tei:*">
<!---->
<
xsl:
if test="
not(@xml:lang) or @xml:lang=$language or @xml:lang='lat' or @xml:lang='ger'">
<
xsl:
call-template name="
element" />
</
xsl:
if>
</
xsl:
template>
<
xd:
doc>
<
xd:
short>
Output element either in-line if mixed content, or as a HTML table row</
xd:
short>
</
xd:
doc>
<
xsl:
template name="
element">
<
xsl:
choose>
<
xsl:
when test="
normalize-space(preceding-sibling::text()) or normalize-space(following-sibling::text())">
<!---->
<
xsl:
apply-templates />
<
SUB>
<
xsl:
call-template name="
start-tag" />
</
SUB>
</
xsl:
when>
<
xsl:
otherwise>
<
TR>
<
TD valign="
top">
<
xsl:
if test="
$debug">
<
xsl:
call-template name="
tag" />
<
BR />
</
xsl:
if>
<
xsl:
call-template name="
id-mark" />
<
B>
<
xsl:
call-template name="
gi-gloss" />
</
B>
<
xsl:
if test="
@*">
<
BR />
<
xsl:
for-each select="
@*">
<
xsl:
call-template name="
att-gloss" />
<
xsl:
text>
</
xsl:
text>
</
xsl:
for-each>
</
xsl:
if>
</
TD>
<
TD>
<
xsl:
choose>
<
xsl:
when test="
name() = 'tagUsage'">
<
xsl:
call-template name="
gi-gloss">
<
xsl:
with-param name="
gi"
select="
@gi" />
</
xsl:
call-template>
</
xsl:
when>
<
xsl:
when test="
name() = 'fs'">
<
xsl:
call-template name="
fs-feats">
<
xsl:
with-param name="
refs"
select="
@feats" />
</
xsl:
call-template>
</
xsl:
when>
<
xsl:
when test="
tei:p or tei:list or normalize-space(./text()) or normalize-space(tei:ref/text())">
<
xsl:
apply-templates />
</
xsl:
when>
<
xsl:
otherwise>
<
TABLE border="
1">
<
xsl:
apply-templates />
</
TABLE>
</
xsl:
otherwise>
</
xsl:
choose>
</
TD>
</
TR>
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
template>
<
xd:
doc>
<
xd:
short>
Put mark with explicit name, to be able to refer to it in HTML.</
xd:
short>
</
xd:
doc>
<
xsl:
template name="
id-mark">
<
xsl:
if test="
not(ancestor::tei:*[6])">
<
xsl:
variable name="
lid">
<
xsl:
variable name="
gi"
select="
name()" />
<
xsl:
choose>
<
xsl:
when test="
@xml:id">
<
xsl:
value-of select="
@xml:id" />
</
xsl:
when>
<!---->
<
xsl:
otherwise>
<
xsl:
text>
loc.</
xsl:
text>
<
xsl:
number count="
tei:*"
level="
multiple" />
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
variable>
<
A href="
#{$lid}"
name="
{$lid}"
title="
ID = {$lid}">
<
SUP>
<
xsl:
text>
§</
xsl:
text>
</
SUP>
</
A>
</
xsl:
if>
</
xsl:
template>
<
xd:
doc>
<
xd:
short>
Output start tag more or less as is.</
xd:
short>
</
xd:
doc>
<
xsl:
template name="
tag">
<
xsl:
param name="
gi"
select="
name()" />
<
SMALL>
<
xsl:
text>
<</
xsl:
text>
<
xsl:
value-of select="
$gi" />
<
xsl:
for-each select="
@*">
<
xsl:
text>
</
xsl:
text>
<
xsl:
value-of select="
name()" />
<
xsl:
text>
=</
xsl:
text>
<
xsl:
value-of select="
." />
</
xsl:
for-each>
<
xsl:
text>
></
xsl:
text>
<
SUB>
<
xsl:
number level="
any"
from="
TEI" />
</
SUB>
</
SMALL>
</
xsl:
template>
<
xsl:
template name="
start-tag">
<
B>
<
xsl:
text>
<</
xsl:
text>
<
xsl:
call-template name="
gi-gloss" />
<
xsl:
if test="
$debug">
<
xsl:
text>
</
xsl:
text>
<
xsl:
call-template name="
tag" />
</
xsl:
if>
<
xsl:
text>
></
xsl:
text>
</
B>
</
xsl:
template>
<
xsl:
template name="
end-tag">
<
B>
<
xsl:
text>
</</
xsl:
text>
<
xsl:
call-template name="
gi-gloss" />
<
xsl:
text>
></
xsl:
text>
</
B>
</
xsl:
template>
<
xd:
doc>
<
xd:
short>
Output localised attribute gloss</
xd:
short>
</
xd:
doc>
<
xsl:
template name="
att-gloss">
<
xsl:
param name="
att"
select="
name()" />
<
xsl:
param name="
val"
select="
normalize-space(.)" />
<
xsl:
variable name="
att_loc"
select="
exsl:node-set($tei-localisation)//tei:attDef[@ident=$att]" />
<
xsl:
variable name="
val_loc"
select="
exsl:node-set($att_loc)/tei:valList/tei:valItem[@ident=$val]" />
<!---->
<
xsl:
if test="
normalize-space($att_loc) and not($att='xml:lang' and $val=$language) and $att!='feats'">
<
B>
<
xsl:
call-template name="
glosstext">
<
xsl:
with-param name="
ident"
select="
$att" />
<
xsl:
with-param name="
text"
select="
$att_loc" />
</
xsl:
call-template>
</
B>
<
xsl:
text>
= </
xsl:
text>
<
xsl:
choose>
<
xsl:
when test="
$att = 'id' or $att = 'xml:id'">
<
A name="
{$val}">
<
xsl:
value-of select="
$val" />
</
A>
</
xsl:
when>
<
xsl:
when test="
$att='xml:lang' or $att='mainLang'">
<
xsl:
value-of select="
//tei:teiHeader//tei:langUsage/tei:language[@ident=$val]/tei:term[@xml:lang=$language]" />
</
xsl:
when>
<
xsl:
when test="
$att='corresp' or $att='feats' or $att='who'">
<
xsl:
call-template name="
idrefs">
<
xsl:
with-param name="
refs"
select="
$val" />
</
xsl:
call-template>
</
xsl:
when>
<
xsl:
when test="
normalize-space($val_loc)">
<
I>
<
xsl:
call-template name="
glosstext">
<
xsl:
with-param name="
ident"
select="
$val" />
<
xsl:
with-param name="
text"
select="
$val_loc" />
</
xsl:
call-template>
</
I>
</
xsl:
when>
<
xsl:
otherwise>
<
I>
<
xsl:
value-of select="
$val" />
<
xsl:
if test="
$debug and translate($val,'0123456789-.,','')">
<
font color="
red">
!</
font>
</
xsl:
if>
</
I>
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
if>
</
xsl:
template>
<
xd:
doc>
<
xd:
short>
Output localised element gloss.</
xd:
short>
</
xd:
doc>
<
xsl:
template name="
gi-gloss">
<
xsl:
param name="
gi"
select="
name()" />
<
xsl:
variable name="
url">
<
xsl:
value-of select="
$tei-url" />
<
xsl:
text>
ref-</
xsl:
text>
<
xsl:
value-of select="
$gi" />
<
xsl:
text>
.html</
xsl:
text>
</
xsl:
variable>
<
xsl:
variable name="
text"
select="
exsl:node-set($tei-localisation)//tei:elementSpec[@ident=$gi]" />
<
A href="
{$url}"
title="
{$gi}">
<
xsl:
call-template name="
glosstext">
<
xsl:
with-param name="
ident"
select="
$gi" />
<
xsl:
with-param name="
text"
select="
$text" />
</
xsl:
call-template>
</
A>
</
xsl:
template>
<
xd:
doc>
<
xd:
short>
Output gloss text from localisation file. Uses exsl:node-set</
xd:
short>
</
xd:
doc>
<
xsl:
template name="
glosstext">
<
xsl:
param name="
loc"
select="
$localisation" />
<
xsl:
param name="
ident" />
<
xsl:
param name="
text" />
<
xsl:
choose>
<
xsl:
when test="
$loc='en'">
<
xsl:
choose>
<
xsl:
when test="
normalize-space(exsl:node-set($text)/ tei:gloss[@xml:lang='en'])">
<
xsl:
value-of select="
exsl:node-set($text)/tei:gloss[@xml:lang='en']" />
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
value-of select="
$ident" />
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
when>
<
xsl:
when test="
$loc='sl'">
<
xsl:
value-of select="
exsl:node-set($text)/tei:gloss[@xml:lang='sl']" />
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
value-of select="
$ident" />
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
template>
<
xsl:
template name="
idrefs">
<
xsl:
param name="
refs" />
<
xsl:
choose>
<
xsl:
when test="
contains($refs,' ')">
<!---->
<
xsl:
call-template name="
idref">
<
xsl:
with-param name="
ref"
select="
substring-before($refs,' ')" />
</
xsl:
call-template>
<
xsl:
text>
, </
xsl:
text>
<
xsl:
call-template name="
idrefs">
<
xsl:
with-param name="
refs"
select="
substring-after($refs,' ')" />
</
xsl:
call-template>
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
call-template name="
idref">
<
xsl:
with-param name="
ref"
select="
$refs" />
</
xsl:
call-template>
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
template>
<
xsl:
template name="
idref">
<
xsl:
param name="
ref" />
<
xsl:
if test="
normalize-space($ref)">
<
A href="
{$ref}">
<
xsl:
choose>
<
xsl:
when test="
starts-with($ref,'#')">
<
xsl:
value-of select="
substring-after($ref,'#')" />
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
value-of select="
$ref" />
</
xsl:
otherwise>
</
xsl:
choose>
</
A>
</
xsl:
if>
</
xsl:
template>
<
xsl:
template name="
fs-feats">
<
xsl:
param name="
refs"
select="
@feats" />
<
xsl:
choose>
<
xsl:
when test="
contains($refs,' ')">
<
xsl:
call-template name="
fs-feat">
<
xsl:
with-param name="
ref"
select="
substring-before($refs,' ')" />
</
xsl:
call-template>
<
xsl:
text>
, </
xsl:
text>
<
xsl:
call-template name="
fs-feats">
<
xsl:
with-param name="
refs"
select="
substring-after($refs,' ')" />
</
xsl:
call-template>
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
call-template name="
fs-feat">
<
xsl:
with-param name="
ref"
select="
$refs" />
</
xsl:
call-template>
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
template>
<
xsl:
template name="
fs-feat">
<
xsl:
param name="
ref" />
<
xsl:
if test="
normalize-space($ref)">
<
xsl:
value-of select="
key('id',substring-after($ref,'#'))[not(@xml:lang) or @xml:lang=$language]/@name" />
<
xsl:
text>
= </
xsl:
text>
<
xsl:
value-of select="
key('id',substring-after($ref,'#'))[not(@xml:lang) or @xml:lang=$language]/tei:symbol/@value" />
</
xsl:
if>
</
xsl:
template>
<
xd:
doc>
<
xd:
short>
For possible capitalisation of glosses. Not used.</
xd:
short>
</
xd:
doc>
<
xsl:
template name="
case">
<
xsl:
param name="
str" />
<
xsl:
variable name="
lower">
<
xsl:
text>
abcčdefghijklmnopqrsštuvwxyzž</
xsl:
text>
</
xsl:
variable>
<
xsl:
variable name="
upper">
<
xsl:
text>
ABCČDEFGHIJKLMNOPQRSŠTUVWXYZŽ</
xsl:
text>
</
xsl:
variable>
<
xsl:
value-of select="
translate($str,$lower,$upper)" />
</
xsl:
template>
<
xd:
doc>
<
xd:
short>
Rendered elements</
xd:
short>
</
xd:
doc>
<
xsl:
template match="
tei:note[@type='COBISS_ID']/text()">
<
A>
<
xsl:
attribute name="
href">
<
xsl:
value-of select="
concat($COBISS-URL,.)" />
</
xsl:
attribute>
<
xsl:
value-of select="
." />
</
A>
</
xsl:
template>
<
xsl:
template match="
tei:lb">
<
BR />
</
xsl:
template>
<
xsl:
template match="
tei:addrLine">
<
xsl:
if test="
not(@xml:lang) or @xml:lang=$language">
<
xsl:
apply-templates />
<
BR />
</
xsl:
if>
</
xsl:
template>
<
xsl:
template match="
tei:p">
<
xsl:
if test="
not(@xml:lang) or @xml:lang=$language or @xml:lang='lat' or @xml:lang='ger'">
<
P>
<
xsl:
apply-templates />
</
P>
</
xsl:
if>
</
xsl:
template>
<
xsl:
template match="
tei:list">
<
xsl:
if test="
not(@xml:lang) or @xml:lang=$language or @xml:lang='lat' or @xml:lang='ger'">
<
UL>
<
xsl:
apply-templates />
</
UL>
</
xsl:
if>
</
xsl:
template>
<
xsl:
template match="
tei:item">
<
xsl:
if test="
not(@xml:lang) or @xml:lang=$language or @xml:lang='lat' or @xml:lang='ger'">
<!---->
<
LI>
<
xsl:
choose>
<
xsl:
when test="
normalize-space(./text())">
<
xsl:
apply-templates />
</
xsl:
when>
<
xsl:
otherwise>
<
TABLE border="
1">
<
xsl:
apply-templates />
</
TABLE>
</
xsl:
otherwise>
</
xsl:
choose>
</
LI>
</
xsl:
if>
</
xsl:
template>
<
xsl:
template match="
tei:hi">
<
EM>
<
xsl:
apply-templates />
</
EM>
</
xsl:
template>
<
xsl:
template match="
tei:q">
<
xsl:
text>
“</
xsl:
text>
<
xsl:
apply-templates />
<
xsl:
text>
”</
xsl:
text>
</
xsl:
template>
<
xsl:
template match="
tei:ref">
<
A href="
{@target}">
<
xsl:
apply-templates />
</
A>
</
xsl:
template>
</
xsl:
stylesheet>
v