<?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:dcterms="http://purl.org/dc/terms/"
      xmlns:service="http://www.daml.org/services/owl-s/1.0/Service.owl#"
      xmlns:d="http://www.daml.org/services/owl-s/1.0/CongoService.owl#"
      xmlns:fo="http://www.w3.org/1999/XSL/Format"
      xmlns:scripts ="http://architag.com/scripts" 
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:html="http://www.w3.org/1999/xhtml"
      xmlns:rss="http://purl.org/rss/1.0/" 
      xmlns:wiki="http://purl.org/rss/1.0/modules/wiki/"
>

<!-- XSL programming environment for TWiki.                                      -->
<!-- <?xml ... header contains file menu to allow you to load your file for edit !  -->
<!--  -->
<!-- known problems:-->
<!-- -->
<!-- 
    This is alpha code of a compact XML manipulation tool. 
    Copyright (c) 2004 Forth Party software
    Please send comments to: JCoe18@excite.com
http://twiki.org/cgi-bin/edit/Main/XslWiki
-->
  <!-- include reference to document containing the developer's keys -->
  <xsl:import href="keys.xsl"/>

 <!-- Extract the wiki key from the $key document -->
    <xsl:variable name="wiki-key" select="document($key)//wiki"/>
  <xsl:variable name="wikiBranch" select="document($key)//wikiBranch"/>

<xsl:variable name="wikiBase">http://twiki.org/cgi-bin/</xsl:variable>
<xsl:variable name="RSSuri">http://twiki.org/cgi-bin/view/Sandbox/TestRSS?skin=rss&amp;contenttype=text/xml</xsl:variable>
<xsl:variable name="wikiEdit"><xsl:value-of select="concat('edit/', $wikiBranch,'/')"/></xsl:variable>
<xsl:variable name="wikiCreate">?topicparent=Sandbox.</xsl:variable>
<xsl:variable name="wiki"><xsl:value-of select="concat($wikiBase, $wikiEdit,$wiki-key)"/></xsl:variable>
<xsl:variable name="wikiNew">  <xsl:value-of select="concat($wikiBase,'edit/Sandbox/XslWikiRssResult',$wikiCreate,$wiki-key)"/>
</xsl:variable>
<xsl:variable name="wikiMain">http://twiki.org</xsl:variable>

	<xsl:attribute-set name="a">
		<xsl:attribute name="text-decoration">underline</xsl:attribute>
		<xsl:attribute name="color">blue</xsl:attribute>
	</xsl:attribute-set>

 <xsl:template name="get-wiki-head">
    <xsl:param name="title"/>
 <xsl:message terminate="no">
        Accessing wiki
      </xsl:message>
    <xsl:variable name="wiki-result" select="document($wiki)"/>
           <xsl:for-each select="$wiki-result/html:head/html:base">
                          <xsl:fallback>
		 <xsl:message terminate="yes">
                                        Accessing wiki fallback
                                   </xsl:message>
  	       </xsl:fallback>
                      <xsl:element name="base"> <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>    
                       </xsl:element>
      </xsl:for-each>        
   <xsl:message terminate="no">
        Accessing wiki2 
      </xsl:message>
  
 </xsl:template>

  <xsl:template name="get-rss">
    <xsl:param name="title"/>
     <div id="hiddenSource">

     </div>
</xsl:template>

  <xsl:template name="get-wiki">
    <xsl:param name="title"/>
  <xsl:variable name="wiki-result-new" select="document($wikiNew)"/>
  
    <xsl:for-each select="$wiki-result-new">
         <xsl:apply-templates />
       </xsl:for-each>
    
  </xsl:template>

 <xsl:template match="rss:title">
 &lt;!---------title------------&gt;
  <xsl:call-template name="six-pack-plus">
        <xsl:with-param name="search-term" select="."/>
      </xsl:call-template>
      <xsl:apply-templates />
 </xsl:template>

 <xsl:template match="rss:items">
  		<xsl:apply-templates/>
 &lt;!--------item-------------&gt;
	  <xsl:call-template name="six-pack-plus">
        <xsl:with-param name="search-term" select="."/>
      </xsl:call-template>	
                      <!--   <xsl:value-of select="scripts:showXML(.)"/>  -->
                      
 
	    
  </xsl:template>
  <xsl:template match="html:*">
	     <xsl:element name="BR">
                           &lt;<xsl:value-of select="name()"/>&gt;<xsl:value-of select="text()"/>
                            <xsl:apply-templates />
                           &lt;/<xsl:value-of select="name()"/>&gt;
                       </xsl:element>
  </xsl:template>

  <xsl:template match="html:head|html:br|html:meta">
	 
  </xsl:template>
  <xsl:template match="html:html|html:body">
	 <xsl:apply-templates />
  </xsl:template>
  <xsl:template match="html:img">
	     <xsl:element name="img">
	        <xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>   
                         <xsl:attribute name="border"><xsl:value-of select="@border"/></xsl:attribute>   
                         <xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>   
                         
                       </xsl:element>
  </xsl:template>
  <xsl:template match="html:input">
	     <xsl:element name="input">
	        <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>   
                           <xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute>   
	         <xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute>        
                       </xsl:element>
  </xsl:template>
  <xsl:template match="html:form">
	     <xsl:element name="form">
                           <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> 
		<xsl:attribute name="action"><xsl:value-of select="@action"/></xsl:attribute> 
     		<xsl:attribute name="method"><xsl:value-of select="@method"/></xsl:attribute> 
       
                       
	         <xsl:apply-templates />    
                       </xsl:element>
          <td colspan="2">
                Main . {  <a href="http://twiki.org/cgi-bin/view/Main/TWikiUsers">Users</a>  |  <a href="http://twiki.org/cgi-bin/view/Main/TWikiGroups">Groups</a>  |  <a href="http://twiki.org/cgi-bin/view/Main/OfficeLocations">Offices</a>  |  <a href="http://twiki.org/cgi-bin/changes/Main" target="_top">Changes</a> (<a href="http://twiki.org/cgi-bin/view/Main/WebChanges">detailed</a>)  |  <a href="http://twiki.org/cgi-bin/view/Main/WebIndex">Index</a>  |  <a href="http://twiki.org/cgi-bin/view/Main/WebSearch">Search</a>  |  Go <input type="text" name="topic" size="16" />  }
          </td>
  </xsl:template>


