Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript and XML round 2

    I am using javascript to display a menu that is pulled from an xml document and sorted alphabetically using xslt. I want to be able to click on a link and display the data on a different <div> on the webpage. The script I have to display the information is:
    Code:
    function show(i)
    {
    
    title=(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
    body=(x[i].getElementsByTagName("body")[0].childNodes[0].nodeValue);
    
    txt= "<center><h2>" + title + "</h2></center><br />" + body;
    
    document.getElementById("mainbdy").innerHTML=txt;
    document.getElementById("subnav").style.visibility='hidden';
    return false;
    }
    the only problem is when I click on a link from my sorted list that isn't originally in the XML document alphabetically, it displays the information in that location of the XML page. I was hoping I could just use a different item other than "i" to choose which part of the XML document to display. Each item has a unique <name> tag. Is it possible to get the information using some variable associated to <name> rather than "i"?

  • #2
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok. I haven't been able to find any new information for the above problem so I'll try to attack it from a different angle.

    I have the following code that will import an xsl file to sort and display some data in an xml document:

    Code:
    function loadXMLDoc(fname)
    {
    var NewxmlDoc;
    // code for IE
    if (window.ActiveXObject)
      {
      NewxmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation 
    && document.implementation.createDocument)
      {
      NewxmlDoc=document.implementation.createDocument("","",null);
      }
    else
      {
      alert('Your browser cannot handle this script');
      }
    NewxmlDoc.async=false;
    NewxmlDoc.load(fname);
    return(NewxmlDoc);
    }
    
    function displayResult()
    {
    xml=loadXMLDoc("support_docs.xml");
    xsl=loadXMLDoc("support_docs.xsl");
    // code for IE
    if (window.ActiveXObject)
      {
      ex=xml.transformNode(xsl);
      document.getElementById("articlestuff").innerHTML=ex;
      }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation 
    && document.implementation.createDocument)
      {
      xsltProcessor=new XSLTProcessor();
      xsltProcessor.importStylesheet(xsl);
      resultDocument = xsltProcessor.transformToFragment(xml,document);
      document.getElementById("articlestuff").appendChild(resultDocument);
      }
    
    }
    Here is the code for the xsl stylesheet:

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    
    
    <xsl:template match="/">
    		<ul id="subnav">
    	        <xsl:for-each select="help_articles/support_doc">
    
    			<xsl:sort select="header" />
          <li>
    		<a href="javascript://" onclick="show({position()-1})">
    		<xsl:value-of select="header" />
    		</a>
          </li>
          </xsl:for-each>
    		</ul>
    </xsl:template>
    
    </xsl:stylesheet>
    Is it possible to add a template to the end of this stylesheet and create a new script that will call just that template, or am I just going to have to create a completely separate stylesheet?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •