Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7777363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:07:24+00:00 2026-06-01T18:07:24+00:00

Ive noticed if i try to apply changed to a XSL file through java

  • 0

Ive noticed if i try to apply changed to a XSL file through java script it only affects the top most node created by the XSL.

Example:
I want to hide all the comments of multiple blog entries. Result only the top blog entry will hide the comments.

I want to change the text of a hyper link. The hyperlink text will only change in top most node.

How can I get the java script to affect all nodes created by the XSL file?

HTML Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="style.css" >
        <title>My Blog</title>

        <script> 

        function loadXMLDoc(fname)  
        {   

                var xmlDoc; 

                // code for IE
                if (window.ActiveXObject)
                {  
                    xmlDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");  
                }
                // code for Mozilla, Firefox, Opera, etc. 
                else if (document.implementation.createDocument) 
                { 
                    xmlDoc = document.implementation.createDocument("", "", null);  
                } 
                else 
                { 
                    alert('Your browser cannot handle this script'); 
                } 
                xmlDoc.async=false; 
                xmlDoc.load(fname); 
                return(xmlDoc); 
            }

            function loadEntries() 
            { 
                xmlDoc = loadXMLDoc("blogData.xml"); 
                xslDoc = loadXMLDoc("blogData.xsl"); 

                // for Firefox, Safari, etc.
                if (document.implementation.createDocument) 
                {
                    var xsltProcessor = new XSLTProcessor();
                    xsltProcessor.importStylesheet(xslDoc); 
                    xsltProcessor.setParameter(null, "id", 11);
                    var resultDocument = xsltProcessor.transformToFragment(xmlDoc,document);
                    document.getElementById("entries").appendChild(resultDocument);

                }
                // Internet Explorer
                else if (window.ActiveXObject) 
                {
                    var xslTemplate=new ActiveXObject("MSXML2.XSLTemplate");
                    xslTemplate.stylesheet=xslDoc;
                    var xslProc = xslTemplate.createProcessor();
                    xslProc.input = xmlDoc;
                    xslProc.addParameter("id", 11);
                    xslProc.transform();
                    document.getElementById("entries").innerHTML = xslProc.output;                  
                }

            }

            function displayResult()
            {
                var xml=loadXMLDoc("blogData.xml");
                var xsl=loadXMLDoc("blogData.xsl");
                // code for IE
                if (window.ActiveXObject)
                {
                    var ex = xml.transformNode(xsl);
                    document.getElementById("entries").innerHTML = ex;
                    document.getElementById("comments").style.display = 'none';
                    document.getElementById("hideShowLink").innerHTML = 'Show Comments';
                }
                // code for Mozilla, Firefox, Opera, etc.
                else if (document.implementation.createDocument)
                {
                    var xsltProcessor = new XSLTProcessor(); 
                    xsltProcessor.importStylesheet(xsl);
                    var resultDocument = xsltProcessor.transformToFragment(xml,document);
                    document.getElementById("entries").appendChild(resultDocument);
                    document.getElementById("comments").style.display = 'none';
                    document.getElementById("hideShowLink").innerHTML = 'Show Comments';
                }
            }

            function hideShow(){
                if(document.getElementById("comments").style.display == 'none'){
                    document.getElementById("comments").style.display = 'block';
                    document.getElementById("hideShowLink").innerHTML = 'Hide Comments';
                } else {
                    document.getElementById("comments").style.display = 'none';
                    document.getElementById("hideShowLink").innerHTML = 'Show Comments';
                }
            }

        </script>

    </head>

    <body onLoad="displayResult()">
        <table width="100%" border="0">
            <tr>
                <td colspan="2">
                    <div class="imgcentered">
                        <img src="banner.gif" alt="banner" />
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div id="entries">
                    </div>
                </td>
                <td class="rightside">
                    <div class="rightbody">
                    <ul>
                        <li><a href="index.html">Home</a></li>
                        <li>Archives</li>
                        <li>Profile
                        <br/>
                        <img src="pokemon.gif" alt="pokemin" width="40%"/><br/>
                        <br/>

                        <dl>
                            <dt><b>Name:</b></dt>
                                <dd>Ash Catchem</dd>
                            <dt><b>Age:</b></dt>
                                <dd>Old Enough</dd>
                            <dt><b>Birth Place:</b></dt>
                                <dd>Pallet Town</dd>
                            <dt><b>Current Residence:</b></dt>
                                <dd>Kanto</dd>
                            <dt><b>Occupation:</b></dt>
                                <dd>Pokemon Catcher</dd>
                        </dl>
                        </li>
                    </ul>
                    </div>
                </td>
            </tr>
        </table>
    </body>
</html>

