WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Recursive XSL, Hakan Bilgin, February 2, 2005
     Re:Recursive XSL, Hakan Bilgin, February 3, 2005
         Re:Recursive XSL, Micah Goulart, February 4, 2005

Subject: Re:Recursive XSL From: Hakan Bilgin Date: February 3, 2005

A small update:

<html xmlns:hbi>
<style type="text/css">

.xEl  {padding-left: 16px; height: 16px; color: #0000FF; font: 14px Trebuchet MS;}
.xEl .ns  {color: #FF0000;}
.xEl .cmnt {color: #888888; border: 0px;}
.xEl pre {color: #000000; cursor: text; font-family: Courier; margin: 2px 0px 2px 10px; padding-left: 5px; border-left: #CCCCCC 1px solid;}
.xEl u  {color: #FF0000; text-decoration: none; width: 16px; margin-left: -16px; padding-left: 2px;}
.xEl i  {color: #990000; font-style: normal;}
.xEl a  {color: #000000; font-weight: bold;}

<script language="Javascript">
// DOM Controlled by Hakan Bilgin © 1996-2005

function getParent(el, a, v) {
 while (el.getAttribute(a) != v) {
  if (el.parentElement == null) return null;
  el = el.parentElement;
 return el;

function doCmd(cmd) {
 switch (cmd) {
  case 'ParseXml':
   if (xDoc.readyState != 'complete') return;
   xAttr = xDoc.firstChild.attributes;
   xStr = '<div class="xEl">&lt;?xml ';
   for (j=0; j<xAttr.length; j++) xStr += xAttr[j].name +'="'+ xAttr[j].value +'" ';
   xStr += ' ?&gt;</div>'+ xDoc.documentElement.transformNode(xSorter.XMLDocument);
   document.body.insertAdjacentHTML('beforeEnd', xStr);
  case 'ClickNode':
   srcEl = event.srcElement;
   if (srcEl.currentStyle.cursor != 'hand') return;
   srcRt = getParent(srcEl, 'className', 'xEl');
   ind = srcRt.all.tags('U')[0];
   if (srcRt.children[1].tagName == 'PRE') srcRt.children[1].style.display = (ind.innerText == '-')? 'none' : 'block' ;
   else srcRt.style.overflow = (ind.innerText == '-')? 'hidden' : 'visible' ;
   ind.innerText = (ind.innerText == '-')? '+' : '-' ;

<body onclick="doCmd('ClickNode');">

<xml id="xSorter">
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <xsl:template match=".">
    <xsl:for-each select=".">
   <div class="xEl"><span>
    <xsl:choose><xsl:when expr="hasChildNodes"><xsl:attribute name="style">cursor: hand;</xsl:attribute></xsl:when></xsl:choose>
    <u><xsl:choose><xsl:when expr="hasChildNodes">-</xsl:when><xsl:otherwise>&#160;</xsl:otherwise></xsl:choose>
    <xsl:apply-templates select="@*"/></span>
     <xsl:when expr="hasChildNodes">&gt;
      <xsl:apply-templates select="text()"/>
      <xsl:apply-templates select="comment()"/>
      <xsl:apply-templates select="./*"/>
  <xsl:template match="text()"><a><xsl:value-of/></a><xsl:apply-templates select="cdata()"/></xsl:template>
  <xsl:template match="@*"><i><xsl:eval>nodename</xsl:eval></i>="<a><xsl:if expr="nodename.indexOf('xmlns')>-1"><xsl:attribute name="class">ns</xsl:attribute></xsl:if><xsl:value-of/></a>" </xsl:template>
  <xsl:template match="cdata()"><div class="xEl"><span style="cursor: hand;"><u>-</u>&lt;![CDATA[</span><pre><xsl:value-of/></pre>&#160;]]&gt;</div></xsl:template>
  <xsl:template match="comment()"><div class="xEl"><span style="cursor: hand;"><u>-</u>&lt;!--</span><pre class="cmnt"><xsl:value-of/></pre>&#160;--&gt;</div></xsl:template>

<xml id="xDoc" src="http://www.challenger.se/test.xml" onreadystatechange="doCmd('ParseXml');"></xml>



Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.

View All Messages
Back to WebFX