<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:h="http://www.w3.org/1999/xhtml"
                exclude-result-prefixes="h"
                version="2.0">
  
  <xsl:output indent="yes"
    doctype-public="-//W3C//DTD Specification V2.1//EN"
    doctype-system="../ws/arch/2/xmlspec-v21.dtd"
    />

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

  <xsl:template match="h:html">
    <spec w3c-doctype="other" other-doctype="use-case" role="editors-copy">
      <header>
        <title><xsl:apply-templates select="h:head/h:title"/></title>
        <w3c-designation>ws-example</w3c-designation>
        <w3c-doctype></w3c-doctype>
        <pubdate>
          <day>5</day>
          <month>May</month>
          <year>2002</year>
        </pubdate>
        <publoc><loc href="http://www.w3.org/2002/06/ws-example">http://www.w3.org/2002/06/ws-example</loc> (<loc href="http://www.w3.org/2002/06/ws-example.xml">XML version</loc> and <loc href="http://www.w3.org/2002/06/ws-example.xml">HTML version</loc>)</publoc>
        <prevlocs><loc href="http://www.w3.org/2002/04/17-ws-usecase">http://www.w3.org/2002/04/17-ws-usecase</loc></prevlocs>
        <authlist>
          <author>
            <name>Hugo Haas</name>
            <affiliation>W3C</affiliation>
            <email href="mailto:hugo@w3.org">hugo@w3.org</email>
          </author>
        </authlist>
        <abstract>
          <!-- Put intro here -->
        </abstract>
        <status><p>This document is in progress.</p></status>
        <langusage>
          <language id="en">English</language>
        </langusage>
        <revisiondesc>
          <p>Last Modified: $Date: 2002/06/10 17:56:54 $</p>
        </revisiondesc>
      </header>
      <xsl:apply-templates select="h:body"/>
    </spec>
  </xsl:template>

  <xsl:template match="h:body">
    <body>
      <xsl:for-each-group select="h:*" group-starting-with="h:h2">
        <xsl:choose>
          <xsl:when test="self::h:h2">
            <div1 id="{if (@id) then @id else generate-id()}">
              <head><xsl:apply-templates/></head>
              <xsl:for-each-group select="current-group()[not(self::h:h1)][not(self::h:h2)]" group-starting-with="h:h3">
                <xsl:choose>
                  <xsl:when test="self::h:h3">
                    <div2 id="{if (@id) then @id else generate-id()}">
                      <head><xsl:apply-templates/></head>
                      <xsl:for-each-group select="current-group()[not(self::h:h3)]" group-starting-with="h:h4">
                        <xsl:choose>
                          <xsl:when test="self::h:h4">
                            <div3 id="{if (@id) then @id else generate-id()}">
                              <head><xsl:apply-templates/></head>
                              <xsl:apply-templates select="current-group()[not(self::h:h4)]"/>
                            </div3>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:apply-templates select="current-group()[not(self::h4)]"/>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:for-each-group>
                    </div2>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:apply-templates select="current-group()"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:for-each-group>
            </div1>
          </xsl:when>
          <xsl:otherwise>
            <div1 id="{generate-id()}">
              <head>No title</head>
              <xsl:apply-templates select="current-group()[not(self::h:h1)]"/>
            </div1>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each-group>
    </body>
  </xsl:template>

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

  <xsl:template match="h:ul">
    <ulist><xsl:apply-templates/></ulist>
  </xsl:template>

  <xsl:template match="h:ol">
    <olist><xsl:apply-templates/></olist>
  </xsl:template>

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

  <xsl:template match="h:a">
    <loc href="{@href}"><xsl:apply-templates/></loc>
  </xsl:template>

  <xsl:template match="h:address">
  </xsl:template>

</xsl:stylesheet>