<!--
Text Area is the post back content, compound access if web is inside this template(for return to TWiki)
-->

  <xsl:template match="h1|h2">
      <b> found rdf tag</b>
  </xsl:template>

  <xsl:template match="html:table">
   <div style="overflow-y:auto;overflow-x:auto;height:50;width:98%;">
		
        <xsl:element name="table">
	       <xsl:attribute name="border">2</xsl:attribute>
        	<xsl:attribute name="width">700</xsl:attribute>
<xsl:attribute name="width">100%</xsl:attribute>
        	<xsl:attribute name="cellpadding">2</xsl:attribute>
        	<xsl:attribute name="cellspacing">2</xsl:attribute>
        	<xsl:attribute name="bgcolor">#4c0582</xsl:attribute>
                          <xsl:apply-templates />    
           </xsl:element>   
       </div>
  </xsl:template>

<xsl:template match="html:tr">
	     <xsl:element name="tr">
                          <xsl:attribute name="bgcolor"><xsl:value-of select="@bgcolor"/></xsl:attribute>   
                         
                          <xsl:apply-templates />    
                       </xsl:element>
  </xsl:template>
<xsl:template match="html:td">
	     <xsl:element name="td">
                            <xsl:attribute name="colspan"><xsl:value-of select="@colspan"/></xsl:attribute>   
    		<xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute> 
		<xsl:attribute name="valign"><xsl:value-of select="@valign"/></xsl:attribute>     
    		<xsl:attribute name="width"><xsl:value-of select="@width"/></xsl:attribute>   
    
                          <xsl:apply-templates />    
                       </xsl:element>
  </xsl:template>
<xsl:template match="html:font">
	     <xsl:element name="font">
                            <xsl:attribute name="size"><xsl:value-of select="@size"/></xsl:attribute>   
    		
                          <xsl:apply-templates />    
                       </xsl:element>
  </xsl:template>
