<?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 version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"     xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:doc="http://www.w3.org/2000/10/swap/pim/doc#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rec="http://www.w3.org/2001/02pd/rec54#"
  xmlns:uri="http://www.w3.org/2000/07/uri43/uri.xsl?template="
exclude-result-prefixes="rdf doc dc rec uri">

  <xsl:import href="http://www.w3.org/2000/07/uri43/uri.xsl"/>

<!-- Output method XML -->
<xsl:output method="xml" 
  indent="yes"
  omit-xml-declaration="no" 
  encoding="utf-8" 
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"  />

<!-- useful for tools based on the XSLT servlet -->
  <xsl:param name="xmlfile"/>
  <xsl:variable name="doc_uri">
    <xsl:choose>
      <xsl:when test="starts-with($xmlfile,'http://cgi.w3.org/cgi-bin/tidy-if?docAddr=')">
        <xsl:value-of select="substring-after($xmlfile,'http://cgi.w3.org/cgi-bin/tidy-if?docAddr=')"/>
      </xsl:when>
      <xsl:when test="starts-with($xmlfile,'http://cgi.w3.org/cgi-bin/tidy?docAddr=')">
        <xsl:value-of select="substring-after($xmlfile,'http://cgi.w3.org/cgi-bin/tidy?docAddr=')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$xmlfile"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

 
<!-- Documenting the XSLT : fill the @@@-->
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="stylesheet" href="http://www.w3.org/StyleSheets/base"/>
    <title>TR References checker</title>
  </head>
  <body>
    <div class='head'><a href="/"><img src="/Icons/w3c_home" alt="W3C"/></a> <a href="http://www.w3.org/2002/01/tr-automation/">TR Automation</a></div>
    <h1>TR References checker</h1>

    <p>This XSLT style sheet flags links to <a href="/TR/">TR documents</a> in a given XHTML that aren't the latest version of a document; this makes it a convenient tool to detect outdated references.</p>

    <form action="http://www.w3.org/2002/08/xslt4html" method="get">
      <div>
        <input type="hidden" name="xslfile" value="http://www.w3.org/2004/07/references-checker" />
        <p><label>URI of the HTML page: <input type="text" name="xmlfile" value="http://www.w3.org/" /></label></p>
        <p><input type="submit" value="Process" /><input type="reset" /></p>
      </div>
    </form>


    <p class="copyright">Copyright &#169; 1994-2004 <a href="http://www.w3.org/">World Wide Web Consortium</a>, (<a
href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of
Technology">M.I.T.</acronym></a>, <a
href="http://www.ercim.org/"><acronym
title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a
href="http://www.keio.ac.jp/">Keio University</a>). All Rights
    Reserved. http://www.w3.org/Consortium/Legal/. W3C <a href="http://www.w3.org/Consortium/Legal/copyright-software">software licensing</a> rules apply.</p>
    <address><a href="http://www.w3.org/People/Dom/">Dominique Haza&#235;l-Massieux</a> - $Id: references-checker.xsl,v 1.10 2004/11/18 15:27:20 dom Exp $</address>
    </body>
</html>

<xsl:variable name="trdata" select="document('http://www.w3.org/2002/01/tr-automation/tr.rdf')/rdf:RDF"/>

<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="stylesheet" href="http://www.w3.org/StyleSheets/base"/>
    <title>TR References checker applied to <xsl:value-of select="/html:html/html:head/html:title"/></title>
  </head>
  <body>
    <div class='head'><a href="/"><img src="/Icons/w3c_home" alt="W3C"/></a> <a href="http://www.w3.org/2002/01/tr-automation/">TR Automation</a></div>
    <h1>TR References checker applied to <a href="{$doc_uri}"><xsl:value-of select="/html:html/html:head/html:title"/></a></h1>

    <p>The following references were found in this document, and point to an outdate version of a W3C Technical Report:</p>
    <ul>
      <!-- finding all dated links to TR space -->
      <xsl:for-each select="//html:a[starts-with(@href,'http://www.w3.org/TR/1') or starts-with(@href,'/TR/1') or starts-with(@href,'http://www.w3.org/TR/2') or starts-with(@href,'/TR/2')][not(parent::html:dd/preceding-sibling::html:dt[1][contains(translate(.,'PV','pv'),'previous version')]) and not(@href='http://www.w3.org/TR/2002/NOTE-patent-practice-20020124')]">
        <xsl:variable name="uriRef">
          <xsl:call-template name="uri:expand">
            <xsl:with-param name="base" select="$doc_uri"/>
            <xsl:with-param name="there" select="@href"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="datedDir" select="substring($uriRef,0,string-length('http://www.w3.org/TR/') + 6)"/>
        <xsl:variable name="trUri">
          <xsl:value-of select="substring-before(concat(concat($datedDir,substring-before(concat(substring-after($uriRef,$datedDir),'/'),'/')),'#'),'#')"/>
        </xsl:variable>
        <xsl:variable name="trUriWSlash" select="concat($trUri,'/')"/>
        <xsl:if test="(not($trdata/*[@rdf:about=$trUri]) and not($trdata/*[@rdf:about=$trUriWSlash])) or ($trdata/*[(@rdf:about=$trUri or @rdf:about=$trUriWSlash) and (rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#FirstEdition' or local-name()='FirstEdition' or rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#Retired' or local-name()='Retired' or rdf:type/@rdf:resource='http://www.w3.org/2001/02pd/rec54#Superseded' or local-name()='Superseded')])">
          <li>The reference in <q><xsl:apply-templates select="."/></q> is probably outdated (or not considered a TR anymore)</li>
        </xsl:if>
      </xsl:for-each>
      <li>nothing else</li>
    </ul>

    <h2>Check another page</h2>

    <p>This XSLT style sheet flags links to <a href="/TR/">TR documents</a> in a given XHTML that aren't the latest version of a document; this makes it a convenient tool to detect outdated references.</p>

    <form action="http://www.w3.org/2002/08/xslt4html" method="get">
      <div>
        <input type="hidden" name="xslfile" value="http://www.w3.org/2004/07/references-checker" />
        <p><label>URI of the HTML page: <input type="text" name="xmlfile" value="{$doc_uri}" /></label></p>
        <p><input type="submit" value="Process" /><input type="reset" /></p>
      </div>
    </form>


    <p class="copyright">Copyright &#169; 1994-2004 <a href="http://www.w3.org/">World Wide Web Consortium</a>, (<a
href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of
Technology">M.I.T.</acronym></a>, <a
href="http://www.ercim.org/"><acronym
title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a
href="http://www.keio.ac.jp/">Keio University</a>). All Rights
    Reserved. http://www.w3.org/Consortium/Legal/. W3C <a href="http://www.w3.org/Consortium/Legal/copyright-software">software licensing</a> rules apply.</p>
    <address>Produced by <a href="http://www.w3.org/2004/07/references-checker">an XSLT</a>, developed by <a href="http://www.w3.org/People/Dom/">Dominique Haza&#235;l-Massieux</a> - $Id: references-checker.xsl,v 1.10 2004/11/18 15:27:20 dom Exp $</address>
    </body>
</html>
  
</xsl:template>

  <!-- default: Identity Transformation -->
  <xsl:template match="*|@*|comment()|text()">
    <xsl:copy>
      <xsl:apply-templates select="*|@*|comment()|text()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>