<?xml version="1.0"?>
<?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"?>
<!--
$Id: is-valid.xsl,v 1.34 2006/01/30 18:29:49 matthieu 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:vld="http://www.w3.org/2001/11/is-valid.xsl" exclude-result-prefixes="vld html">

<!-- Tests run when in units test mode -->
<tests xmlns="http://www.w3.org/2001/11/is-valid.xsl">
  <test>
    <uri>http://www.w3.org/</uri>
    <HTMLvalid>OK</HTMLvalid>
    <CSSvalid>OK</CSSvalid>
  </test>
  <!-- update as needed -->
  <test>
    <uri>http://www.lucent.com/</uri>
    <HTMLvalid>Error</HTMLvalid>
    <CSSvalid>OK</CSSvalid>
  </test>
  <test>
    <uri>http://lists.w3.org/Archives/Public/www-qa/2005Feb/0032.html</uri>
    <HTMLvalid>OK</HTMLvalid>
    <CSSvalid>Error</CSSvalid>
  </test>
</tests>



<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="stylesheet" href="http://www.w3.org/StyleSheets/base"/>
    <title>Templates to get validity results</title>
  </head>
  <body>
    <div class='head'><a href="/"><img src="/Icons/w3c_home" alt="W3C"/></a> | <a href="../../2001/10/xslt-toolbox">XSLT toolbox</a></div>

    <h1>
    Templates to get validity results
    </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>

    <p>It comes with a Unit test, to allow easier debugging; the test is obtained by running the style sheet against any XML, and the output is given through <code>xsl:message</code>.</p>

    <h2>Templates</h2>
    <p>Note that to be used, this stylesheet needs online resources.</p>
    <dl>
      <dt>vld:is-html-valid</dt>
      <dd>Takes a <var>doc_uri</var> parameter with the URI of the document to be checked against HTML validity and returns <code>yes</code>, <code>no</code> or <code>tocheck</code> when the result is not understandable</dd>
      <dt>vld:is-css-valid</dt>
      <dd>Takes a <var>doc_uri</var> parameter with the URI of the document to be checked against CSS validity and returns <code>yes</code>, <code>no</code> or <code>tocheck</code> when the result is not understandable</dd>
    </dl>

    <hr />

    <address>$Id: is-valid.xsl,v 1.34 2006/01/30 18:29:49 matthieu Exp $
    <br />

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

<!-- For the Unit Test -->
<xsl:template match="/">
  <xsl:message>Starting</xsl:message>
  <xsl:for-each select="document('')/xsl:stylesheet/vld:tests/vld:test">
      <xsl:message>Running test # <xsl:value-of select="position()"/>: <xsl:value-of select="vld:uri"/></xsl:message>
    <xsl:variable name="HTMLresult">
      <xsl:call-template name="vld:is-html-valid">
        <xsl:with-param name="doc_uri" select="vld:uri"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="CSSresult">
      <xsl:call-template name="vld:is-css-valid">
        <xsl:with-param name="doc_uri" select="vld:uri"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="vld:HTMLvalid!=$HTMLresult">
        <xsl:message>-&gt; HTML validation failed: got <xsl:value-of select="$HTMLresult"/>, expected <xsl:value-of select="vld:HTMLvalid"/></xsl:message>
      </xsl:when>
      <xsl:when test="vld:CSSvalid!=$CSSresult">
        <xsl:message>-&gt; CSS validation failed: got <xsl:value-of select="$CSSresult"/>, expected <xsl:value-of select="vld:CSSvalid"/></xsl:message>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>success!</xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>
</xsl:template>



<xsl:template name="vld:is-html-valid">
  <xsl:param name="doc_uri"/>
  <xsl:variable name="result" select="document(concat('http://cgi.w3.org/cgi-bin/tidy?docAddr=http://validator.w3.org/check?uri=',$doc_uri))/html:html/html:body"/>
  <xsl:choose>
    <xsl:when test="$result//html:div[@id='result']/child::html:h2[@class='valid']">OK</xsl:when>
    <xsl:otherwise>
      <a href="http://validator.w3.org/check?uri={$doc_uri}">
        <xsl:choose>
          <xsl:when test="$result//html:div[@id='result']/child::html:h2[@class='invalid']">Error</xsl:when>
          <xsl:otherwise>Markup Validation Service</xsl:otherwise>
        </xsl:choose>
      </a>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="vld:is-css-valid"  xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:m="http://www.w3.org/2005/07/css-validator">
  <xsl:param name="doc_uri"/>
  <!-- Using SOAP output of the CSS Validator -->
  <xsl:variable name="result" select="document(concat('http://jigsaw.w3.org/css-validator/validator?usermedium=all&amp;output=soap12&amp;uri=',$doc_uri))/env:Envelope/env:Body/m:cssvalidationresponse/m:validity"/>
  <xsl:choose>
    <xsl:when test="$result='true'">OK</xsl:when>
    <xsl:otherwise>
      <a href="http://jigsaw.w3.org/css-validator/validator?uri={$doc_uri}">
        <xsl:choose>
          <xsl:when test="$result='false'">Error</xsl:when>
          <xsl:otherwise>CSS Validation Service</xsl:otherwise>
        </xsl:choose>
      </a>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>

