<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns:uddi="urn:uddi-org:api_v2"
      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
      xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
      xmlns:owl="http://www.w3.org/2002/07/owl#" 
      xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:xoomle="http://www.dentedreality.com.au/xoomle/docs/">

  <!-- include reference to document containing the developer's keys -->
  <xsl:import href="keys.xsl"/>

  <!-- setup the baseline queries -->
  <xsl:variable name="google">http://xoomle.dentedreality.com.au</xsl:variable>
  <xsl:variable name="google-search-base"><xsl:value-of select="concat($google, '/search')"/></xsl:variable>
  <xsl:variable name="google-spelling-base"><xsl:value-of select="concat($google, '/spell')"/></xsl:variable>
  <xsl:variable name="google-cache-base"><xsl:value-of select="concat($google, '/cache')"/></xsl:variable>


<!-- Obtain the first url from the search criteria ========================-->
  <xsl:template name="feeling-lucky">
    <xsl:param name="search-term"/>

    <!-- Build the query string -->
    <xsl:variable name="google-query-string">
      <xsl:variable name="base-query">
        <xsl:call-template name="google-request">
          <xsl:with-param name="search-term" select="$search-term"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="concat($base-query, '&amp;maxResults=1')"/>
    </xsl:variable>

    <xsl:variable name="google-results" select="document($google-query-string)"/>

    <xsl:value-of select="$google-results//xoomle:URL"/>
    
  </xsl:template>

  <!-- Obtain the first 6 items from the search criteria =========================-->
  <xsl:template name="six-pack">
    <xsl:param name="search-term"/>

    <!-- Build the query string -->
    <xsl:variable name="google-query-string">
      <xsl:variable name="base-query">
        <xsl:call-template name="google-request">
          <xsl:with-param name="search-term" select="$search-term"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="concat($base-query, '&amp;maxResults=6')"/>
    </xsl:variable>

    <xsl:variable name="google-results" select="document($google-query-string)"/>
      <xsl:for-each select="$google-results//xoomle:item">
          <a><xsl:attribute name="title">
                        <xsl:value-of select="xoomle:snippet"/></xsl:attribute>
          <xsl:attribute name="href">
            <xsl:value-of select="."/>
          </xsl:attribute>
          :<xsl:value-of select="xoomle:title"/>
        </a> 

    </xsl:for-each>
    <xsl:value-of select="$google-results//xoomle:URL"/>
    
  </xsl:template>

<!-- Obtain the first 6 items from the search criteria =========================-->
  <xsl:template name="six-pack-plus">
    <xsl:param name="search-term"/>

    <!-- Build the query string -->
    <xsl:variable name="google-query-string">
      <xsl:variable name="base-query">
        <xsl:call-template name="google-request">
          <xsl:with-param name="search-term" select="$search-term"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="concat($base-query, '&amp;maxResults=6')"/>
    </xsl:variable>

    <xsl:variable name="google-results" select="document($google-query-string)"/>
      <xsl:for-each select="$google-results//xoomle:item">
          <a><xsl:attribute name="title">
                        <xsl:value-of select="xoomle:snippet"/></xsl:attribute>
          <xsl:attribute name="href">
            <xsl:value-of select="xoomle:URL"/>
          </xsl:attribute>
          :<xsl:value-of select="xoomle:URL"/>
        </a> 
        <xsl:if test="contains(xoomle:URL,'.rdf')">-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
         <xsl:variable name="rdfSnip" select="document(xoomle:URL)"/>
        
             
 
            <xsl:for-each select="$rdfSnip">
                &lt;!--Owl Content:     Number of OWL Classes: <xsl:value-of select="count(//owl:*)"/>
              Number of RDF Objects: <xsl:value-of select="count(//rdf:*)"/>---&gt;
               
                <xsl:for-each select="./@rdf:about">
                    about:<xsl:value-of select="*"/>
                 </xsl:for-each>
                 <xsl:for-each select="./@rdf:resource">
                     resource:<xsl:value-of select="*"/>
                 </xsl:for-each>
              </xsl:for-each>
          </xsl:if>
