<?xml version="1.0" encoding="utf-8" ?>
<!-- XSL programming environment for TWiki.                                      -->

<!--  -->
<!-- known problems:-->

<!-- 
    This is alpha code of a compact XML manipulation tool. 
    Copyright (c) 2003 Forth Party software
    Please send comments to: JCoe18@excite.com

-->
<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:fo="http://www.w3.org/1999/XSL/Format"
      xmlns:scripts ="http://architag.com/scripts" 
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:rss="http://purl.org/rss/1.0/" 
      xmlns:wiki="http://purl.org/rss/1.0/modules/wiki/"
      xmlns:html="http://www.w3.org/1999/xhtml"
     xmlns:xlink="http://www.w3.org/1999/xlink"> 
  <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" omit-xml-declaration="yes"
      doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
      doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
     />

<!-- Clipboard access to content will promote one-off environment-->
<!-- 
    This is alpha code of a compact XML manipulation tool. 
    Copyright (c) 2003 Forth Party software
    Please send comments to: JCoe18@excite.com

-->
  <xsl:include href="..\XslWiki\amazon.xsl"/>
  <xsl:include href="google.xsl"/>
  <xsl:include href="..\XslWiki\uddi.xsl"/>
  <xsl:include href="RSSwiki.xsl"/>
  <xsl:include href="..\XslWiki\foaf.xsl"/>

	
<!-- Display width (pixels) -->
<xsl:variable name="display-width" select="'700'"/>

<!-- Background color (#rgb) -->
<xsl:variable name="background-color" select="'#D0F0D0'"/>

<!-- Use table separator (yes/no) -->
<xsl:variable name="use-table-separator" select="'yes'"/>

<!-- Use record separator (yes/no) -->
<xsl:variable name="use-record-separator" select="'no'"/>


<!--
**
**   Description :  HTML Treeview
**
*   Updates :
** 
-->
	
<!-- Change the encoding here if you need it, i.e. UTF-8 -->
	<xsl:output method="html" encoding="iso-8859-1" indent="yes"/>
	 
	<!-- ************************************ Parameters ************************************ -->
	<!-- deploy-treeview, boolean - true if you want to deploy the tree-view at the first print -->
	<xsl:param name="param-deploy-treeview" select="'false'"/>
	
	<!-- is the client Netscape / Mozilla or Internet Explorer. Thanks to Bill, 90% of sheeps use Internet Explorer so it will the default value-->	
	<xsl:param name="param-is-netscape" select="'false'"/>

	<!-- hozizontale distance in pixels between a folder and its leaves -->
	<xsl:param name="param-shift-width" select="15"/>
	
	<!-- image source directory-->
	<xsl:param name="param-img-directory" select="'..\XslClient\'"/>
	
	<!-- ************************************ Variables ************************************ -->
	<xsl:variable name="var-simple-quote">'</xsl:variable>
	<xsl:variable name="var-slash-quote">\'</xsl:variable>
 <msxsl:script implements-prefix="scripts" language="JavaScript1.2" > 

   <![CDATA[ 
//      var WikiNameRegexp = '^([A-Za-z0-9])([A-Z][a-z]+){2,}(?![A-Za-z0-9])';
      var g_obj = new Array();
      var wikiNS = 'http://twiki.org/cgi-bin/view/';
      var wikiBranch = 'Main/';
      var parts;
      var seqTextArea = 0;
      var constituentFolders = new Array();

//     SET_DHTML(CURSOR_MOVE, RESIZABLE, NO_ALT, SCROLL, "alligator", "bluelyr", "button"+VERTICAL+HORIZONTAL+CURSOR_DEFAULT, "cat", "chameleon", "counter", "greylyr", "koala", "leop", "low", "muckl"+COPY+4, "newresiz", "prdog", "reldiv", "reldivn4", "reltab", "slidercanvas", "smile1", "smile2"+SCALABLE, "thumb"+HORIZONTAL+MAXOFFLEFT+45+MAXOFFRIGHT+45, "track"+NO_DRAG, "upleft");

      //constituentFolders=currentURL.split("/"); 

             function tget(p){ 
             return parts[p];
}
function getLoc() { return history.length;}
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++){
		   
                                         
		     tmp2 = parts[i].split(']');
		    
		     if(tmp2.length > 1)
                                         {    tmp=tmp2[1].indexOf(']');
		         var tmp3 =  tmp2[1].substring(1,tmp);
			 tmp2[0].replace(/%ATTACHURL%/g, wikiNS + wikiBranch );
                                                   var mn = tdom.createNode(1, 'h2', '');
			var tn = tdom.createTextNode("bb"+tmp3);
			mn = od.appendChild(mn);
			tn = mn.appendChild(tn);
			mn = tdom.createNode(1, 'h1', '');
			var tn = tdom.createTextNode(tmp2[0]);
			mn = od.appendChild(mn);
			tn = mn.appendChild(tn);
                                          //   count = count + 1;
		     }

		}
                  }
              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;
           }



