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

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

<xsl:key name="who"
	 match='h:div[h:h3/h:a/@id="xbgbio"]/h:table/h:tbody/h:tr'
	 use="h:th/text()" />

<xsl:key name="whenr"
	 match='h:div[h:h3/h:a/@id="xrevwhen"]/h:table/h:tbody/h:tr'
	 use="h:th/text()" />

<xsl:template match="/">
  <html xmlns='http://www.w3.org/1999/xhtml'>
    <head><title>HTML WG Tasks, remix edition</title>
    </head>
    <body>

      <address>
	derived from <a
	href="http://www.w3.org/2002/09/wbs/40318/tasks83/results">results</a>
	of <a href="http://www.w3.org/2002/09/wbs/40318/tasks83/">HTML
	WG tasks survey</a>
      </address>

      <xsl:for-each select='.//h:div[h:h3/h:a/@id="xwhichsec"]'>
	<div><h2>Detailed Spec Review</h2>
	<ul>
	  <xsl:for-each select='h:table[@class="results"]/h:thead/h:tr
				/h:th [ position() &gt; 1]'>
	    <xsl:variable name="col" select="position()" />

	    <li id="{generate-id()}">
	      <b><xsl:value-of select="." /></b>
	      <xsl:if test='../../../h:tbody/h:tr[h:td[$col] = "1"]'>
		<ol>
		  <xsl:for-each select='../../../h:tbody/h:tr[h:td[$col] = "1"]'>
		    <xsl:sort select='string(key("whenr", h:th)/h:td)' />
		    <li>
		      <xsl:value-of select='key("whenr", h:th)/h:td' />
		      <xsl:text> </xsl:text>
		      <a href='#{generate-id(key("who", h:th))}'>
			<xsl:value-of select="h:th" />
		      </a>
		    </li>
		  </xsl:for-each>
		</ol>
	      </xsl:if>
	    </li>

	  </xsl:for-each>
	</ul>
	</div>
      </xsl:for-each>

      <xsl:for-each select='.//h:div[h:h3/h:a/@id="xtasks"]'>
	<div><h2>Various Tasks</h2>
	<ul>
	  <xsl:for-each select='h:table[@class="results"]/h:thead/h:tr/h:th
				[position() &gt; 1]'>
	    <xsl:variable name="col" select="position()" />
	    <li id="{generate-id()}">
	      <b><xsl:value-of select="." /></b>
	      <ol>
		<xsl:for-each select='../../../h:tbody/h:tr[h:td[$col] = "1"]'>
		  <li>
		    <a href='#{generate-id(key("who", h:th))}'>
		      <xsl:value-of select="h:th" />
		    </a>
		  </li>
		</xsl:for-each>
	      </ol>
	    </li>
	  </xsl:for-each>
	</ul>
	</div>
      </xsl:for-each>

      <xsl:apply-templates />
    </body>
  </html>
</xsl:template>

<xsl:template match='h:div[h:h3/h:a/@id="xbgbio"]/h:table'>
  <ul>
    <xsl:for-each select="h:tbody/h:tr">
      <li id="{generate-id()}">
	<xsl:variable name="name" select="h:th" />
	<b><xsl:value-of select="$name" /></b>
	<blockquote>
	  <xsl:copy-of select="h:td[1]/node()" />
	  <span />
	</blockquote>

	<xsl:variable name="taskRow"
		      select='//h:div[h:h3/h:a/@id="xtasks"]
			      /h:table[@class="results"]/h:tbody
			      /h:tr[h:th=$name]' />

	<p>
	  <xsl:copy-of select="$taskRow/h:td[last()]/node()" />
	</p>

      </li>
    </xsl:for-each>
  </ul>

</xsl:template>

<!-- don't pass text thru -->
<xsl:template match="text()|@*">
</xsl:template>


</xsl:transform>