<!-- 
          <xsl:element name="Input"><xsl:attribute name="type">file</xsl:attribute>
            Title:<xsl:value-of select="xoomle:title"/>Snippet:<xsl:value-of select="xoomle:snippet"/>
         </xsl:element>  -->
    </xsl:for-each>
    <xsl:value-of select="$google-results//xoomle:URL"/>
    
  </xsl:template>


  <!-- Perform the basic google search ===========================-->
  <xsl:template name="basic-search">
    <xsl:param name="search-term"/>

    <xsl:variable name="google-query-string">
      <xsl:call-template name="google-request">
        <xsl:with-param name="search-term" select="$search-term"/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="google-results" select="document($google-query-string)"/>

    <xsl:copy-of select="$google-results"/>

  </xsl:template>



  <!-- Creates the core search query containing base URL, search terms and the developer key ======-->
  <xsl:template name="google-request">
    <xsl:param name="search-term"/>

    <!-- Remove extraneous whitespace, then substitue '+' for space characters -->
    <xsl:variable name="google-search">
      <xsl:value-of select="translate(normalize-space($search-term), ' ', '+')"/>
    </xsl:variable>

    <!-- Extract the google key from the $key document -->
    <xsl:variable name="google-key" select="document($key)//google"/>
    <xsl:value-of select="concat($google-search-base, '?q=', $google-search, '&amp;key=', $google-key)"/>

  </xsl:template>
<!-- Obtain the first 6 items from the search criteria =========================-->
  <xsl:template name="search-for-wiki">
    <xsl:param name="search-term1"/>
	<xsl:for-each select="$search-term1">
zzzzzzzzzzzzz
	        <xsl:call-template name="two-for-wiki">
        		<xsl:with-param name="search-term" select="$search-term1"/>
                          </xsl:call-template>
 	</xsl:for-each>
</xsl:template>
<!-- Obtain the first 6 items from the search criteria =========================-->
  <xsl:template name="two-for-wiki">
    <xsl:param name="search-term"/>

    <!-- Build the query string -->
    <xsl:variable name="google-query-string">
      <xsl:variable name="base-query">
         <xsl:call-template name="google-request"><xsl:with-param name="search-term" select="$search-term"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="concat($base-query, '&amp;maxResults=6')"/>
    </xsl:variable>

    <xsl:variable name="google-results" select="document($google-query-string)"/>
      <xsl:for-each select="$google-results//xoomle:item">
          <a><xsl:attribute name="title">
                        <xsl:value-of select="xoomle:snippet"/></xsl:attribute>
          <xsl:attribute name="href">
            <xsl:value-of select="xoomle:URL"/>
          </xsl:attribute>
          :<xsl:value-of select="xoomle:URL"/>
        </a> [RefGoogle][<xsl:value-of select="xoomle:URL"/>]
        <xsl:if test="contains(xoomle:URL,'.rdf')">-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
         <xsl:variable name="rdfSnip" select="document(xoomle:URL)"/>
        
             
 
            <xsl:for-each select="$rdfSnip">
                &lt;!--Owl Content:     Number of OWL Classes: <xsl:value-of select="count(//owl:*)"/>
              Number of RDF Objects: <xsl:value-of select="count(//rdf:*)"/>---&gt;
               
                <xsl:for-each select="./@rdf:about">
                    about:<xsl:value-of select="*"/>
                 </xsl:for-each>
                 <xsl:for-each select="./@rdf:resource">
                     resource:<xsl:value-of select="*"/>
                 </xsl:for-each>
              </xsl:for-each>
          </xsl:if>
<!--   -->
    </xsl:for-each>
    <xsl:value-of select="$google-results//xoomle:URL"/>
    
  </xsl:template>
</xsl:stylesheet>
