<?xml version="1.0" encoding="utf-8"?>
<!-- $Id: aboutTests.xsl,v 1.23 2007/09/24 08:02:41 jcarroll Exp $ -->

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:s="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:h="http://www.w3.org/1999/xhtml"
  xmlns:t="http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#"
  xmlns:g="http://www.w3.org/2001/sw/grddl-wg/td/grddl-test-vocabulary#"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  exclude-result-prefixes="xlink"
  version="1.0">

<xsl:output method="xml" indent="yes"/>
<xsl:param name="infTests" select="true()"/>
<div xmlns="http://www.w3.org/1999/xhtml">
<address>$Id: aboutTests.xsl,v 1.23 2007/09/24 08:02:41 jcarroll Exp $</address>
</div>

<xsl:template match="/">
  <r:RDF xml:base="http://www.w3.org/2001/sw/grddl-wg/td/">
    <xsl:comment>If you wish to run the tests using local copies of the 
files then it is possible to modify the above xml:base as 
appropriate.</xsl:comment>
    <xsl:apply-templates />
  </r:RDF>
</xsl:template>   
<!-- Duplicate A
<xsl:template match="h:a[@href='#testing_GRDDL_transformation']" mode="coverage">
    <g:exercisesRule
        r:resource="http://www.w3.org/TR/grddl/#rule_GRDDL_transformation"/>
</xsl:template>
-->
<xsl:template match="h:a[@href='#testing_merge']" mode="coverage">
    <g:exercisesRule
        r:resource="http://www.w3.org/TR/grddl/#rule_merge"/>
</xsl:template>
<xsl:template match="h:a[@href='#testing_rdfxbase']" mode="coverage">
    <g:exercisesRule
        r:resource="http://www.w3.org/TR/grddl/#rule_rdfxbase"/>
</xsl:template>
<!-- left A -->
<xsl:template match="h:a[@href='#testing_GRDDL_transformation']" mode="coverage">
    <g:exercisesRule
        r:resource="http://www.w3.org/TR/grddl/#rule_GRDDL_transformation"/>
</xsl:template>
<xsl:template match="h:a[@href='#testing_nstx']" mode="coverage">
    <g:exercisesRule
        r:resource="http://www.w3.org/TR/grddl/#rule_nstx"/>
</xsl:template>
<xsl:template match="h:a[@href='#testing_tlrel']" mode="coverage">
    <g:exercisesRule
        r:resource="http://www.w3.org/TR/grddl/#rule_tlrel"/>
</xsl:template>
<xsl:template match="h:a[@href='#testing_profiletrans']" mode="coverage">
    <g:exercisesRule
        r:resource="http://www.w3.org/TR/grddl/#rule_profiletrans"/>
</xsl:template>
<xsl:template match='h:ul[@class="TestList"]/h:li'>
  <t:Test>
     <xsl:call-template name="inside-test-item" />
     <xsl:apply-templates select=".//h:a[@class='grddlCoverage']" mode="coverage"/>
  </t:Test>
</xsl:template>
<xsl:template match='h:ul[@class="InformativeTestList"]/h:li'>
  <xsl:if test="$infTests">
    <t:Test>
       <xsl:call-template name="inside-test-item" />
       <xsl:apply-templates select=".//h:a[@class='grddlCoverage']" mode="coverage"/>
    </t:Test>
  </xsl:if>
</xsl:template>
<xsl:template match='h:ul[@class="TestList"]/h:li[@class="SecurityTest"]' priority="10" >
  <g:SecurityTest>
     <xsl:call-template name="inside-test-item" />
  </g:SecurityTest>
</xsl:template>
<xsl:template name="inside-test-item">
  <xsl:variable name="baseUri">
    <xsl:choose>
      <xsl:when test="@class = 'NetworkedTest'">http://www.w3.org/2001/sw/grddl-wg/td/</xsl:when>
      <xsl:otherwise></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>  
  <xsl:variable name="outputRef" 
                select=".//h:a[text()='output']/@href"/>
  <xsl:variable name="inputRef" 
                select=".//h:a[text()='input']/@href"/>
  <xsl:variable name="testId" select="@id"/>
  <xsl:attribute name="r:about"><xsl:value-of select="concat('http://www.w3.org/2001/sw/grddl-wg/td/grddl-tests#',$testId)"/></xsl:attribute>    
  <xsl:if test="@class = 'NetworkedTest'">
    <r:type r:resource="http://www.w3.org/2001/sw/grddl-wg/td/grddl-test-vocabulary#NetworkedTest"/>
  </xsl:if>
  <dc:title><xsl:value-of select="h:b" /></dc:title>
  <t:inputDocument 
    r:resource='{concat($baseUri,
                        substring-after($inputRef,"http://www.w3.org/2001/sw/grddl-wg/td/"))}' />
  <t:outputDocument 
    r:resource='{concat($baseUri,
                        substring-after($outputRef,"http://www.w3.org/2001/sw/grddl-wg/td/"))}'/>
  <xsl:if test="h:p[@class='approved-test']">
    <t:approval r:resource="{h:p[@class='approved-test']/h:a/@href}"/>
  </xsl:if>
  <xsl:choose>
    <xsl:when test="h:div[@class = 'maximal-result']">
      <!-- The maximal result-->
      <xsl:for-each select="../h:li[.//h:a[text()='input']/@href = $inputRef and not(@id = $testId)]">
        <g:subsumes r:resource="http://www.w3.org/2001/sw/grddl-wg/td/grddl-tests#{@id}"/>
      </xsl:for-each>      
    </xsl:when>
    <xsl:when test="not(../h:li[.//h:a[text()='input']/@href = $inputRef and not(@id = $testId)]/h:div[@class = 'maximal-result'])">
      <!-- A group without a maximal result-->
      <xsl:for-each select="../h:li[.//h:a[text()='input']/@href = $inputRef and not(@id = $testId)]">
        <g:alternative r:resource="http://www.w3.org/2001/sw/grddl-wg/td/grddl-tests#{@id}"/>
      </xsl:for-each>                  
    </xsl:when>
    <xsl:when test="not(h:div[@class = 'maximal-result']) and ../h:li[.//h:a[text()='input']/@href = $inputRef and not(@id = $testId)]/h:div[@class = 'maximal-result']">
      <!-- A test subsumed by a maximal test is an alternative for the other non-maximal tests -->
      <xsl:for-each 
        select="../h:li[.//h:a[text()='input']/@href = $inputRef and not(@id = $testId)]">
        <xsl:if test="not(h:div[@class = 'maximal-result'])">
          <g:alternative r:resource="http://www.w3.org/2001/sw/grddl-wg/td/grddl-tests#{@id}"/>  
        </xsl:if>        
      </xsl:for-each>                  
    </xsl:when>
  </xsl:choose>
</xsl:template>

<!-- don't pass text  thru -->
<xsl:template match="text()|@*">
</xsl:template>

</xsl:stylesheet>
