<?xml version="1.0"?>
<!-- $Id: groktr.xsl,v 1.8 2002/02/15 10:26:31 dom Exp $ -->

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:uri="http://www.w3.org/2000/07/uri43/uri.xsl?template="
  xmlns:h="http://www.w3.org/1999/xhtml"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:rec="http://www.w3.org/2001/02pd/rec54#"
  xmlns:contact="http://www.w3.org/2000/10/swap/pim/contact#"
  xmlns:date="http://www.w3.org/2001/08/date-util.xslt"
  xmlns:doc='http://www.w3.org/2000/10/swap/pim/doc#'
  exclude-prefixes="uri date"
  >
  <xsl:import href="http://www.w3.org/2000/07/uri43/uri.xsl"/>
  <xsl:import href="http://www.w3.org/2001/08/date-util.xslt"/>
<!-- members, sorted by date-joined http://www.w3.org/Systems/db/advancedSearch?action=Search&orderBy=dateJoined%20asc&theWhere=&theFrom=&theSelect=%2C%20dateJoined&disp_fields[]=dateJoined -->

<!-- xslt service
http://www23.w3.org:8001/servlet/org.w3c.app.xsl.XSLtransformer -->

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

  <xsl:variable name="Months"
           select='document("http://www.w3.org/2000/04/mem-news/date-util.xml")/*/months'/>

  <xsl:param name="since" select='"1000-04-01"' /> <!-- @@2000-->
  <xsl:param name="debug" select='0'/>

  <xsl:template match="/h:html">
    <rdf:RDF>
     <xsl:apply-templates/>
    </rdf:RDF>
  </xsl:template>

  <xsl:template match="h:dl/h:dt[./h:b/h:i]">
    <xsl:variable name="ref" select='string(.//h:a[position()=last()]/@href)'/>
    <xsl:variable name="absRef"><xsl:choose>
      <xsl:when test="starts-with($ref,'../')">
        <xsl:value-of select="concat('http://www.w3.org/',substring($ref,4))"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select='concat("http://www.w3.org/TR/", $ref)'/>
      </xsl:otherwise>
    </xsl:choose></xsl:variable>

    <xsl:variable name="title" select=".//h:a[position()=last()]"/>
    <xsl:variable name="nextDD" select='following-sibling::h:dd[1]'/>
    <xsl:variable name="DDsupp">
      <xsl:if test="following-sibling::h:*[2][local-name()='dd']">
        <xsl:copy-of select="following-sibling::h:*[2]"/>
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="friendlyDate"
	select='normalize-space(substring-before($nextDD, ","))'/>

    <xsl:variable name="isoDate">
      <xsl:call-template name="date:makeDateNumeric">
        <xsl:with-param name="format-iso">yes</xsl:with-param>
        <xsl:with-param name="friendlyDate" select="$friendlyDate"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="status" select="preceding::h:h2[position()=1]/h:a/@id"/>
    <xsl:if test="$debug">
      <li>title: <xsl:value-of select="$title"/> friendlyDate: <xsl:value-of select="$friendlyDate"/> since: <xsl:value-of select="$since"/>
      </li>
    </xsl:if>

    <xsl:if test="number(translate($isoDate,'-','')) > number(translate($since,'-',''))">

      <xsl:message>@@
	 shortname: <xsl:value-of select="$ref"/>
	 <xsl:value-of select="$absRef"/> :: 
      </xsl:message>

      <rdf:Description rdf:about='{$absRef}'>
        <dc:date><xsl:value-of select="$isoDate"/></dc:date>

        <dc:title><xsl:value-of select="normalize-space($title)"/></dc:title> <!-- hmm... what about markup in titles? parseType Literal with copy-of? -->
	<xsl:call-template name="parseEditors">
	  <xsl:with-param name="eds" select='substring-after($nextDD, ",")'/>
	</xsl:call-template>
        <xsl:if test="$status='WD' and preceding::h:h3[position()=1]/h:a/@id='no-devel'">
          <rdf:type rdf:resource='http://www.w3.org/2001/02pd/rec54#Retired'/>
        </xsl:if>

        <xsl:if test="normalize-space($DDsupp)">
          <xsl:message>
            2nd dd detected; in status: <xsl:value-of select="$status"/> [<xsl:value-of select="preceding::h:h2[position()=1]"/>]
          </xsl:message>
          <xsl:choose>
            <xsl:when test="$status='Recommendations'">
              <xsl:variable name="previousRec" select="concat('http://www.w3.org/TR/',following-sibling::h:*[2]/h:a[last()]/@href)"/>
              <xsl:variable name="previousRecDate" select="normalize-space(substring-after(following-sibling::h:*[2]/h:a[last()],'published on '))"/>
              <xsl:variable name="previousRecTitle" select="normalize-space(substring-before(following-sibling::h:*[2]/h:a[last()],' published on'))"/>
              <xsl:message>
                Date of previous rec: <xsl:value-of select="$previousRecDate"/>
              </xsl:message>
              <!-- Revised recommendations -->
              <rec:previousEdition>
                <rdf:Description rdf:about='{$previousRec}'>
                  <dc:date>
                    <xsl:call-template name="date:makeDateNumeric">
                      <xsl:with-param name="format-iso">yes</xsl:with-param>
                      <xsl:with-param name="friendlyDate" select="$previousRecDate"/>
                    </xsl:call-template>
                  </dc:date>
                  <dc:title><xsl:value-of select="$previousRecTitle"/></dc:title>
                  <rdf:type rdf:resource='http://www.w3.org/2001/02pd/rec54#REC'/>
                  <rdf:type rdf:resource='http://www.w3.org/2001/02pd/rec54#FirstEdition'/>
                </rdf:Description>
              </rec:previousEdition>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$status='PR'">
                  <!-- End of PR Review -->
                  <rec:prReviewsDue>
                    <xsl:call-template name="date:makeDateNumeric">
                      <xsl:with-param name="format-iso">yes</xsl:with-param>
                      <xsl:with-param name="friendlyDate" select="substring-after($DDsupp,'Ends ')"/>
                    </xsl:call-template>
                  </rec:prReviewsDue>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <xsl:when test="$status='CR'">
                      <!-- end of implemenation feedback -->
                      <rec:implementationFeedbackDue>
                        <xsl:call-template name="date:makeDateNumeric">
                          <xsl:with-param name="format-iso">yes</xsl:with-param>
                          <xsl:with-param name="friendlyDate" select="substring-after($DDsupp,'Ends ')"/>
                        </xsl:call-template>
                      </rec:implementationFeedbackDue>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$status='WD' and preceding::h:h3[position()=1]/h:a/@id='last-call'">
                          <!-- end of last call feedback -->
                          <rec:lastCallFeedBackDue>
                            <xsl:call-template name="date:makeDateNumeric">
                              <xsl:with-param name="format-iso">yes</xsl:with-param>
                              <xsl:with-param name="friendlyDate" select="substring-after($DDsupp,'Ends ')"/>
                            </xsl:call-template>
                          </rec:lastCallFeedBackDue>
                        </xsl:when>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:if>

	<xsl:variable name="submAnch"
                      select='$nextDD/h:a[contains(., "ubmission")]'/>
	<xsl:if test='$submAnch'>
          <rec:fromSubmission> <!-- @@add to schema -->
          <xsl:variable name="submRef">
            <xsl:call-template name="uri:expand">
              <xsl:with-param name="base">http://www.w3.org/TR/</xsl:with-param>
              <xsl:with-param name="there" select="$submAnch/@href"/>
            </xsl:call-template>
          </xsl:variable>
            <rdf:Description rdf:about='{$submRef}'>
              <dc:title><xsl:value-of select="$submAnch"/></dc:title> <!-- hmm... is this really it title? perhaps parse out the submissionName part? -->
            </rdf:Description>
          </rec:fromSubmission>
        </xsl:if>

      </rdf:Description>
    </xsl:if>
  </xsl:template>


