TEI to XHTML in XSLT 1

Here should go questions about transforming XML with XSLT and FOP.
Garzo
Posts: 1
Joined: Wed May 28, 2014 5:20 pm

TEI to XHTML in XSLT 1

Post by Garzo »

I am fairly new to writing XSLT. I have a basic XSLT2 stylesheet for transforming TEI into XHTML. However, it cannot be used by most web browsers, and I don't seem to be able to turn it into functioning XSLT1. The original XSLT2 is

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="2.0">

<xsl:template match="TEI">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>
<xsl:value-of select="teiHeader/fileDesc/titleStmt/title"/>
</title>
</head>
<body>
<xsl:apply-templates select="text/front"/>
<xsl:apply-templates select="text/body"/>
</body>
</html>
</xsl:template>

<xsl:template match="front">
<h1>
<xsl:value-of select="titlePage/docTitle/titlePart[@type='main']"/>
</h1>
<h2>
<xsl:value-of select="titlePage/docTitle/titlePart[@type='sub']"/>
</h2>
<h3><xsl:value-of select="titlePage/byline/docAuthor"/>, <xsl:value-of
select="titlePage/docImprint/pubPlace"/></h3>
</xsl:template>

<xsl:template match="body">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="p">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>

<xsl:template match="foreign">
<em>
<xsl:apply-templates/>
</em>
</xsl:template>

<xsl:template match="q|soCalled"> ‘<xsl:apply-templates/>’ </xsl:template>

<xsl:template match="placeName">
<u>
<xsl:apply-templates/>
</u>
</xsl:template>

<xsl:template match="persName">
<strong>
<xsl:apply-templates/>
</strong>
</xsl:template>
</xsl:stylesheet>
Can anyone help me out?

Thanks,

Gareth.
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: TEI to XHTML in XSLT 1

Post by adrian »

Hi,

To convert this to XSLT 1.0 you need to:
- remove the @xpath-default-namespace attribute which is specific to 2.0
- declare a namespace prefix for the TEI namespace: xmlns:ns="http://www.tei-c.org/ns/1.0" version="1.0"
- exclude that namespace from the result: exclude-result-prefixes="ns"
- and add the namespace prefix to all elements mentioned everywhere in the stylesheet (ns:TEI, ns:body, etc)


This is the end result, I left commented the output indent instruction:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://www.tei-c.org/ns/1.0" version="1.0"
exclude-result-prefixes="ns">
<!--<xsl:output indent="yes"/>-->

<xsl:template match="ns:TEI">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>
<xsl:value-of select="ns:teiHeader/ns:fileDesc/ns:titleStmt/ns:title"/>
</title>
</head>
<body>
<xsl:apply-templates select="ns:text/ns:front"/>
<xsl:apply-templates select="ns:text/ns:body"/>
</body>
</html>
</xsl:template>

<xsl:template match="ns:front">
<h1>
<xsl:value-of select="ns:titlePage/ns:docTitle/ns:titlePart[@type='main']"/>
</h1>
<h2>
<xsl:value-of select="ns:titlePage/ns:docTitle/ns:titlePart[@type='sub']"/>
</h2>
<h3><xsl:value-of select="ns:titlePage/ns:byline/ns:docAuthor"/>, <xsl:value-of
select="ns:titlePage/ns:docImprint/ns:pubPlace"/></h3>
</xsl:template>

<xsl:template match="ns:body">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="ns:p">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>

<xsl:template match="ns:foreign">
<em>
<xsl:apply-templates/>
</em>
</xsl:template>

<xsl:template match="ns:q|ns:soCalled"> ‘<xsl:apply-templates/>’ </xsl:template>

<xsl:template match="ns:placeName">
<u>
<xsl:apply-templates/>
</u>
</xsl:template>

<xsl:template match="ns:persName">
<strong>
<xsl:apply-templates/>
</strong>
</xsl:template>
</xsl:stylesheet>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply