<?xml version="1.0"?>
<!--
$Id: http-head.xsl,v 1.10 2002/05/22 18:40:57 dom Exp $
-->
<?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:html="http://www.w3.org/1999/xhtml"
xmlns:http="http://www.w3.org/2001/11/http-head.xsl"
xmlns:str="http://www.w3.org/2001/10/str-util.xsl">
<xsl:import href="http://www.w3.org/2001/10/str-util.xsl"/>
  <div xmlns="http://www.w3.org/1999/xhtml">
    <h1>
    <a href="http://www.w3.org/">
      <img src="http://www.w3.org/Icons/w3c_home" alt="W3C" />
    </a>
    XSLT Templates to get the value of some HTTP headers
    </h1>

    <h2>Status</h2>

    <p>The templates in this stylesheet are used in several other
    ones. Please don't modify it without letting me know and don't
    break the current exposed API in any case.</p>

    <h2>Templates</h2>
    <p>Note that to be used, this stylesheet needs online resources.</p>
    <dl>
      <dt>http:get-header</dt>
      <dd>Takes the URI of the document to get the header from (<var>doc_uri</var>) and the header to be extracted (<var>header_name</var>) and gives the value of this header.</dd>
      <dt>http:get-content-type</dt>
      <dd>Takes the URI of the document to get the header from (<var>doc_uri</var>) and gives the content-type of the given resource (you can precise if you want the parameters or not with a variable <var>with-param</var> which takes the value <code>yes</code> or <code>no</code>)</dd>
      <dt>http:get-etag</dt>
      <dd>Takes the URI of the document to get the header from (<var>doc_uri</var>) and gives the ETag HTTP Header of the given resource</dd>
      <dt>http:get-status-code</dt>
      <dd>Takes the URI of the document at <var>doc_uri</var> and outputs the HTTP status code for this URI (200, 404, ...)</dd>
    </dl>
    <h2>References</h2>
    <ul>
	<li><a href="/2001/10/xslt-toolbox.html">the XSLT Toolbox</a></li>
    </ul>

    <hr />

    <address>$Id: http-head.xsl,v 1.10 2002/05/22 18:40:57 dom Exp $
    <br />

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

    <hr />
</div>
<xsl:template name="http:get-header">
  <xsl:param name="doc_uri"/>
  <xsl:param name="header_name"/>
  <xsl:if test="starts-with($doc_uri,'http://')">
    <xsl:value-of select="document(concat('http://cgi.w3.org/cgi-bin/headers?url=',$doc_uri))/html:html/html:body/html:pre/html:span[@class='headername' and .=$header_name][position()=last()]/following::html:span[@class='headervalue'][1]"/>
  </xsl:if>
</xsl:template>

<xsl:template name="http:get-content-type">
  <xsl:param name="doc_uri"/>
  <xsl:param name="with-param">yes</xsl:param>
  <xsl:variable name="header"><xsl:call-template name="http:get-header"><xsl:with-param name="doc_uri" select="$doc_uri"/><xsl:with-param name="header_name">Content-Type</xsl:with-param></xsl:call-template></xsl:variable>
  <xsl:choose><xsl:when test="$with-param='yes'"><xsl:value-of select="$header"/></xsl:when><xsl:otherwise><xsl:call-template name="str:keep-before"><xsl:with-param name="string" select="$header"/><xsl:with-param name="delimiter">;</xsl:with-param></xsl:call-template></xsl:otherwise></xsl:choose>
</xsl:template>

<xsl:template name="http:get-etag">
  <xsl:param name="doc_uri"/>
  <xsl:call-template name="http:get-header">
    <xsl:with-param name="header_name">
      <xsl:text>Etag</xsl:text>
    </xsl:with-param>
    <xsl:with-param name="doc_uri" select="$doc_uri"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="http:get-status-code">
  <xsl:param name="doc_uri"/>
  <xsl:if test="starts-with($doc_uri,'http://')">
    <xsl:value-of select="document(concat('http://cgi.w3.org/cgi-bin/headers?url=',$doc_uri))/html:html/html:body/html:pre/html:span[@class='errcode'][position()=last()]"/>
  </xsl:if>
</xsl:template>
</xsl:stylesheet>
