<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:h="http://www.w3.org/1999/xhtml"
  >

<!-- $Id: html2dw.xsl,v 1.11 2005/06/10 18:06:23 connolly Exp $ -->

<xsl:output method="xml" indent="yes" />

<xsl:template match="h:html">
  <xsl:processing-instruction name="xml-stylesheet"> type="text/xsl" href="developerworks/xsl/dw-document-html-4.0.xsl"</xsl:processing-instruction>
  <xsl:text>&#10;</xsl:text>

 <dw-document
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="developerworks/schema/dw-document-4.0.xsd" 
   >

   <dw-article
       local-site="worldwide" 
       ratings-form="auto"
       related-contents="auto" 
       toc="auto"
       skill-level="1">

     <xsl:apply-templates />
   </dw-article>
 </dw-document>
</xsl:template>

<xsl:template match="h:head">
  <id cma-id="" domino-uid="" content-id="" original="yes"/>

  <keywords content='{h:meta[@name="keywords"]/@content}' />

  <xsl:variable
      name="RCSDate"
      select = 'substring-before(substring-after(
		h:meta[@name="last-updated"]/@content,
		concat("$", "Date: ")), "$")'/>

  <xsl:variable name="dd" select='substring($RCSDate, 9, 2)' />
  <xsl:variable name="mm" select='substring($RCSDate, 6, 2)' />
  <xsl:variable name="yyyy" select='substring($RCSDate, 1, 4)' />

  <meta-last-updated day="{$dd}" month="{$mm}" year="{$yyyy}"
		     initials="jcs"/>

  <content-area-primary name="xml" /> <!-- guess?? -->
  <!-- <content-area-secondary name="db2" /> -->

  <title><xsl:value-of select="h:title" /></title>
  <subtitle><xsl:value-of select="../h:body/h:h1" /></subtitle>
  <!-- ?? <forum-url url="" /> -->

  <xsl:variable name="sig" select="../h:body/h:address" />
  <author
      jobtitle='{$sig/*[@class="jobtitle"]}' 
      company='{$sig/*[@class="company"]}'
      email-cc='{$sig/*[@class="email-cc"]}'
      email='{$sig/*[@class="email"]}'>

    <bio>
      <xsl:for-each select='../h:body//*[@class="bio"]'>
	<p><xsl:value-of select="."/></p>
      </xsl:for-each>
    </bio>

    <name><xsl:value-of select='$sig/*[@class="name"]' /></name>

    <xsl:for-each select='../h:body/h:img[@class="author-img"]'>
      <img src='{@src}' width="{@width}" height="{@height}" alt="{@alt}" />
    </xsl:for-each>
  </author>

  <date-published day="{$dd}" month="{$mm}" year="{$yyyy}" />
  <!-- 
  <date-updated day="{$dd}" month="{$mm}" year="{$yyyy}" />
  -->

  <abstract>
    <xsl:value-of select='../h:body//*[@class="abstract"]' />
  </abstract>

  <!-- doesn't seem to be used

  <abstract-extended>
    <xsl:for-each select='../h:body//*[@class="abstract"]'>
      <xsl:apply-templates />
    </xsl:for-each>
  </abstract-extended>
  -->

</xsl:template>

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

  <related-list>
    <xsl:for-each select='../h:head/h:link[@rel="related"]'>
      <a href="{@href}"><xsl:value-of select="@title" /></a>
    </xsl:for-each>
  </related-list>

  <xsl:for-each select='h:div[@class="references"]/h:ul'>
    <resource-list>
      <ul>
	<xsl:apply-templates />
      </ul>
    </resource-list>
  </xsl:for-each>
</xsl:template>

<xsl:template match="h:h1">
  <!-- consumed with head -->
</xsl:template>

<xsl:template match='h:div[@class="bio"]'>
  <!-- consumed with head -->
</xsl:template>

<xsl:template match='*[@class="abstract"]'>
  <!-- consumed with head -->
</xsl:template>

<xsl:template match='h:img[@class="author-img"]'>
  <!-- consumed with head -->
</xsl:template>

<xsl:template match='*[@class="ed"]'>
  <!-- editorial notes to self -->
</xsl:template>

<xsl:template match="h:h2">
  <heading refname="{@id}" type="major" toc="yes">
    <xsl:apply-templates />
  </heading>
</xsl:template>

<xsl:template match="h:h3">
  <heading refname="{@id}" type="minor" toc="no">
    <xsl:apply-templates />
  </heading>
</xsl:template>

<xsl:template match="h:blockquote">
  <xsl:for-each select="h:p">
    <blockquote>
      <xsl:apply-templates />
    </blockquote>
  </xsl:for-each>
</xsl:template>

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

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

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

<xsl:template match="h:pre">
  <!-- @@ class="counterExample" -->

  <code type="section" width="">
    <xsl:if test="@title">
      <heading refname="" type="code" toc="no">
	<xsl:value-of select="@title" />
	</heading>
    </xsl:if>
    <xsl:apply-templates />
  </code>
</xsl:template>

<xsl:template match="h:address">
  <!-- consumed in h:html template -->
</xsl:template>

<xsl:template match="h:tt">
  <code type="inline">
    <xsl:apply-templates />
  </code>
</xsl:template>

<xsl:template match="h:q">
  <!-- <xsl:text>&#x201C;</xsl:text> -->
  <xsl:text>"</xsl:text>
    <xsl:apply-templates />
  <xsl:text>"</xsl:text>
  <!-- <xsl:text>&#x201D;</xsl:text> -->
</xsl:template>

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

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

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

<!-- odd... they seem to use <i> sometimes and "" others -->
<xsl:template match="h:cite[@class='i']">
  <i>
    <xsl:apply-templates />
  </i>
</xsl:template>

<xsl:template match='h:cite'>
  <xsl:text>"</xsl:text>
  <xsl:apply-templates />
  <xsl:text>"</xsl:text>
</xsl:template>

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

<xsl:template match="*">
  <xsl:message>@@not matched: <xsl:value-of select="name()" />
  </xsl:message>
</xsl:template>

</xsl:transform>