<?xml version="1.0" encoding="utf-8"?>
<?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"?>
<?xml-stylesheet href="http://www.w3.org/2002/07/01-style-xsl.xsl" type="application/xml"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0" xmlns:contact="http://www.w3.org/2000/10/swap/pim/contact#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rec="http://www.w3.org/2001/02pd/rec54#" xmlns="http://www.w3.org/1999/xhtml" xmlns:date="http://www.w3.org/2001/08/date-util.xslt" xmlns:str="http://www.w3.org/2001/10/str-util.xsl" xmlns:doc="http://www.w3.org/2000/10/swap/pim/doc#" xmlns:org="http://www.w3.org/2001/04/roadmap/org#" xmlns:tra="http://www.w3.org/2002/01/tr-automation/process#" exclude-result-prefixes="contact dc rec rdf date str doc org tra">
  <xsl:import href="../../../2001/08/date-util.xslt"/>
  <xsl:import href="../../../2001/10/str-util.xsl"/>
  <xsl:output method="xml" indent='yes'/>
  <xsl:param name="format" select="'xhtml'"/>
  <xsl:param name="uris"/>
  <xsl:param name="labels" select="0"/>

  <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title>Stylesheet to format bibliographic data for our TR publications</title>
      <link rel="stylesheet" href="http://www.w3.org/StyleSheets/base"/>
    </head>
    <body>
      <div class='head'><a href="/"><img src='/Icons/w3c_home' alt='W3C'/></a> <a href="./"><acronym title="Technical Reports">TR</acronym> Automation</a></div>
      <h1>Stylesheet to format bibliographic data for our TR publications</h1>
      <p>This XSLT allows to get an XHTML formatted data for our TR publications, embedded in a &lt;dd> element. You can test it using the XSLT servlet by passing the (dated or not) URI(s) of the document(s) you want bibliographic data on:</p>
      <form action="http://www.w3.org/2000/06/webdata/xslt" method="GET">
        <div>
          <input type="hidden" name="xslfile" value="http://www.w3.org/2002/01/tr-automation/tr-biblio.xsl"/>
          <input type="hidden" name="xmlfile" value="http://www.w3.org/2002/01/tr-automation/tr-logs.rdf"/>
          <p><label>URI(s): <textarea name="uris" cols="100" rows="6"></textarea> (one URI per line if several)</label></p>
          <p>If you want a bibliography with labels to be generated, provide the said labels before their URIs (separating them with a space), and <label title="Check this if you provided labels in the preceding control">check this <input type="checkbox" name="labels" /></label>.</p>

          <input type="submit" value="Go" />
        </div>

      </form>
      <p>See also:</p>
      <ul>
        <li><a href="http://lists.w3.org/Archives/Public/spec-prod/2003OctDec/0000.html">Announce and details sent to spec-prod</a></li>
        <li><a href="/2003/Editors/">W3C Editors Home Page</a></li>
      </ul>
      <address><a href="http://www.w3.org/People/Dom/">Dominique Hazael-Massieux</a> - $Id: tr-biblio.xsl,v 1.31 2006/01/05 20:34:16 matthieu Exp $</address>
    </body>
  </html>

  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Technical Report Bibliographies</title>
<link type="text/css" rel="stylesheet" href="/StyleSheets/base" />
</head>
<body>
<p><a href="/" title="W3C"><img height="48" width="72" alt="W3C"
src="http://www.w3.org/Icons/w3c_home" /></a></p>

<h1>Technical Report Bibliographies</h1>

<p>The list of Technical Reports submitted are to be inserted in a bibliography as follows: (copy-paste source code as needed)</p>

    <dl>
      <xsl:call-template name="dispatch">
        <xsl:with-param name="uris" select="$uris"/>
      </xsl:call-template>
    </dl>

<p>This output can be regenerated by putting the following input in the <a href="/2002/01/tr-automation/tr-biblio-ui">Technical Reports Bibliography extractor</a>:</p>
<pre>
<xsl:value-of select="$uris"/>
</pre>

