Share via


Figure 3

Extended XML

  
<PERSON>
    <NAME>Jane Finance</NAME>
    <TITLE>Chief Financial Officer</TITLE>
    <CERTIFICATION>CA</CERTIFICATION>
    <DEGREE>Bachelor</DEGREE>
    <DEGREE>Master</DEGREE>
    <PUBLICATION>USA Today</PUBLICATION>
</PERSON>
<PERSON>
    <NAME>Tom Tech</NAME>
    <TITLE>Technology Officer</TITLE>
    <DEGREE>Bachelor</DEGREE>
    <PUBLICATION>MIND</PUBLICATION>
    <PEOPLE>
•••

Figure 5

Pattern Matching in Action

  
function cmdSearch_onclick() 
{
var strPattern = "//PERSON";
if (chkManual.checked)
strPattern = txtManual.value;
else
{    
    if (chkCertification.checked)
(txtCertification.value.length == 0) ? strPattern += "[CERTIFICATION]" : strPattern += "[CERTIFICATION = '" + txtCertification.value + "']";
    if (chkDegree.checked)
(txtDegree.value.length == 0) ? strPattern += "[DEGREE]" : strPattern += "[DEGREE = '" + txtDegree.value + "']";
    if (chkPublication.checked)
(txtPublication.value.length == 0) ? strPattern += "[PUBLICATION]" : strPattern += "[PUBLICATION = '" + txtPublication.value + "']";
    txtManual.value = strPattern;
 }            

 //Unhighlight all spans
 var objSpans = document.getElementsByTagName("SPAN");
 for (var i=0; i< objSpans.length; i++)
    objSpans(i).style.color = "black";

 //Select matched nodes and highlight
 var objCol = infoxml.selectNodes(strPattern + "/@ID");
 for (var i=0; i< objCol.length; i++)    
    document.all(objCol(i).text).style.color = "blue";
}Support for Re-orgs!

Figure 6

MovePerson

  
function MovePerson(SourceID, DestinationID)
{
var strSearchString
var objSource, objDest
        
if (SourceID == DestinationID) {
  alert("You cannot move a person onto themselves.");
  ReloadEdit();
  ReloadOrgChart();
  return;
}
                
// find the source node
strSearchString = ".//PERSON[@ID = '" + SourceID + "']";
objSource = infoxml.selectSingleNode(strSearchString);
            
// find the destination node
if (DestinationID=="TOP")
{
  objDest = infoxml.selectSingleNode("CLIENT"); 
// top level reference
}
else
{        
  strSearchString = ".//PERSON[@ID = '" + DestinationID + "']";
  objDest = infoxml.selectSingleNode(strSearchString);
}

// Remove the node from the source
objSource.parentNode.removeChild(objSource);
        
// And add it to the destination person
AddPersonToPeople(objDest, objSource);
        
// Reload
ReloadEdit();
ReloadOrgChart();
}

Figure 7

AddPersonToPeople

  
function AddPersonToPeople(objPerson, objNewNode)
{
  try
  {
  // add to the people collection
  objPerson.selectNodes("PEOPLE")(0).appendChild(objNewNode);
  }
  catch (e)
  {
  // if that failed, then there is no people collection, so 
  // create one
  var newPeople;
  var newtree;

  newPeople = 
      objPerson.ownerDocument.createNode(1,"PEOPLE","");
  newtree = objPerson.appendChild(newPeople);
  newtree.appendChild(objNewNode);
  }
}

Figure 9

XSL Person Template

  
<xsl:template match="PERSON/(NAME | TITLE)">
    <TR>
        <TD CLASS="clsColumn1">
<xsl:eval>GetNodeNameProper()</xsl:eval>
</TD>
        <TD CLASS="clsColumn2">
            <xsl:element name="INPUT">
                <xsl:attribute name="ID">
                <xsl:eval>GetNodeName()</xsl:eval>
                <xsl:value-of select="@ID"/>
                </xsl:attribute>
                <xsl:attribute name="VALUE">
                <xsl:value-of select="."/>
                </xsl:attribute>
                <xsl:attribute name="ONCHANGE">
                infoxml.selectSingleNode(".//*[@ID ='
                <xsl:value-of select="@ID"/>']").text =                
                <xsl:eval>GetNodeName()</xsl:eval>
                <xsl:value-of select="@ID"/>.value;
                </xsl:attribute>    
            </xsl:element>
        </TD>
    </TR>            
</xsl:template>

Figure 10

AddPerson Method

  
function AddPerson(strID) 
{
    var objNew, objPerson, oXSL, strName, strSearchString
    var strName = window.prompt("Name:","");
            
    // make sure the name  is unique
    objPerson = infoxml.selectSingleNode("CLIENT/PEOPLE//
    PERSON[NAME= '" + strName + "']");
            
    if (objPerson!=null) {
        alert("No two people can have the same name in a 
        company!");
        return;
    }
            
    //find the parent node to attach the new person
    strSearchString = ".//PERSON[@ID = '" + strID + "']";
    objPerson = infoxml.selectSingleNode(strSearchString);
            
    // make a copy of the node (this will become the new 
    // person)
    objNew = objPerson.cloneNode(true);

    try
    {
        // remove a people node from the clone, if there is one
        objNew.removeChild(objNew.selectNodes("PEOPLE").item(0));
    }
    catch(e)
    {
    }
            
    // erase the contents of the clone
    for(var i=0;i<objNew.childNodes.length;i++) {
        objNew.childNodes(i).text = "";
    }
            
    // set the first and last name for the person
    objNew.selectNodes("NAME")(0).text = strName;

    AddPersonToPeople(objPerson, objNew);
                    
    ReloadEdit();
    ReloadOrgChart();        
}

Figure 11

SaveXML and removeIndexXML Methods

  
function SaveXML() 
{  
    var objhttp = new ActiveXObject("Microsoft.XMLHTTP");

    objhttp.Open("POST",strSitename + "/Sales/
        savexml.asp?company=" + strCompany, false);
    // strip off ID attribute
    removeIndexXML(infoxml);
    
    objhttp.send(infoxml.XMLDocument);
    
    if (objhttp.responseText!="")
        alert(objhttp.responseText);
    else
        alert("Save successful.");
}

function removeIndexXML(XML)
{
    var objCol = XML.getElementsByTagName("*");
    for (var i=0; i< objCol.length; i++)    
        objCol(i).attributes.removeNamedItem("ID");
}