<?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"?>
<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: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:mat="http://www.w3.org/2002/05/matrix/vocab#" exclude-result-prefixes="contact dc rec rdf date str doc org mat">
  <xsl:import href="../../../2001/08/date-util.xslt"/>
  <xsl:import href="../../../2001/10/str-util.xsl"/>

  <xsl:output method="xml" indent='yes' doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>    
  <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>TR views formatter</title></head>
    <body>
    <p>
    <a href="http://www.w3.org/">
      <img src="http://www.w3.org/Icons/w3c_home" alt="W3C" />
      </a></p>

      <h1>XSLT to generate various views of the TR page</h1>

      <h2>Abstract</h2>
      <p>This stylesheet allow to generate various views of the TR page based on the <a href="tr.rdf">RDF data</a> created in the <a href=".">TR automation project</a>.</p>
      <h2>See it in use</h2>

      <p>View the TR page sorted by:</p>
          <form action="http://www.w3.org/2000/06/webdata/xslt"
    method="get">
            <input type="hidden" name="xslfile" value="http://www.w3.org/2002/01/tr-automation/viewBy.xsl"/>
            <input type="hidden" name="xmlfile" value="http://www.w3.org/2002/01/tr-automation/trview.html"/>
            <select name="type">
              <option value="title">title</option>
              <option value="date">date</option>
              <option value="editor">editor</option>
            </select>
            <input type="submit" value="View"/>
          </form>

          <p>Note that the result won't be uptodate if the RDF data aren't either.</p>
    <hr />

    <address>$Id: viewBy.xsl,v 1.60 2009/09/22 17:58:29 ijacobs Exp $
    <br />

    <a href="../../People/Dom/">Dominique Hazael-Massieux</a>
    </address>
  </body>
  </html>


  <xsl:param name="type" select="'title'"/>
  <!-- set to e.g. REC to only get Recommendations listed -->
  <xsl:param name="status" select="''"/>
  <!-- set to title to only get the titles+links list -->
  <xsl:param name="info" select="''"/>

  <!-- set to the URI of the patentRules to limit spec produced under the said rules -->
  <xsl:param name="patentRules" select="''"/>


  <xsl:variable name="trdata" select="document('tr.rdf')/rdf:RDF"/>
  <xsl:variable name="alphaKeys" select="'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'"/>

  <!-- This is used only to detect whether the XSLT is used from the servlet -->
  <xsl:param name="xslfile"/>

  <!-- @@@ will break if W3C still uses this system in 2020! -->
  <xsl:variable name="upperBound" select="2019"/>

  <!-- which type of list: dl or ul depending on whether only the title is shown -->
  <xsl:variable name="listTypeElement">
    <xsl:choose>
      <xsl:when test="normalize-space($info)">
        <xsl:text>ul</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>dl</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <!-- Identity Transformation, modifications are done on a case by case basis -->
  <xsl:template match="*|@*">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*[local-name()='head']">
    <xsl:copy>
      <xsl:if test="normalize-space($xslfile)">
        <base href="http://www.w3.org/TR/tr-{$type}" />
      </xsl:if>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*[local-name()='object' and @classid='http://www.w3.org/2002/02/tr-automation/viewBy?type']">
    <xsl:value-of select="$type"/>
    <xsl:if test="normalize-space($status)">
      of W3C <xsl:value-of select="document('../../../2001/07/pubrules-copyright.xml')//*[local-name()='li']/*[local-name()='abbr' and .=$status]/@title"/>s
    </xsl:if>
  </xsl:template>

  <xsl:template match="*[local-name()='object' and @classid='http://www.w3.org/2002/02/tr-automation/viewBy?list']">
    <div xmlns="http://www.w3.org/1999/xhtml" class="view"><p>
      <a href=".">View by Status</a>
      <xsl:if test="not($type='editor')">
        <xsl:text> | </xsl:text><a href="tr-editor">View by Editor</a>
      </xsl:if>
      <xsl:if test="not($type='title')">
        <xsl:text> | </xsl:text><a href="tr-title">View by Title</a>
      </xsl:if>
      <xsl:if test="not($type='date')">
        <xsl:text> | </xsl:text><a href="tr-date">View by Date</a>        
      </xsl:if>
      <xsl:if test="not($type='activity')">
         <xsl:text> | </xsl:text><a href="tr-activity">View by Activity</a>
      </xsl:if>
      <xsl:text> | </xsl:text><a href="tr-otherviews">Configurable Views</a>
    </p></div>
  </xsl:template>

    <xsl:template match="*[local-name()='object' and @classid='http://www.w3.org/2002/02/tr-automation/viewBy?sort']">
      <xsl:choose>
        <xsl:when test="$type='title'">
          <div class="navbar"><xsl:call-template name="groupByTitle"><xsl:with-param name="mode" select="'nav'"/></xsl:call-template></div>
          <xsl:call-template name="groupByTitle"/>
        </xsl:when>
        <xsl:when test="$type='date'">
          <p>See also the <a href="/2002/01/tr-automation/tr-stats-ui">lists of Technical Reports published between two dates</a>.</p>
          <div class="navbar"><xsl:call-template name="groupByDate"><xsl:with-param name="mode" select="'nav'"/></xsl:call-template></div>
          <xsl:call-template name="groupByDate"/>
        </xsl:when>
        <xsl:when test="$type='editor'">
          <div class="navbar"><xsl:call-template name="groupByEditor"><xsl:with-param name="mode" select="'nav'"/></xsl:call-template></div> 
          <xsl:call-template name="groupByEditor"/>
          <!-- <h2 id="unknown">Unknown editors</h2>
          <xsl:element name="{$listTypeElement}">
            <xsl:for-each select="$trdata/rec:*[doc:versionOf][not(rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#Superseded' or local-name()='Superseded')][not(local-name()='FirstEdition')][not(normalize-space($status)) or rdf:type/@rdf:resource=concat('http://www.w3.org/2001/02pd/rec54#',$status) or local-name()=$status][not(rec:editor)]">
              <xsl:sort select="dc:date" order="descending"/>
              <xsl:sort select="normalize-space(dc:title)"/>
              <xsl:call-template name="makeStatusList">
                <xsl:with-param name="noId" select="1"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:element> -->
        </xsl:when>
	<xsl:when test="$type='activity'">
	  <!-- <div class="navbar"><xsl:call-template name="groupByActivity"><xsl:with-param name="mode" select="'nav'"/></xsl:call-template> <a href="#unknown">unknown</a></div> -->
	  <xsl:call-template name="groupByActivity"/>
	</xsl:when>
        <xsl:otherwise>
          <xsl:message>
            How the heck did you get there?
          </xsl:message>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

  <xsl:template name="makeStatusList">
    <xsl:param name="noStatus" select="normalize-space($info)"/>
    <xsl:param name="noId" select="0"/>
    <xsl:variable name="link">
      <xsl:call-template name="makeLinkRelative">
        <xsl:with-param name="uri" select="@rdf:about"/>
      </xsl:call-template>
    </xsl:variable>
    <!-- to preserve the same a/@id, now that we're using dated URIs -->
    <xsl:variable name="link_old">
      <xsl:choose>
        <xsl:when test="not(rec:previousEdition)">
          <xsl:value-of select="doc:versionOf/@rdf:resource"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@rdf:about"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="id">
      <xsl:variable name="baseId" select="translate($link_old,'+','-')"/>
      <xsl:if test="not($noId)">
        <xsl:choose>
          <xsl:when test="contains($baseId,'/')">
            <xsl:variable name="notrailingslash">
              <xsl:choose>
                <xsl:when test="substring($baseId,string-length($baseId))='/'">
                  <xsl:value-of select="substring($baseId,1,string-length($baseId)-1)"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="$baseId"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <xsl:choose>
              <xsl:when test="contains($notrailingslash,'/')">
                <xsl:value-of select="substring-after($notrailingslash,'/')"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="$notrailingslash"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$baseId"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="listElement">
      <xsl:choose>
        <xsl:when test="normalize-space($info)">
          <xsl:text>li</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>dt</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:element name="{$listElement}">
      <a href="{normalize-space($link)}"><xsl:if test="not(contains($id,'/')) and not($noId)"><xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute><xsl:attribute name="name"><xsl:value-of select="$id"/></xsl:attribute></xsl:if><xsl:value-of select="dc:title"/></a>
      <xsl:if test="not($noStatus)">
        <xsl:text>: </xsl:text>
        <xsl:choose>
          <xsl:when test="normalize-space(local-name())='NOTE'">
            <xsl:text>Group Note</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="statusName"><xsl:with-param name="shortStatus" select="local-name()"/></xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
    </xsl:element>
    <xsl:if test="not(normalize-space($info))">
      <xsl:text>&#x0A;</xsl:text>
      <dd><xsl:call-template name="date:makeDateFriendly"><xsl:with-param name="date" select="translate(dc:date,'-','')"/></xsl:call-template>
      <xsl:for-each select="rec:editor[contact:fullName or org:name]">
        <!-- Yet another ugly 'skip an xsl:if' hack -->
        <xsl:value-of select="concat(', ',contact:fullName,org:name)"/>
      </xsl:for-each>
      <xsl:if test="mat:hasErrata">
        <xsl:text> - </xsl:text>(<a href="{mat:hasErrata/@rdf:resource}">Errata</a>)
      </xsl:if>
      <xsl:if test="rec:fromSubmission">
        <xsl:text> (</xsl:text><a href="{rec:fromSubmission/@rdf:resource}"><xsl:value-of select="/rdf:RDF/*[@rdf:about=current()/rec:fromSubmission/@rdf:resource]/dc:title"/></a><xsl:text>)</xsl:text>
      </xsl:if>
      <xsl:if test="rdf:type[@rdf:resource='http://www.w3.org/2001/02pd/rec54#Superseded'] and local-name()='Retired'">
        <xsl:text> - This document has been superseded by </xsl:text><a href="{/rdf:RDF/rdf:Description[rec:supersedes/@rdf:resource=current()/doc:versionOf/@rdf:resource]/@rdf:about}"><xsl:value-of select="/rdf:RDF/*[doc:versionOf/@rdf:resource=/rdf:RDF/rdf:Description[rec:supersedes/@rdf:resource=current()/doc:versionOf/@rdf:resource]/@rdf:about]/dc:title"/></a>
      </xsl:if>
      </dd>
      <xsl:text>&#x0A;</xsl:text>
      <xsl:if test="rec:prReviewsDue">
        <dd>Proposed Recommendation Reviews Ends <xsl:call-template name="date:makeDateFriendly"><xsl:with-param name="date" select="translate(rec:prReviewsDue,'-','')"/></xsl:call-template></dd>
      </xsl:if>
      <xsl:if test="rec:perReviewsDue">
        <dd>Proposed Edited Recommendation Reviews Ends <xsl:call-template name="date:makeDateFriendly"><xsl:with-param name="date" select="translate(rec:perReviewsDue,'-','')"/></xsl:call-template></dd>
      </xsl:if>
      <xsl:if test="rec:implementationFeedbackDue">
        <dd>Candidate Recommendation Phase Ends <xsl:call-template name="date:makeDateFriendly"><xsl:with-param name="date" select="translate(rec:implementationFeedbackDue,'-','')"/></xsl:call-template></dd>
      </xsl:if>
      <xsl:if test="rec:lastCallFeedBackDue">
        <dd>Last Call Ends <xsl:call-template name="date:makeDateFriendly"><xsl:with-param name="date" select="translate(rec:lastCallFeedBackDue,'-','')"/></xsl:call-template></dd>
      </xsl:if>
      <xsl:if test="rec:previousEdition">
        <xsl:variable name="uri" select="rec:previousEdition/@rdf:resource"/>
        <dd>This specification is a revision of the <a href="{$uri}"><xsl:value-of select="/rdf:RDF/rec:FirstEdition[@rdf:about=$uri]/dc:title|/rdf:RDF/rec:REC[@rdf:about=$uri]/dc:title"/> published on <xsl:call-template name="date:makeDateFriendly"><xsl:with-param name="date" select="translate(/rdf:RDF/rec:FirstEdition[@rdf:about=$uri]/dc:date|/rdf:RDF/rec:REC[@rdf:about=$uri]/dc:date,'-','')"/></xsl:call-template></a></dd>
      </xsl:if>
      <xsl:if test="/rdf:RDF/rec:*[local-name()='Retired' or local-name()='REC'][doc:versionOf/@rdf:resource=/rdf:RDF/rdf:Description[@rdf:about=current()/doc:versionOf/@rdf:resource]/rec:supersedes/@rdf:resource]/@rdf:about">
        <xsl:variable name="superseded" select="/rdf:RDF/rec:*[local-name()='Retired' or local-name()='REC'][doc:versionOf/@rdf:resource=/rdf:RDF/rdf:Description[@rdf:about=current()/doc:versionOf/@rdf:resource]/rec:supersedes/@rdf:resource]/@rdf:about"/>
        <dd>This specification supersedes <a href="{$superseded}"><xsl:value-of select="/rdf:RDF/*[@rdf:about=$superseded]/dc:title"/> published on <xsl:call-template name="date:makeDateFriendly"><xsl:with-param name="date" select="translate(/rdf:RDF/*[@rdf:about=$superseded]/dc:date,'-','')"/></xsl:call-template></a>
        <xsl:if test="/rdf:RDF/*[@rdf:about=$superseded]/rec:previousEdition">
          <xsl:variable name="previous" select="/rdf:RDF/*[@rdf:about=$superseded]/rec:previousEdition/@rdf:resource"/>
          <xsl:text> first published as </xsl:text><a href="{$previous}"><xsl:value-of select="/rdf:RDF/*[@rdf:about=$previous]/dc:title"/> on <xsl:call-template name="date:makeDateFriendly"><xsl:with-param name="date" select="translate(/rdf:RDF/*[@rdf:about=$previous]/dc:date,'-','')"/></xsl:call-template></a>
        </xsl:if>
        </dd>
      </xsl:if>
    </xsl:if>
  </xsl:template>

  <xsl:template name="makeLinkRelative">
    <xsl:param name="uri"/>
    <xsl:choose>
      <xsl:when test="starts-with($uri,'http://www.w3.org/TR/')">
        <xsl:value-of select="substring-after($uri,'http://www.w3.org/TR/')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="concat('../',substring-after($uri,'http://www.w3.org/'))"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="statusName">
    <xsl:param name="shortStatus"/>
    <xsl:choose>
      <xsl:when test="document('../../../2001/07/pubrules-copyright.xml')//*[local-name()='li']/*[local-name()='abbr' and .=$shortStatus]/@title">
        <xsl:value-of select="document('../../../2001/07/pubrules-copyright.xml')//*[local-name()='li']/*[local-name()='abbr' and .=$shortStatus]/@title"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$shortStatus='FirstEdition'">
            <xsl:text>Recommendation (First Edition)</xsl:text>
          </xsl:when>
          <xsl:when test="$shortStatus='LastCall'">
            <xsl:text>Working Draft in Last Call</xsl:text>
          </xsl:when>
          <xsl:when test="$shortStatus='Retired'">
            <xsl:text>Working Draft no longer in development</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            Unknown short status <xsl:value-of select="$shortStatus"/>
          </xsl:otherwise>
        </xsl:choose>
        
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="groupByActivity">
    <xsl:param name="mode" select="''"/>
    <xsl:variable name="wgData" select="document('../../../2000/04/mem-news/public-groups.rdf')/rdf:RDF"/>
    <xsl:choose>
      <xsl:when test="$mode='nav'">
     <!-- 
        <xsl:for-each select="$wgData/rdf:Description[rdf:type/@rdf:resource='http://www.w3.org/2001/04/roadmap/org#Activity'][org:includes]">
	<xsl:sort select="org:name"/>
        <xsl:variable name="activityId" select="translate(org:name,' ()','')"/>
	
	  <a href="#{$activityId}"><xsl:value-of select="org:name"/></a>  | 
	</xsl:for-each>
	-->
      </xsl:when>
      <xsl:otherwise>
        <xsl:for-each select="$wgData/rdf:Description[rdf:type/@rdf:resource='http://www.w3.org/2001/04/roadmap/org#Activity'][org:includes]">
	  <xsl:sort select="org:name"/>
          <xsl:variable name="activityId" select="translate(org:name,' ()','')"/>
	  <xsl:variable name="activityName" select="org:name"/>
 	  <h2>
	    <a name="{$activityId}" id="{$activityId}">
	      <xsl:value-of select="$activityName"/>
	    </a>
	  </h2>
          <xsl:for-each select="org:includes">
	    <xsl:variable name="wg" select="@rdf:nodeID"/>
	    <xsl:variable name="wgUri" select="$wgData/rdf:Description[@rdf:nodeID=$wg]/contact:homePage/@rdf:resource"/>
	    <!-- get rid of interest groups -->
	    <xsl:if test="$wgData/rdf:Description[@rdf:nodeID=$wg and rdf:type/@rdf:resource='http://www.w3.org/2001/04/roadmap/org#WorkingGroup']">
  	      <h3><xsl:value-of select="$wgData/rdf:Description[@rdf:nodeID=$wg ]/org:name"/></h3>
	      <xsl:choose>
	        <xsl:when test="$trdata/rec:*[org:deliveredBy/contact:homePage/@rdf:resource=$wgUri]">
		  <xsl:element name="{$listTypeElement}">
	            <xsl:for-each select="$trdata/rec:*[org:deliveredBy/contact:homePage/@rdf:resource=$wgUri][not(normalize-space($status)) or rdf:type/@rdf:resource=concat('http://www.w3.org/2001/02pd/rec54#',$status) or local-name()=$status]">
	              <xsl:sort select="normalize-space(dc:title)"/>
                      <xsl:call-template name="makeStatusList">
		        <xsl:with-param name="noId" select="1"/>
		      </xsl:call-template>
	            </xsl:for-each>
		  </xsl:element>
	        </xsl:when>
	        <xsl:otherwise>
	          <p>This working group has not published any Technical Report yet.</p>
	        </xsl:otherwise>
	      </xsl:choose>
	    </xsl:if>
	  </xsl:for-each>
	</xsl:for-each>
	
	<h2><a name="unknown" id="unknown">Other</a></h2>
	<xsl:element name="{$listTypeElement}">
	  <xsl:for-each 
	    select="$trdata/rec:*[not(org:deliveredBy) and doc:versionOf ]">
            <xsl:call-template name="makeStatusList">
	        <xsl:with-param name="noId" select="1"/>
            </xsl:call-template>
	  </xsl:for-each>
	</xsl:element>
	
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>

  <xsl:template name="groupByDate">
    <xsl:param name="mode" select="''"/>
    <xsl:param name="key" select="$upperBound"/>
    <xsl:if test="$trdata/rec:*[doc:versionOf][not(rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#Superseded' or local-name()='Superseded')][not(rec:previousEdition)][not(normalize-space($status)) or rdf:type/@rdf:resource=concat('http://www.w3.org/2001/02pd/rec54#',$status) or local-name()=$status][starts-with(dc:date,$key)]">
      <xsl:choose>
        <xsl:when test="$mode='nav'">
          <a href="#y{$key}"><xsl:value-of select="$key"/></a><xsl:text> - </xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <h2 id="y{$key}" class="key"><xsl:value-of select="$key"/></h2>
          <xsl:element name="{$listTypeElement}">
            <xsl:for-each select="$trdata/rec:*[doc:versionOf][not(rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#Superseded' or local-name()='Superseded')][not(rec:previousEdition)][not(normalize-space($status)) or rdf:type/@rdf:resource=concat('http://www.w3.org/2001/02pd/rec54#',$status) or local-name()=$status][starts-with(dc:date,$key)]">
              <xsl:sort select="normalize-space(dc:date)" order="descending"/>
              <xsl:call-template name="makeStatusList"/>
            </xsl:for-each>
          </xsl:element>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    <xsl:if test="$key &gt; 1994">
      <xsl:call-template name="groupByDate">
        <xsl:with-param name="key" select="$key - 1"/>
        <xsl:with-param name="mode" select="$mode"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template name="groupByTitle">
    <xsl:param name="cursor" select="1"/>
    <xsl:param name="mode" select="''"/>
    <xsl:variable name="key" select="substring($alphaKeys,$cursor,1)"/>
    <xsl:if test="$trdata/rec:*[doc:versionOf][not(rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#Superseded' or local-name()='Superseded')][not(local-name()='FirstEdition')][not(normalize-space($status)) or rdf:type/@rdf:resource=concat('http://www.w3.org/2001/02pd/rec54#',$status) or local-name()=$status][starts-with(translate(dc:title,'&quot;',''),$key)]">
      <xsl:choose>
        <xsl:when test="$mode='nav'">
          <a accesskey="{$key}" href="#{$key}"><xsl:value-of select="$key"/></a><xsl:text> - </xsl:text>
          <!-- <xsl:if test="normalize-space(substring($alphaKeys,$cursor+1,1)) and $trdata/rec:*[doc:versionOf][not(rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#Superseded' or local-name()='Superseded')][not(local-name()='FirstEdition')][not(normalize-space($status)) or rdf:type/@rdf:resource=concat('http://www.w3.org/2001/02pd/rec54#',$status) or local-name()=$status][starts-with(translate(dc:title,'&quot;',''),substring($alphaKeys,$cursor+1,1))]">
            <xsl:text> - </xsl:text>
          </xsl:if>
          -->
        </xsl:when>
        <xsl:otherwise>
          <h2 id="{$key}" class="key"><xsl:value-of select="$key"/></h2>
          <xsl:element name="{$listTypeElement}">
            <xsl:for-each select="$trdata/rec:*[doc:versionOf][not(rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#Superseded' or local-name()='Superseded')][not(local-name()='FirstEdition')][not(normalize-space($status)) or rdf:type/@rdf:resource=concat('http://www.w3.org/2001/02pd/rec54#',$status) or local-name()=$status][starts-with(dc:title,$key)]">
              <xsl:sort select="normalize-space(dc:title)"/>
              <xsl:call-template name="makeStatusList"/>
            </xsl:for-each>
          </xsl:element>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    <xsl:if test="$cursor &lt; string-length($alphaKeys)">
      <xsl:call-template name="groupByTitle">
        <xsl:with-param name="cursor" select="$cursor+1"/>
        <xsl:with-param name="mode" select="$mode"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template name="groupByEditor">
    <xsl:param name="cursor" select="1"/>
    <xsl:param name="mode" select="''"/>
    <xsl:variable name="key" select="substring($alphaKeys,$cursor,1)"/>
    <xsl:if test="document('known-tr-editors.rdf')/rdf:RDF/rdf:Description[starts-with(contact:sortName,$key)]">
      <xsl:choose>
        <xsl:when test="$mode='nav'">
          <a accesskey="{$key}" href="#{$key}"><xsl:value-of select="$key"/></a><xsl:text> - </xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <h2 id="{$key}" class="key"><xsl:value-of select="$key"/></h2>
          <xsl:for-each select="document('known-tr-editors.rdf')/rdf:RDF/rdf:Description[starts-with(contact:sortName,$key)]">
            <xsl:sort select="contact:sortName"/>
            <xsl:variable name="middle">
              <xsl:if test="contact:middleName">
                <xsl:value-of select="concat(contact:middleName,' ')"/>
              </xsl:if>
              <xsl:if test="contact:middleNameInitial">
                <xsl:value-of select="concat(contact:middleNameInitial,' ')"/>
              </xsl:if>
            </xsl:variable>
            <xsl:variable name="suffix">
              <xsl:if test="contact:personalSuffix">
                <xsl:value-of select="concat(' ',contact:personalSuffix)"/>
              </xsl:if>
            </xsl:variable>
            <xsl:variable name="first">
              <xsl:if test="contact:firstName">
                <xsl:value-of select="contact:firstName"/>
              </xsl:if>
              <xsl:if test="contact:firstNameInitial">
                <xsl:value-of select="contact:firstNameInitial"/>
              </xsl:if>
            </xsl:variable>
            <xsl:variable name="fullName1" select="concat($first,' ',$middle,contact:lastName,$suffix)"/>
            <xsl:variable name="fullName2" select="concat($first,' ',contact:lastName)"/>
            <xsl:variable name="fullName3" select="concat(contact:firstNameInOriginalScript,' ',contact:lastNameInOriginalScript)"/>
            <xsl:variable name="fullName4" select="concat(contact:lastNameInOriginalScript,' ',contact:firstNameInOriginalScript)"/>
            <xsl:variable name="name" select="org:name"/>
	    <!-- we don't want "empty" editors right ? -->
	    <xsl:if test="$trdata/rec:*[doc:versionOf][not(rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#Superseded' or local-name()='Superseded')][not(local-name()='FirstEdition')][not(normalize-space($status)) or rdf:type/@rdf:resource=concat('http://www.w3.org/2001/02pd/rec54#',$status) or local-name()=$status][rec:editor/contact:fullName=$fullName1 or rec:editor/contact:fullName=$fullName2 or (normalize-space($fullName3) and rec:editor/contact:fullName=$fullName3) or (normalize-space($fullName4) and rec:editor/contact:fullName=$fullName4) or rec:editor/org:name=$name]">
              <h3><xsl:attribute name="id"><xsl:value-of select="translate(concat(org:name,contact:sortName,$first,$middle),&quot;' .&quot;,'')"/></xsl:attribute><xsl:value-of select="normalize-space(concat(org:name,contact:lastName,', ',$first,' ',$middle))"/><xsl:if test="normalize-space($fullName4)"> (<xsl:value-of select="$fullName4"/>)</xsl:if></h3>
              <xsl:element name="{$listTypeElement}">
                <xsl:for-each select="$trdata/rec:*[doc:versionOf][not(rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#Superseded' or local-name()='Superseded')][not(normalize-space($status)) or rdf:type/@rdf:resource=concat('http://www.w3.org/2001/02pd/rec54#',$status) or local-name()=$status][not(local-name()='FirstEdition')][rec:editor/contact:fullName=$fullName1 or rec:editor/contact:fullName=$fullName2 or (normalize-space($fullName3) and rec:editor/contact:fullName=$fullName3) or (normalize-space($fullName4) and rec:editor/contact:fullName=$fullName4) or rec:editor/org:name=$name]">
                  <xsl:sort select="dc:date" order="descending"/>
                  <xsl:sort select="normalize-space(dc:title)"/>
                  <xsl:call-template name="makeStatusList">
                    <xsl:with-param name="noId" select="1"/>
                  </xsl:call-template>
                </xsl:for-each>
              </xsl:element>
	    </xsl:if>
          </xsl:for-each>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    <xsl:if test="$cursor &lt; string-length($alphaKeys)">
      <xsl:call-template name="groupByEditor">
        <xsl:with-param name="cursor" select="$cursor+1"/>
        <xsl:with-param name="mode" select="$mode"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>
