<?xml-stylesheet href="http://www.w3.org/StyleSheets/base.css" type="text/css"?>
<?xml-stylesheet href="http://www.w3.org/2002/02/style-xsl.css" type="text/css"?>
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:html="http://www.w3.org/1999/xhtml" exclude-result-prefixes="html xsi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd" doctype-public="-//W3C//DTD XHTML Basic 1.1//EN" />

    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>Style sheet to transform XHTML 1.0 in XHTML Basic 1.1</title>
        <link rel="stylesheet" href="/StyleSheets/base.css"/>
      </head>
      <body>
      <div class='head'><a href="/"><img src='/Icons/w3c_home' alt='W3C'/></a></div>
      <h1>Style sheet to transform XHTML 1.x in XHTML Basic 1.1</h1>
      <h2>Abstract and Status</h2>
      <p>This style sheet allows to transform a valid <a href="http://www.w3.org/TR/xhtml1/">XHTML 1.0 (Transitional or Strict)</a> (and probably also XHTML 1.1) in <a href="http://www.w3.org/TR/xhtml-basic/">XHTML Basic</a>. This transformation can imply some loss in the semantics context of the document and uses a set of HTML classes to identify some of the removed elements.</p>
      <p>Note that nested tables are not allowed in XHTML Basic 1.1, so they'll be removed without further ado; so, if you intend to use this stylesheet for production use, you should first make sure the sources files don't have nested tables.</p>
      <p>Please send any bug report to Dominique Haza&#235;l-Massieux &lt;<a href="dom@w3.org">dom@w3.org</a>&gt;.</p>
      <h2>See it in action</h2>
      <form action="http://www.w3.org/2005/08/online_xslt/xslt">
        <div>
          <input type="hidden" value="http://www.w3.org/2003/04/xhtml1ToBasic.xsl" name="xslfile"/><label>URI: <input type="text" name="xmlfile" value="http://www.w3.org/"/></label><input type="submit" value="submit"/>
        </div>
      </form>
      <address><a href="http://www.w3.org/People/Dom/">Dominique Hazael-Massieux</a> - $Id: xhtml1ToBasic11.xsl,v 1.7 2008/04/01 06:50:43 dom Exp $</address>
      </body>
    </html>
    
    <!-- Identity transformation -->
    <xsl:template match="*|@*|comment()|text()">
      <xsl:copy>
        <xsl:apply-templates select="*|@*|comment()|text()"/>
      </xsl:copy>
    </xsl:template>

    <xsl:template match="html:u">
      <span style='text-decoration:underline'><xsl:apply-templates select="*|@*|comment()|text()"/></span>
    </xsl:template>

    <xsl:template match="html:s|html:strike">
      <span style='text-decoration:line-through'><xsl:apply-templates select="*|@*|comment()|text()"/></span>
    </xsl:template>

    <xsl:template match="html:script[normalize-space()='']">
      <xsl:copy>
        <xsl:apply-templates select="@*|comment()|text()"/>
        &#xA0;
      </xsl:copy>
    </xsl:template>

    <!-- we need to deal with ins and del depending
    on whether they include block or inline elements -->
    <xsl:template match="html:ins[html:p|html:div|html:h1|html:h2|html:h3|html:h4|html:h5|html:h6|html:pre|html:dl|html:noscript|html:blockquote|html:form|html:hr|html:table|html:fieldset|html:address]
                         | html:del[html:p|html:div|html:h1|html:h2|html:h3|html:h4|html:h5|html:h6|html:pre|html:dl|html:noscript|html:blockquote|html:form|html:hr|html:table|html:fieldset|html:address]">
      <div>
        <xsl:call-template name="addClassToken">
          <xsl:with-param name="token" select="local-name()"/>
        </xsl:call-template>
      </div>
    </xsl:template>

    <xsl:template match="html:ins[not(html:p|html:div|html:h1|html:h2|html:h3|html:h4|html:h5|html:h6|html:pre|html:dl|html:noscript|html:blockquote|html:form|html:hr|html:table|html:fieldset|html:address)]
                         |html:del[not(html:p|html:div|html:h1|html:h2|html:h3|html:h4|html:h5|html:h6|html:pre|html:dl|html:noscript|html:blockquote|html:form|html:hr|html:table|html:fieldset|html:address)]
                         |html:bdo">
      <span>
        <xsl:call-template name="addClassToken">
          <xsl:with-param name="token" select="local-name()"/>
        </xsl:call-template>
      </span>
    </xsl:template>

    <xsl:template match="@lang">
      <xsl:if test="not(parent::*[@xml:lang])">
        <xsl:attribute name="xml:lang"><xsl:value-of select="."/></xsl:attribute>
      </xsl:if>
    </xsl:template>


    <xsl:template match="@xml:space[parent::html:style or parent::html:title or parent::html:script or parent::html:head or parent::html:param or parent::html:meta or parent::html:base or parent::html:html]|@dir|html:ins/@cite|html:del/@cite|@datetime|@border|@cellpadding|@cellspacing|@datapagesize|@frame|@char|@charoff|@rules|html:col|@shape|@coords|@nohref|@usemap|@ismap|html:basefont|html:isindex|@compact|@alink|@background|@bgcolor|@link|@text|@vlink|@clear|@caption|@align[not(parent::html:tr or parent::html:td or parent::html:th)]|@type[parent::html:dl or parent::html:ol or parent::html:ul or parent::html:li]|@noshade|@size[not(parent::html:input or parent::html:select)]|@width[not(parent::html:table or html:object or html:img)]|@hspace|@vspace|@start|@height[not(parent::html:img or parent::html:object)]|@nowrap"/>

    <xsl:template match="@version">
      <xsl:attribute name="version">-//W3C//DTD XHTML Basic 1.1//EN</xsl:attribute>
    </xsl:template>

    <xsl:template match="@name[parent::html:a or parent::html:form or parent::html:iframe or parent::html:img or parent::html:map]">
      <xsl:if test="not(../@id)">
        <xsl:attribute name="id">
          <xsl:value-of select='.'/>
        </xsl:attribute>
      </xsl:if>
    </xsl:template>

    <xsl:template match="html:area">
      <a><xsl:apply-templates select="@*[not(local-name()='alt')]"/><xsl:value-of select="@alt"/></a>
    </xsl:template>

    <xsl:template match="html:menu|html:dir">
      <ul><xsl:apply-templates select="*|@*|comment()"/></ul>
    </xsl:template>

    <xsl:template match="html:center">
      <div style='text-align:center'>
        <xsl:apply-templates select="*|@*|text()|comment()"/>
      </div>
    </xsl:template>

    <xsl:template match="html:map|html:iframe">
      <div>
        <xsl:call-template name="addClassToken">
          <xsl:with-param name="token" select="local-name()"/>
        </xsl:call-template>
      </div>
    </xsl:template>

    <xsl:template match="html:tbody|html:thead|html:colgroup|html:tfoot|html:font">
      <xsl:apply-templates select="*|comment()"/>
    </xsl:template>

    <xsl:template match="html:table//html:table">
      <xsl:message>Nested table encountered and removed</xsl:message>
      <xsl:comment>Nested table not allowed in XHTML 1.1 Basic... removed, the source needs to be re-designed appropriately </xsl:comment>
    </xsl:template>

    <xsl:template name="addClassToken">
      <xsl:param name="token"/>
      <xsl:attribute name="class">
        <xsl:if test="@class">
          <xsl:value-of select="@class"/><xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of select="$token"/>
      </xsl:attribute>
      <xsl:apply-templates select="*|@*[not(local-name()='class')]|comment()|text()"/>
    </xsl:template>

</xsl:stylesheet>