<hr />
<address><a href="http://www.w3.org/People/Dom/">Dominique
Haza&#235;l-Massieux</a> &lt;<a
href="mailto:dom@w3.org">dom@w3.org</a>&gt;<br />
Last Modified: $Date: 2006/01/05 20:34:16 $</address>
</body>
    </html>
  </xsl:template>

  <xsl:template name="dispatch">
    <xsl:param name="uris"/>    
    <xsl:if test="normalize-space($uris)">
      <xsl:variable name="uri">
        <xsl:choose>
          <xsl:when test="$labels">
            <xsl:value-of select="substring-before(concat(substring-after(normalize-space($uris),' '),' '),' ')"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="substring-before(concat(normalize-space($uris),' '),' ')"/>                  
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="log">
        <xsl:variable name="dated_uri_log">
          <xsl:choose>
            <xsl:when test="document('tr.rdf')/rdf:RDF/*[@rdf:about=$uri and doc:versionOf]">
              <xsl:text>tr.rdf</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="/rdf:RDF/tra:Log[1]" mode="findLog">
                <xsl:with-param name="uri" select="$uri"/>
              </xsl:apply-templates>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:choose>
          <xsl:when test="normalize-space($dated_uri_log)">
            <xsl:value-of select="$dated_uri_log"/>
          </xsl:when>
          <xsl:when test="document('tr.rdf')/rdf:RDF/*/doc:versionOf[@rdf:resource=$uri]">
            <xsl:text>tr.rdf</xsl:text>
          </xsl:when>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="label">
        <xsl:if test="$labels">
          <xsl:value-of select="substring-before(normalize-space($uris),' ')"/>
        </xsl:if>
      </xsl:variable>
      <xsl:call-template name="entry">
        <xsl:with-param name="label" select="$label"/>
        <xsl:with-param name="log" select="$log"/>
        <xsl:with-param name="uri">
          <!-- Needs to extract the dated URI if the original URI wasn't so -->
          <xsl:variable name="_uri" select="$uri"/>
          <xsl:choose>
            <xsl:when test="document($log)/rdf:RDF/*[@rdf:about=$_uri and doc:versionOf]">
              <xsl:value-of select="$_uri"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="document($log)/rdf:RDF/*[doc:versionOf/@rdf:resource=$_uri and not(local-name()='FirstEdition' or rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#FirstEdition')]/@rdf:about"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:with-param>
      </xsl:call-template>
      <xsl:if test="normalize-space(substring-after(normalize-space($uris),' '))">
        <xsl:call-template name="dispatch">
          <xsl:with-param name="uris">
            <xsl:choose>
              <xsl:when test="$labels">
                <xsl:value-of select="substring-after(substring-after(normalize-space($uris),' '),' ')"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="substring-after(normalize-space($uris),' ')"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>            
        </xsl:call-template>
      </xsl:if>
    </xsl:if>
  </xsl:template>

  <xsl:template name="entry">
    <xsl:param name="uri"/>
    <xsl:param name="log"/>
    <xsl:param name="label"/>
    <dt>
      <xsl:variable name="computedLabel">
        <xsl:choose>
          <xsl:when test="$labels and normalize-space($label)">
            <xsl:value-of select="$label"/>
          </xsl:when>
          <xsl:otherwise>
            <!-- compute the label from the latest version URI -->
            <xsl:value-of select="translate(substring-after(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/doc:versionOf/@rdf:resource,'http://www.w3.org/TR/'),'abcdefghijklmnopqrstuvwxyz+/','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <a name="{$computedLabel}" id="{$computedLabel}"><xsl:value-of select="$computedLabel"/></a>
    </dt>
    <dd><cite><a
    href="{$uri}"><xsl:value-of select="document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/dc:title"/></a></cite>, <xsl:call-template name="formatEditors"><xsl:with-param name="uri" select="$uri"/><xsl:with-param name="log" select="$log"/></xsl:call-template> Editor<xsl:if test="count(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/rec:editor) &gt; 1">s</xsl:if>, W3C <xsl:call-template name="status"><xsl:with-param name="uri" select="$uri"/><xsl:with-param name="log" select="$log"/></xsl:call-template>, <xsl:call-template name="date:makeDateFriendly"><xsl:with-param name="date" select="translate(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/dc:date,'-','')"/></xsl:call-template>, <xsl:value-of select="$uri"/> . <a href="{document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/doc:versionOf/@rdf:resource}" title="Latest version of {document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/dc:title}">Latest version</a> available at <xsl:value-of select="document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/doc:versionOf/@rdf:resource"/> .</dd>
  </xsl:template>

  <xsl:template name="formatEditors">
    <xsl:param name="uri"/>
    <xsl:param name="log"/>
    <xsl:for-each select="document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/rec:editor/contact:fullName">
      <xsl:variable name="firstNameStart" select="substring-before(.,' ')"/>
      <xsl:variable name="lastNameEnd">
        <xsl:variable name="before">
          <xsl:call-template name="str:keep-before-last">
            <xsl:with-param name="string" select="."/>
            <xsl:with-param name="delimiter" select="' '"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:value-of select="normalize-space(substring-after(.,$before))"/>
      </xsl:variable>
      <xsl:choose>
        <!-- Special casing for when we have the name in Original Script (e.g. in Japanese);  currently assume that the order is inversed in this case... -->
        <xsl:when test="document('known-tr-editors.rdf')/rdf:RDF/*[contact:lastNameInOriginalScript=substring-before(current(),' ')]">
          <xsl:value-of select="substring-before(.,' ')"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="substring($firstNameStart,1,1)"/>
          <xsl:text>. </xsl:text>
          <xsl:if test="document('known-tr-editors.rdf')/rdf:RDF/*[contains(contact:lastName,$lastNameEnd) and not(normalize-space(substring-after(contact:lastName,$lastNameEnd))) and (starts-with(contact:firstName,$firstNameStart) or starts-with(contact:firstNameInitial,substring($firstNameStart,1,1)))]/contact:middleNameInitial">
            <xsl:value-of select="document('known-tr-editors.rdf')/rdf:RDF/*[contains(contact:lastName,$lastNameEnd) and not(normalize-space(substring-after(contact:lastName,$lastNameEnd))) and (starts-with(contact:firstName,$firstNameStart) or starts-with(contact:firstNameInitial,substring($firstNameStart,1,1)))]/contact:middleNameInitial"/>        
            <xsl:text> </xsl:text>
          </xsl:if>
          <xsl:value-of select="document('known-tr-editors.rdf')/rdf:RDF/*[contains(contact:lastName,$lastNameEnd) and not(normalize-space(substring-after(contact:lastName,$lastNameEnd))) and (starts-with(contact:firstName,$firstNameStart) or starts-with(contact:firstNameInitial,substring($firstNameStart,1,1)))]/contact:lastName"/>          
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>, </xsl:text>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="status">
    <xsl:param name="uri"/>
    <xsl:param name="log"/>
    <xsl:value-of select="document('../../../2001/07/pubrules-copyright.xml')/h:html/h:body/h:div[@id='status']/h:ul/h:li/h:abbr[normalize-space()=substring-after(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/rdf:type/@rdf:resource,'http://www.w3.org/2001/02pd/rec54#') or normalize-space()=local-name(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri])]/@title"/>
    <xsl:if test="not(substring-after(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/rdf:type/@rdf:resource,'http://www.w3.org/2001/02pd/rec54#')='REC' or local-name(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri])='REC' or substring-after(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/rdf:type/@rdf:resource,'http://www.w3.org/2001/02pd/rec54#')='NOTE' or local-name(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri])='NOTE' or substring-after(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri]/rdf:type/@rdf:resource,'http://www.w3.org/2001/02pd/rec54#')='RSCND' or local-name(document(normalize-space($log))/rdf:RDF/*[@rdf:about=$uri])='RSCND')">
      <xsl:text> (work in progress)</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="tra:Log" mode="findLog">
    <xsl:param name="uri"/>
    <xsl:choose>
      <xsl:when test="document(@rdf:about)/rdf:RDF/*[@rdf:about=$uri and doc:versionOf]">
        <xsl:value-of select="@rdf:about"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="following-sibling::tra:Log[1]" mode="findLog"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>