//Thus we have the complete code for our simple breadcrumb trail in Javascript as follows : 
function buildDepth(iterations)
{
    var iterations=iterations-3;
    var depthStr="";
    for (i=0;i<iterations;i++)
    {
        depthStr=depthStr + "../";
    }
    return depthStr;
}

function buildBreadCrumbTrail(currentURL)
{
    var constituentFolders = new Array();
  var outputStr="";   
var tdom = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");// THIS LINE MAKE CODE IE DEPENDANT
           var od = tdom.createNode(1, 'a', '');

   // constituentFolders=currentURL.split("/");
 
  //  for (count=2;count<(constituentFolders.length-1);count++)
  //  {
       // outputStr=outputStr + " : <a href='" + buildDepth((constituentFolders.length-count)+1) + "WebHome'>" + constituentFolders[count] + "</a>";
////    }
        mn = tdom.createNode(1, 'h1', '');
		var tn = tdom.createTextNode("test");
		mn = od.appendChild(mn);
		tn = mn.appendChild(tn);
		
		return od.selectNodes("*");
} 
  ]]> 

</msxsl:script>	
<!--
**
**  Model "treeview"
** 
**  This model transforms an XML treeview into an html treeview
**  
-->
	<xsl:template match="/treeview|/rdf:RDF|/rdf:rdf">
		<!-- -->
		<link rel="stylesheet" href="treeview.css" type="text/css"/>
<!--
Version: <xsl:value-of select="system-property('xsl:version')" />
<br />
Vendor: <xsl:value-of select="system-property('xsl:vendor')" />
<br />
Vendor URL: <xsl:value-of select="system-property('xsl:vendor-url')" />

		-->
		<script src="jisirc.js" language="javascript" type="text/javascript"></script>
		<script src="wz_dragdrop.js" language="javascript" type="text/javascript"></script>
		<script src="WikiView.js" language="javascript" type="text/javascript"></script>
<input type="text" name="irc" size="31" maxlength="255" value="" onclick=' irc_send()' />	

	
		<table border="1" cellspacing="0" cellpadding="0">
		  	<tr><td>
		  		<!-- Apply the template folder starting with a depth in the tree of 1-->
				<xsl:apply-templates select="folder|rss:ITEM|rss:item">
					<xsl:with-param name="depth" select="1"/>
				</xsl:apply-templates>
			</td></tr>
		 </table>
		         <title>////<xsl:value-of select="contenttype"/>\\\\</title>
<form method="get" action="http://www.google.com/search">
  <input type="text" name="q" size="31" maxlength="255" value="" /> 
  <input type="hidden" name="domains" value="twiki.org" /> 
  <input type="hidden" name="sitesearch" value="twiki.org" /> 
  <input type="submit" name="btnG1" value="Google Search twiki.org" />
