<xslt:stylesheet xmlns:xslt="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- ==================================================== xml2html.xslt, (c) 2005 Linkwerk.com, Stefan Mintert, All rights reserved. Check http://www.linkwerk.com/pub/xml/xml2html/ for legal information. In no case may this copyright notice be removed. This XSLT stylesheet converts an input XML instance to HTML. Known issues: - Handling of namespaces is experimental. May not work properly. . Do not use more than one ns prefix for one ns. . Namespaces in the XPath data model are "visible" only where they are used, not where they are declared. - Empty elements are written as starttag/endtag, not as empty element tag. - Whitespace is not preserved, but normalized. This may be a problem depending on the semantics of some element types. - Everything that is not accessible with XPath is dropped, i.e. DOCTYPE declaration, XML declaration. - The ampersand is not escaped. Therefore the character referenced by a character entity is written, instead of the entity itself. $Revision: 1.7 $ $Date: 2006/10/19 11:47:31 $ ==================================================== -->
<!-- ==================================================== -->
<!-- = Set output method to XML, but mime-type to HTML. = -->
<!-- ==================================================== -->
<xslt:output method="xml" encoding="utf-8" media-type="text/html"></xslt:output>
<!-- ==================================================== -->
<!-- = Control of output: verbose (default) or short = -->
<!-- = ("short" = no html, head and body elements) = -->
<!-- ==================================================== -->
<xslt:param name="htmloutput">
verbose
</xslt:param>
<!-- ==================================================== -->
<!-- = How to handle comments: drop or show = -->
<!-- ==================================================== -->
<xslt:param name="comments">
show
</xslt:param>
<!-- ==================================================== -->
<!-- = START with/without HTML container elements = -->
<!-- ==================================================== -->
<xslt:template match="/">
<xslt:message>
WARNING: Handling of namespace declarations is experimental. Please check for correct output.
</xslt:message>
<xslt:choose>
<xslt:when test="$htmloutput = 'short'">
<xslt:comment>
Generated by xml2html.xslt, (c) Linkwerk.com 2005, Do not remove this copyright note, www.linkwerk.com/pub/xml/xml2html/
</xslt:comment>
<xslt:comment>
Include this file in an HTML page and link to xml2html.css, available at www.linkwerk.com/pub/xml/xml2html/, to get an approriate rendering
</xslt:comment>
<xslt:call-template name="xml2html-start"></xslt:call-template>
</xslt:when>
<xslt:otherwise>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
HTML rendering of a XML instance
</title>
<link rel="stylesheet" type="text/css" href="xml2html.css"></link>
<meta name="generator" content="xml2html.xslt by Linkwerk, www.linkwerk.com/pub/xml/xml2html/"></meta>
</head>
<body>
<xslt:comment>
Generated by xml2html.xslt, (c) Linkwerk.com 2005, Do not remove this copyright note, www.linkwerk.com/pub/xml/xml2html/
</xslt:comment>
<xslt:call-template name="xml2html-start"></xslt:call-template>
</body>
</html>
</xslt:otherwise>
</xslt:choose>
</xslt:template>
<!-- ==================================================== -->
<!-- = This is where it really starts = -->
<!-- ==================================================== -->
<xslt:template name="xml2html-start">
<div xmlns="http://www.w3.org/1999/xhtml" xmlns:xml="http://www.w3.org/XML/1998/namespace" class="xml2html root" xml:space="default">
<xslt:apply-templates select="*"></xslt:apply-templates>
<div class="xml2html comment copyright">
<!-- Generated with
<a class="xml2html" href="http://www.linkwerk.com/pub/xml/xml2html/">
xml2html.xslt
</a>
, Linkwerk.com -->
</div>
</div>
</xslt:template>
<!-- ==================================================== -->
<!-- = Processing of elements = -->
<!-- ==================================================== -->
<xslt:template match="*">
<!-- Elements from known namespace are linked to their specification -->
<xslt:variable name="url">
<xslt:choose>
<xslt:when test="namespace-uri() = 'http://www.w3.org/1999/XSL/Transform'">
<xslt:choose>
<xslt:when test="(ancestor-or-self::xslt:stylesheet[@version = '2.0']) or (ancestor-or-self::xslt:transform[@version = '2.0'])">
<xslt:text>
http://www.w3.org/TR/xslt20/#element-
</xslt:text>
</xslt:when>
<xslt:otherwise>
<!-- Default: Link with XSLT 1.0 spec -->
<xslt:text>
http://www.w3.org/TR/1999/REC-xslt-19991116.html#element-
</xslt:text>
</xslt:otherwise>
</xslt:choose>
<xslt:value-of select="local-name()"></xslt:value-of>
</xslt:when>
<xslt:when test="namespace-uri() = 'http://exslt.org/functions'">
<xslt:text>
http://exslt.org/func/elements/
</xslt:text>
<xslt:value-of select="local-name()"></xslt:value-of>
</xslt:when>
<xslt:when test="namespace-uri() = 'http://exslt.org/dates-and-times'">
<xslt:text>
http://exslt.org/date/elements/
</xslt:text>
<xslt:value-of select="local-name()"></xslt:value-of>
</xslt:when>
<xslt:when test="namespace-uri() = 'http://exslt.org/common'">
<xslt:text>
http://exslt.org/exsl/elements/
</xslt:text>
<xslt:value-of select="local-name()"></xslt:value-of>
</xslt:when>
<xslt:when test="namespace-uri() = 'http://exslt.org/common'">
<xslt:text>
http://exslt.org/exsl/elements/
</xslt:text>
<xslt:value-of select="local-name()"></xslt:value-of>
</xslt:when>
<xslt:otherwise></xslt:otherwise>
</xslt:choose>
</xslt:variable>
<div xmlns="http://www.w3.org/1999/xhtml" class="element xml2html">
<span class="starttag xml2html">
<xslt:choose>
<xslt:when test="$url != ''">
<
<a class="xml2html" href="{$url}">
<xslt:value-of select="name()"></xslt:value-of>
</a>
</xslt:when>
<xslt:otherwise>
<
<xslt:value-of select="name()"></xslt:value-of>
</xslt:otherwise>
</xslt:choose>
<xslt:apply-templates select="." mode="process-ns-declarations"></xslt:apply-templates>
<xslt:apply-templates select="@*"></xslt:apply-templates>
>
</span>
<xslt:if test="*|comment()|processing-instruction()|text()">
<div class="elementcontent xml2html">
<xslt:apply-templates select="*|comment()|processing-instruction()|text()"></xslt:apply-templates>
</div>
</xslt:if>
<span class="endtag xml2html">
</
<xslt:value-of select="name()"></xslt:value-of>
>
</span>
</div>
</xslt:template>
<!-- ==================================================== -->
<!-- = Processing of attributes = -->
<!-- ==================================================== -->
<xslt:template match="@*">
<xslt:text>
</xslt:text>
<span xmlns="http://www.w3.org/1999/xhtml" class="attributename xml2html">
<xslt:value-of select="name()"></xslt:value-of>
</span>
<xslt:text>
="
</xslt:text>
<span xmlns="http://www.w3.org/1999/xhtml" class="attributevalue xml2html">
<xslt:value-of select="."></xslt:value-of>
</span>
<xslt:text>
"
</xslt:text>
</xslt:template>
<!-- ==================================================== -->
<!-- = Processing of PIs = -->
<!-- ==================================================== -->
<xslt:template match="processing-instruction()">
<div xmlns="http://www.w3.org/1999/xhtml" class="pi xml2html">
<?
<xslt:value-of select="local-name()"></xslt:value-of>
<xslt:text>
</xslt:text>
<xslt:value-of select="."></xslt:value-of>
?>
</div>
</xslt:template>
<!-- ==================================================== -->
<!-- = Processing of comments = -->
<!-- ==================================================== -->
<xslt:template match="comment()">
<xslt:if test="$comments != 'drop'">
<div xmlns="http://www.w3.org/1999/xhtml" class="comment xml2html">
<!--
<xslt:value-of select="."></xslt:value-of>
-->
</div>
</xslt:if>
</xslt:template>
<!-- ==================================================== -->
<!-- = Processing of namespace declarations = -->
<!-- ==================================================== -->
<xslt:template match="*|@*" mode="process-ns-declarations">
<!-- Process namespace of the element -->
<xslt:if test="namespace-uri() != ''">
<xslt:variable name="ns-prefix">
<xslt:value-of select="substring-before(substring-before(name(),local-name()),':')"></xslt:value-of>
</xslt:variable>
<xslt:variable name="ns-prefix-withcolon">
<xslt:choose>
<xslt:when test="$ns-prefix = ''"></xslt:when>
<xslt:otherwise>
<xslt:text>
:
</xslt:text>
<xslt:value-of select="$ns-prefix"></xslt:value-of>
</xslt:otherwise>
</xslt:choose>
</xslt:variable>
<xslt:if test="not(ancestor::*[(namespace-uri() = namespace-uri(current())) and (substring-before(name(),local-name()) = substring-before(name(current()),local-name(current())))])">
<xslt:text>
</xslt:text>
<span xmlns="http://www.w3.org/1999/xhtml" class="attributename xml2html">
xmlns
<xslt:value-of select="$ns-prefix-withcolon"></xslt:value-of>
</span>
<xslt:text>
="
</xslt:text>
<span xmlns="http://www.w3.org/1999/xhtml" class="attributevalue xml2html">
<xslt:value-of select="namespace-uri()"></xslt:value-of>
</span>
<xslt:text>
"
</xslt:text>
</xslt:if>
</xslt:if>
<!-- Process namespaces of the attributes -->
<xslt:for-each select="./@*">
<xslt:apply-templates select="." mode="process-ns-declarations"></xslt:apply-templates>
</xslt:for-each>
</xslt:template>
<!-- The following elements have no meaning to the XSLT enginge. Their purpose is to test this program. Run it with itself as the input XML instance -->
<a:b xmlns:a="bla" xmlns:c="ns-c" c:att="val">
<b xmlns="http://ns.example.com/"></b>
</a:b>
</xslt:stylesheet>