<xsl:template match="html:script">
	     <xsl:element name="BR">
                           &lt;<xsl:value-of select="name()"/>&gt;
		<xsl:value-of select="text()"/>
                           
                           &lt;/<xsl:value-of select="name()"/>&gt;
                       </xsl:element>
  </xsl:template>
  <xsl:template match="html:b">
	     <xsl:element name="b">	
		
                          <xsl:value-of select="text()"/> 
                       </xsl:element>
  </xsl:template>

  <xsl:template match="html:a">
	     <xsl:element name="a">	
		<xsl:attribute name="href"><xsl:value-of select="$wikiMain"/><xsl:value-of select="@href"/></xsl:attribute> 
		<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> 
		
                          <xsl:value-of select="text()"/> 
                       </xsl:element>
  </xsl:template>

 <msxsl:script implements-prefix="scripts" > 

   <![CDATA[ 
      var WikiNameRegexp = "/(?<![A-Za-z0-9])([A-Z][a-z]+){2,}(?![A-Za-z0-9])";
      var g_obj = new Array();
      var parts;
      var seqTextArea = 0;
             function tget(p){ 
             return parts[p];
}
          function tname(ctx){ 
          var tmp;
	seqTextArea++;
           if(seqTextArea == 1) return "old";
           return "new";
}
          function findTopics(ctx){ 
          var tmp;
          var tmp2;
         // var idVal = ctx.getAttribute("id");

          var replaceText = ctx.nextNode().text;
         replaceText = replaceText.replace(WikiNameRegexp, '%ICON{"xml"}% ');
var tdom = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");// THIS LINE MAKE CODE IE DEPENDANT
           var od = tdom.createNode(1, 'myRE', '');
              parts = replaceText.split('---++++++');
	if (parts  != null){
		//
		for (var i=1; i < parts.length; i++){
			//window.status =window.status + parts[i];
			tmp=parts[i].split('/n');

			var mn = tdom.createNode(1, 'h2', '');
			var tn = tdom.createTextNode(tmp[1]);
			mn = od.appendChild(mn);
			tn = mn.appendChild(tn);
			mn = tdom.createNode(1, 'h1', '');
			var tn = tdom.createTextNode(tmp[0]);
			mn = od.appendChild(mn);
			tn = mn.appendChild(tn);
			g_obj[i] = tmp[0];
		}
		//
    for (var i=1; i < g_obj.length; i++){
	//window.status =window.status + parts[i];
	tmp2=tmp2 + ' ' +g_obj[i]; 

           }
                                     mn = tdom.createNode(1, 'h1', '');
		var tn = tdom.createTextNode(tmp2);
		mn = od.appendChild(mn);
		tn = mn.appendChild(tn);
		
		return od.selectNodes("*");
	}
}
function topicGroup(ctx){ 
          var tmp='';
          var st='';
          var replaceText = ctx.nextNode().text;
         replaceText = replaceText.replace(WikiNameRegexp, '%ICON{"xml"}% ');
          for (var i=1; i < g_obj.length; i++){
	//window.status =window.status + parts[i];
	tmp=tmp + ' ' +g_obj[i]; 

           }
           tmp = tmp.replace('/n ', ' ');
           tmp = tmp.replace('/n ', ' ');
      tmp = tmp.replace('          ', ' ');
           tmp = tmp.replace('    ', ' ');
           tmp = tmp.replace('     ', ' ');
           tmp = tmp.replace('  ', ' ');
           return tmp;
}

 
function   _wander(ctx){
	var retStr = "";
	for (var i=0; i < ctx.childNodes.length; i++){
		ctxN = ctx.childNodes[i];
		switch(ctxN.nodeType){
			case 1:
				retStr +=   _wander(ctxN);
				break;
			case 3:
				retStr += ctxN.nodeValue;
				break;
			default:
				break;
		}
	}
	return retStr;
}
    function showXML(nodelist)
           {
           txtResult = "<SPAN "+
               "STYLE='background-color:lightyellow;" +
               "cursor:hand;font-size:8pt;' " +
               "TITLE='"
           replaceText = nodelist.nextNode().xml
           replaceText = replaceText.replace(/&/g, '&amp;')
           replaceText = replaceText.replace(/</g, '&lt;')
           replaceText = replaceText.replace(/>/g, '&gt;')
           replaceText = replaceText.replace(/'/g, '&rsquo;')
           txtResult += replaceText
           txtResult += "'>(show xml)</SPAN>"
           return txtResult;
           }
  function findItems(nodelist)
           {
        
           var replaceText = nodelist.nextNode().xml;
            replaceText = replaceText.replace(WikiNameRegexp, '%ICON{"xsl"}% ');
           replaceText = replaceText.replace(/ ---/g, '%ICON{"xml"}% ');
     
         
           return replaceText;
           }


  ]]> 

</msxsl:script>
  <xsl:template match="html:textarea">
                       <xsl:variable name="textAreaId" select="scripts:tname(.)"/>

	     <xsl:element name="textarea"><!--NEED TO TEST FOR CORRECT TEXT AREA-->
		<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> 
		<xsl:attribute name="wrap"><xsl:value-of select="@wrap"/></xsl:attribute> 
                                    <xsl:attribute name="rows">20</xsl:attribute>
 		<xsl:attribute name="cols">70</xsl:attribute>
		<xsl:attribute name="id"><xsl:value-of select="$textAreaId"/></xsl:attribute>
                                    <xsl:attribute name="onload">moveText(this)</xsl:attribute>
  <xsl:variable name="wiki-result" select="document($RSSuri)"/>
  
          <xsl:for-each select="$wiki-result">
          

	
		  <xsl:for-each select="//rss:item"> 
---+++<xsl:value-of select="rss:title"/>    <xsl:value-of select="rss:link"/>    <xsl:text>
			</xsl:text><xsl:value-of select="/rss:description"/>    <xsl:text>
			</xsl:text><xsl:value-of select="/rdf:about"/>    <xsl:text>
 &lt;!---------related topics on Google------------&gt;</xsl:text>
  <xsl:call-template name="two-for-wiki">
        <xsl:with-param name="search-term" select="rss:title"/>
      </xsl:call-template>
		</xsl:for-each>
                 
		
                      <!--   <xsl:value-of select="scripts:showXML(.)"/>  -->
                      </xsl:for-each> 
 
                       </xsl:element>
	    
  </xsl:template>

</xsl:stylesheet>