</form>
         <a name="PageTop"></a>
 <!--     
          <xsl:call-template name="get-rss"><xsl:with-param name="title" select="."/>
           </xsl:call-template>
           <xsl:call-template name="get-wiki"><xsl:with-param name="title" select="."/>
       </xsl:call-template>
       <xsl:apply-templates/>
      <xsl:call-template name="makeForms"><xsl:with-param name="title" select="."/>
      </xsl:call-template>
      
End of page ,
-->
        <a name="PageBottom"></a>		
</xsl:template>
  <!-- include reference to document containing the developer's keys -->
 
  <xsl:include href="../XslClient/form.xsl"/>
<!--
**
**  Model "folder"
** 
**  This model transforms a folder element. Prints a plus (+) or minus (-)  image, the folder image and a title
**  
-->
<xsl:template match="folder|rss:ITEM|rss:item">
	<xsl:param name="depth"/>
	<table border="1" cellspacing="0" cellpadding="0">
  		<tr>
  			<!-- If first level of depth, do not shift of $param-shift-width-->
  			<xsl:if test="$depth>1">
  				<td width="{$param-shift-width}"></td>
  			</xsl:if>
	  			
  			<td><xsl:apply-templates select="form">
					</xsl:apply-templates>
  				<a class="folder">
				<xsl:attribute name="onclick">toggle2(this, '<xsl:value-of select="@rdf:about"/>')</xsl:attribute>
				
  				<!-- If the treeview is unfold, the image minus (-) is displayed-->
				<xsl:if test="@expanded">
					<xsl:if test="@expanded='true'">
  						<img src="{$param-img-directory}minus.gif"/>
  					</xsl:if>
	  				<!-- plus (+) otherwise-->
					<xsl:if test="@expanded='false'">
						<img src="{$param-img-directory}plus.gif"/>
	  				</xsl:if>
				</xsl:if>
				<xsl:if test="not(@expanded)">
					<xsl:if test="$param-deploy-treeview = 'true'">
						<img src="{$param-img-directory}minus.gif"/>
					</xsl:if>
					
					<xsl:if test="$param-deploy-treeview = 'false' or not(@expanded)">
						<img src="{$param-img-directory}plus.gif"/>
					</xsl:if>
				</xsl:if>
				<xsl:if test="@img">
  				    <img src="{$param-img-directory}{@img}">
  					<!-- if the attribut alt is present-->
					<xsl:if test="@alt">
						<!-- if Netscape / Mozilla -->
						<xsl:if test="$param-is-netscape='true'">
							<xsl:attribute name="title"><xsl:value-of select="@alt"/></xsl:attribute>
						</xsl:if>
						<!-- if Internet Explorer -->
						<xsl:if test="$param-is-netscape='false'">
							<xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
						</xsl:if>								
					</xsl:if>
  				    </img>
				</xsl:if>
  				<xsl:value-of select="@title"/></a>
				<xsl:value-of select="@wiki:version"/>
<xsl:value-of select="@rdf:about"/>
   <!--    <xsl:eval select="scripts:buildBreadCrumbTrail(@rdf:about)"> 
                                  	          

		              
                                        </xsl:eval>        -->
				<!-- Shall we expand all the leaves of the treeview ? no by default-->
				<div>
					<xsl:if test="@expanded">
						<xsl:if test="@expanded='true'">
	  						<xsl:attribute name="style">display:block;color:blue;</xsl:attribute>
	  					</xsl:if>
		  				<!-- plus (+) otherwise-->
						<xsl:if test="@expanded='false'">
							<xsl:attribute name="style">display:none;color:pink;</xsl:attribute>
		  				</xsl:if>
					</xsl:if>
						
					<xsl:if test="not(@expanded)">
						<xsl:if test="$param-deploy-treeview = 'true'">
							<xsl:attribute name="style">display:block;color:red;</xsl:attribute>						
						</xsl:if>
													
						<xsl:if test="$param-deploy-treeview = 'false'">
							<xsl:attribute name="style">display:none;color:yellow;</xsl:attribute>
						</xsl:if>
					</xsl:if>						
					<xsl:if test="@wiki"> 
   				 <xsl:call-template name="RssFindCache">
       				 <xsl:with-param name="search-term"> <xsl:value-of select = "$RssCache"/>  <xsl:value-of select = "@wiki"/> </xsl:with-param>
      				</xsl:call-template>
					</xsl:if>
					<!-- Thanks to the magic of reccursive calls, all the descendants of the present folder are gonna be built -->
  					<xsl:apply-templates select="folder">
						<xsl:with-param name="depth" select="$depth+1"/>
					</xsl:apply-templates>
						
					<!-- print all the leaves of this folder-->
  					<xsl:apply-templates select="leaf"/>
				</div>
  			</td>
  		</tr>
  	</table>
	  	
