<?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-basic10.dtd" doctype-public="-//W3C//DTD XHTML Basic 1.0//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"/>
        <link rel="stylesheet" href="/QA/2002/12/qa4"/>
      </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, 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/2000/06/webdata/xslt" method="GET">
        <div>
          <p>(Note that the xlst processor used in the servlet underlying this service has some bugs which will likely make the final output invalid)</p>
          <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: xhtml1ToBasic.xsl,v 1.7 2008/03/28 08:11:37 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:b|html:big">
      <strong><xsl:apply-templates select="*|@*|comment()|text()"/></strong>
    </xsl:template>

    <xsl:template match="html:i">
      <em><xsl:apply-templates select="*|@*|comment()|text()"/></em>
    </xsl:template>

    <xsl:template match="html:small|html:sub|html:sup|html:tt|html:ins|html:del|html:bdo|html:button[not(@type='submit')]|html:legend|html:u|html:strike|html:s">
      <span>
        <xsl:call-template name="addClassToken">
          <xsl:with-param name="token" select="local-name()"/>
        </xsl:call-template>
      </span>
    </xsl:template>

    <xsl:template match="html:button[@type='submit']">
      <input type='submit'><xsl:apply-templates select="@*[not(local-name()='type')]"/></input>
    </xsl:template>

    <!-- The XHTML Basic DTD is borken: @tabindex should be OK for input -->
    <xsl:template match="html:input/@tabindex"/>

    <xsl:template match="html:input[@type='button']|html:hr|@dir|html:ins/@cite|html:del/@cite|@datetime|@accept|@accept-charset|html:input/@alt|@disabled|@readlonly|html:option/@label|html:button/@value|html:button/@type|@border|@cellpadding|@cellspacing|@datapagesize|@frame|@char|@charoff|@rules|html:col|@shape|@coords|@nohref|@usemap|@ismap|@target|@onblur|@onfocus|@onload|@onunload|@onreset|@onsubmit|@onchange|@onselect|html:script|@style|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|@width[not(parent::html:table)]|@size[parent::html:hr]|@hspace|@vspace|@start|@height|@nowrap|@lang|@xml:lang|@onclick|@ondblclick|@onmousedown|@onmouseup|@onmouseover|@onmousemove|@onmouseout|@onkeypress|@onkeydown|@onkeyup|html:style|@version|@xml:space"/>
    
    <xsl:template match="@align[parent::html:tr or parent::html:td or parent::html:th]">
      <xsl:if test="@align='left' or @align='right' or @align='center'">
        <xsl:value-of select="."/>
      </xsl:if>
    </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="@valign">
      <xsl:if test="@align='top' or @align='bottom' or @align='middle'">
        <xsl:value-of select="."/>
      </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:fieldset|html:map|html:iframe|html:noscript|html:center">
      <div>
        <xsl:call-template name="addClassToken">
          <xsl:with-param name="token" select="local-name()"/>
        </xsl:call-template>
      </div>
    </xsl:template>

    <xsl:template match="html:optgroup|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:comment>Nested table not allowed in XHTML 1.0 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>