XSL 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="/">
        <html>

            <body>
                <div class="leftbody">
                    <!-- Loops Through all of the entries node in the XML and displays then in order by date descending order --> 
                    <xsl:for-each select="//entries">
                        <xsl:sort select="creationTime/@sort" order="descending" />
                        <p><xsl:value-of select="creationTime"/>[<a href="javascript:hideShow()"> <xsl:value-of select="count(comments)"/> Comments</a>]</p>
                        <h1><xsl:value-of select="title"/></h1>
                        <p><xsl:value-of select="description"/></p>
                        <br/>
                        <p><a href="javascript:hideShow()" id="hideShowLink" class="comments"></a></p>
                        <br/><hr/><br/>

                        <div id="comments" class="comments">
                        <h2>Comments:</h2>
                            <xsl:for-each select="//comments">
                                <p class="comments"><h3><xsl:value-of select="title"/></h3></p>
                                <p class="comments"><xsl:value-of select="description"/></p>
                                <p class="comments">-- <xsl:value-of select="creator"/></p>
                            </xsl:for-each>
                            <hr/>
                        </div>

                    </xsl:for-each>



                </div>

            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Web Page I’m playing with: http://dl.dropbox.com/u/12914798/Project%202/index.html

The changes are perfect in the first blog entry. A link is created to show and hide the comments. But no where else is it working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:07:25+00:00Added an answer on June 1, 2026 at 6:07 pm

    Try to use unique IDs for A and DIV tags by using generate-id() function.

    Some changes in XSLT:

                    <xsl:for-each select="//entries">
                        <xsl:sort select="creationTime/@sort" order="descending" />
    
                        <!-- define variables -->
                        <xsl:variable name="unique-id">
                            <xsl:choose>
                                <xsl:when test="position() = 1">
                                    <xsl:value-of select="''"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="generate-id(.)"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>
                        <xsl:variable name="comments-id" select="concat('comments',$unique-id)"/>
                        <xsl:variable name="hideShowLink-id" select="concat('hideShowLink',$unique-id)"/>
                        <xsl:variable name="a-href" select="concat('javascript:hideShow(&#34;',$unique-id,'&#34;)')"/>
    
                        <!-- title and description -->
                        <p><xsl:value-of select="creationTime"/>[<xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="$a-href"/></xsl:attribute> <xsl:value-of select="count(comments)"/> Comments</xsl:element>]</p>
                        <h1><xsl:value-of select="title"/></h1>
                        <p><xsl:value-of select="description"/></p>
                        <br/>
                        <p>
                            <xsl:element name="a">
                                <xsl:attribute name="id"><xsl:value-of select="$hideShowLink-id"/></xsl:attribute>
                                <xsl:attribute name="href"><xsl:value-of select="$a-href"/></xsl:attribute>
                                <xsl:attribute name="class"><xsl:value-of select="'comments'"/></xsl:attribute>
                                Show Comments
                            </xsl:element>
                        </p>
                        <br/><hr/><br/>
    
                        <!-- comments -->
                        <xsl:element name="div">
                            <xsl:attribute name="id"><xsl:value-of select="$comments-id"/></xsl:attribute>
                            <xsl:attribute name="class"><xsl:value-of select="'comments'"/></xsl:attribute>
                            <xsl:attribute name="style"><xsl:value-of select="'display:none'"/></xsl:attribute>
                            <h2>Comments:</h2>
                            <xsl:for-each select="//comments">
                                <p class="comments"><h3><xsl:value-of select="title"/></h3></p>
                                <p class="comments"><xsl:value-of select="description"/></p>
                                <p class="comments">-- <xsl:value-of select="creator"/></p>
                            </xsl:for-each>
                            <hr/>
                        </xsl:element>
    
                    </xsl:for-each>
    

    Also you need to change JS functions:

            function displayResult()
            {
                var xml=loadXMLDoc("p100993_IR1.2_output_without_header_1.csv.xml");
                var xsl=loadXMLDoc("LoadVendorAnalytic.xsl");
                // code for IE
                if (window.ActiveXObject)
                {
                    var ex = xml.transformNode(xsl);
                    document.getElementById("entries").innerHTML = ex;
                }
                // code for Mozilla, Firefox, Opera, etc.
                else if (document.implementation.createDocument)
                {
                    var xsltProcessor = new XSLTProcessor(); 
                    xsltProcessor.importStylesheet(xsl);
                    var resultDocument = xsltProcessor.transformToFragment(xml,document);
                    document.getElementById("entries").appendChild(resultDocument);
                }
            }
    
            function hideShow(id){
                if(document.getElementById("comments"+id).style.display == 'none'){
                    document.getElementById("comments"+id).style.display = 'block';
                    document.getElementById("hideShowLink"+id).innerHTML = 'Hide Comments';
                } else {
                    document.getElementById("comments"+id).style.display = 'none';
                    document.getElementById("hideShowLink"+id).innerHTML = 'Show Comments';
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to use single quotes as much as possible and I've noticed that
I think I'm not the only one having this problem. Whenever I try to
I've noticed that if you try to send an email to an invalid address,
I've noticed something peculiar about Visual Studio. First, try typing this (C#) somewhere in
I try to make my code fool-proof, but I've noticed that it takes a
I've noticed something funny Java does (or at least Netbeans) when I use classes
I've noticed that when I try to display the value of a variable with
I've noticed this problem happening a lot in most things I do, so I'm
I've noticed with Integer.parseInt() that you don't have to surround it with a try
I've noticed I'm getting a compiler warning message: Warning: BC40056: Namespace or type specified

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.