</xsl:template>
	
<!--
**
**  Model "leaf"
** 
**  This model prints an image plus the name of the element
**  
-->
<xsl:template match="leaf">
	<table border="0" cellspacing="0" cellpadding="0">
		<tr> <td width="{$param-shift-width}"></td> 
			<td>
				<a class="leaf">
					<!-- The line is very long bu I have no choice, I called the function replace-string to replace the quotes (') by /' -->
					<xsl:attribute name="onclick">selectLeaf('<xsl:call-template name="replace-string"><xsl:with-param name="text" select="@title"/><xsl:with-param name="from" select="$var-simple-quote"/><xsl:with-param name="to" select="$var-slash-quote"/></xsl:call-template>','<xsl:call-template name="replace-string"><xsl:with-param name="text" select="@code"/><xsl:with-param name="from" select="$var-simple-quote"/><xsl:with-param name="to" select="$var-slash-quote"/></xsl:call-template>')</xsl:attribute>						
					<!-- if it is the last leaf, print a different image for the link to the folder-->
					<xsl:choose>
						<xsl:when test="position()=last()">
							<img src="{$param-img-directory}lastlink.gif"/>
						</xsl:when>
						<xsl:otherwise>
							<img src="{$param-img-directory}link.gif"/>
						</xsl:otherwise>
					</xsl:choose>
					
					<img src="{$param-img-directory}{@img}">
						<!-- if the attribut alt is present-->
						<xsl:if test="@alt">
							<!-- if Netscape / Mozilla -->
							<xsl:if test="$param-is-netscape='true'">
								<xsl:attribute name="title"><xsl:value-of select="@alt"/></xsl:attribute>
							</xsl:if>
							<!-- if Internet Explorer -->
							<xsl:if test="$param-is-netscape='false'">
								<xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
							</xsl:if>								
						</xsl:if>
					</img>

					<xsl:value-of select="@title"/>
					<xsl:if test="@wiki">test 
						<xsl:variable name="fname"> <xsl:value-of select = "@wiki"/></xsl:variable>
   				 		<xsl:call-template name="get-wiki">
      						 <xsl:with-param name="search-term"><xsl:value-of select = "@wiki"/></xsl:with-param>
      						</xsl:call-template>
					</xsl:if>
				</a>
			</td>
		</tr>
	</table>
</xsl:template>
	
<!--
**
**  Model "replace-string"
** 
**  reusable replace-string function **  
-->
	<xsl:template name="replace-string">
		<xsl:param name="text"/>
		<xsl:param name="from"/>
		<xsl:param name="to"/>
		<xsl:choose>
			<xsl:when test="contains($text, $from)">
				<xsl:variable name="before" select="substring-before($text, $from)"/>
				<xsl:variable name="after" select="substring-after($text, $from)"/>
				<xsl:variable name="prefix" select="concat($before, $to)"/>
				<xsl:value-of select="$before"/>
				<xsl:value-of select="$to"/>
				<xsl:call-template name="replace-string">
					<xsl:with-param name="text" select="$after"/>
					<xsl:with-param name="from" select="$from"/>
					<xsl:with-param name="to" select="$to"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$text"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	
</xsl:stylesheet>




