You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Luke Flesch <lu...@yale.edu> on 2000/11/19 05:59:30 UTC
XML + XSL -> XHTML
I'm trying to generate XHTML from XML using XSL on Cocoon. This
is a test derived from the W3C Recommendation.
Test.xml:
<?xml version="1.0"?>
<?xml-stylesheet href="XSL/test.xhtml.xsl" type="text/xsl"?>
<?cocoon-process type="xslt"?>
<doc>
<title>Document Title</title>
<chapter>
<title>Chapter Title</title>
<section>
<title>Section Title</title>
<para>This is a test.</para>
<note>This is a note.</note>
</section>
<section>
<title>Another Section Title</title>
<para>This is <emph>another</emph> test.</para>
<note>This is another note.</note>
</section>
</chapter>
</doc>
Test.xhtml.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/strict">
<xsl:strip-space elements="doc chapter section"/>
<xsl:output
method="xml"
indent="yes"
encoding="iso-8859-1"
/>
<xsl:template match="doc">
<html>
<head>
<title>
<xsl:value-of select="title"/>
</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="doc/title">
<h1>
<xsl:apply-templates/>
</h1>
</xsl:template>
<xsl:template match="chapter/title">
<h2>
<xsl:apply-templates/>
</h2>
</xsl:template>
<xsl:template match="section/title">
<h3>
<xsl:apply-templates/>
</h3>
</xsl:template>
<xsl:template match="para">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="note">
<p class="note">
<b>NOTE: </b>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="emph">
<em>
<xsl:apply-templates/>
</em>
</xsl:template>
</xsl:stylesheet>
Output:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html xmlns="http://www.w3.org/TR/xhtml1/strict">
<head>
<title>Document Title</title>
</head>
<body>
<h1>Document Title</h1>
<h2>Chapter Title</h2>
<h3>Section Title</h3>
<p>This is a test.</p>
<p class="note">
<b>NOTE: </b>
This is a note.
</p>
<h3>Another Section Title</h3>
<p>This is
<em>another</em>
test.
</p>
<p class="note">
<b>NOTE:</b>
This is another note.
</p>
</body>
</html>
<!-- This page was served from cache in 4 milliseconds by Cocoon 1.8 -->
As far as I can tell, the output is valid XHTML except for the first line.
I don't know how to modify the DOCTYPE. Can someone help?
-Luke Flesch
Re: XML + XSL -> XHTML
Posted by Donald Ball <ba...@webslingerZ.com>.
On Sat, 18 Nov 2000, Luke Flesch wrote:
> I'm trying to generate XHTML from XML using XSL on Cocoon. This
> is a test derived from the W3C Recommendation.
use <?cocoon-format type="text/xhtml"?>
- donald