<!-- DOM specs are special... -->

<xsl:template match="h:dl/h:dd/h:ul/h:li[./h:b/h:i]">
    <xsl:variable name="ref" select='string(.//h:a/@href)'/>
    <xsl:variable name="absRef" select='concat("http://www.w3.org/TR/", $ref)'/> <!-- @@absolutize -->

    <xsl:variable name="title" select=".//h:a"/>

    <xsl:variable name="friendlyDate"
	select='normalize-space(../../preceding-sibling::h:dd[1])'/>

    <xsl:variable name="dayOfMonth"
	select="number(substring-before($friendlyDate, ' '))"/>

    <xsl:variable name="monthName"
	select="substring-before(substring-after($friendlyDate, ' '), ' ')"/>

    <xsl:variable name="year"
	select="number(substring-after(substring-after($friendlyDate, ' '), ' '))"/>

    <xsl:variable name="monthNum"
	select="number($Months/month[text() = $monthName]/@num)"/>

      <xsl:message>@@
	 shortname: <xsl:value-of select="$ref"/>
         fmt year: <xsl:value-of select='format-number($year, "0000")'/>
         friendly: <xsl:value-of select='$friendlyDate'/>
	 <xsl:value-of select="$absRef"/> :: 
      </xsl:message>

    <rdf:Description rdf:about='{$absRef}'>
      <dc:date><xsl:value-of select='concat(format-number($year, "0000"), "-", format-number($monthNum, "00"), "-", format-number($dayOfMonth, "00"))'/></dc:date>
      <dc:title><xsl:value-of select="normalize-space($title)"/></dc:title> <!-- hmm... what about markup in titles? parseType Literal with copy-of? -->
      <xsl:call-template name="parseEditors">
        <xsl:with-param name="eds" select='text()'/>
      </xsl:call-template>


    </rdf:Description>

</xsl:template>

<xsl:template name="parseEditors">
  <xsl:param name="eds"/>

  <xsl:variable name="edRest" select='substring-after($eds, ",")'/>
  <xsl:variable name="ed1">
    <xsl:choose>
      <xsl:when test="$edRest">
        <xsl:value-of select='substring-before($eds, ",")'/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select='$eds'/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:if test="$ed1">
    <rec:editor rdf:parseType="Resource">
      <xsl:variable name="fullName">
        <xsl:choose>
          <xsl:when test='contains($ed1, "(")'>
            <xsl:value-of select='substring-before($ed1, "(")'/>
	  </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select='$ed1'/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>


      <!-- parse given/family names? -->
      <contact:fullName><xsl:value-of select='normalize-space($fullName)'/></contact:fullName>

      <xsl:variable name="affName">
        <xsl:choose>
          <xsl:when test='contains($ed1, "(")'>
            <xsl:value-of select='normalize-space(substring-before(substring-after($ed1, "("), ")"))'/>
	  </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select='""'/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:if test='string-length($affName) > 0 and not(contains($affName, "ubmission"))'>
        <contact:affiliation rdf:parseType="Resource"> <!-- @@not in contact.n3 -->
          <contact:name><xsl:value-of select='$affName'/></contact:name>  <!-- @@not in contact.n3 -->
	</contact:affiliation>
      </xsl:if>
    </rec:editor>
  </xsl:if>

  <xsl:if test="$edRest">
    <xsl:call-template name="parseEditors">
      <xsl:with-param name="eds" select='$edRest'/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

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

</xsl:stylesheet>

