Achieve full expansion or complete collapse in stylesheet through Java code

My goal is to compile multiple XML files into an HTML table and display the results. I utilize the xsl:elemnt command to create individual cells within the tables as shown below:

<table>
    <col span="1" class="firstCol" />
    <thead align="center">
        <tr class="headerColor" >
            <th style="text-align: left" class="Test" >Test</th>
            <th > Start </th>
            <th > End </th>
            <th > Duration </th>
        </tr >
        <tr style="border: 2px solid black" class="fristRow" onclick="CollapseExpandAll(this)" title="Click here to collapse/expand">
            <td align="left">
                <b> 
                    <xsl:value-of select="attribute::name"/>                            
                </b>
            </td>
        </tr>
    </thead>
    <xsl:element name="tableRows">
        <xsl:attribute name="id">
            <xsl:value-of select="attribute::name"/>
        </xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</table>

To enable expand/collapse functionality, I have implemented the following JavaScript code:

<script type="text/javascript" language="JavaScript" >
    function CollapseExpandAll(obj)
        {
            var tableRows = obj.parentNode.parentNode.parentNode.getElementsByTagName("tableRows")[0];
            var old = tableRows.style.display;
            tableRows.style.display = (old == "none"?"":"none");
        }
</script>

I am looking for help in modifying this script to simultaneously collapse or expand all created tables using a single button. Any guidance or assistance would be greatly appreciated. Thank you!

Update:

Below is a snippet of my XML file structure:

<SquishReport version="2.1" xmlns="http://www.froglogic.com/XML2">
    <test name="tst_main">
        <test name="tst_start_app">
            <description>  CDATA </description>
        </test>
        <test name="tst2">
            <description>  CDATA </description>
        </test>
    </test>
    ...
</SquishReport>

The desired outcome is to generate a separate table for each test_main, resulting in three distinct tables within the HTML document.

Answer №1

Take a look at this thread.

How can I expand and collapse a <div> using javascript?

If you want to add an expand and collapse effect to a table, you would need to assign a class to the table. Here is an example of how the code might look:

HTML:

<table class="tableClass">
<col span="1" class="firstCol" />
<thead align="center">
    <tr class="headerColor" >
        <th style="text-align: left" class="Test" >Test</th>
        <th > Start </th>
        <th > End </th>
        <th > Duration </th>
    </tr >
    <tr style="border: 2px solid black" class="fristRow" onclick="CollapseExpandAll(this)" title="Click here to collapse/expand">
        <td align="left">
            <b> 
                <xsl:value-of select="attribute::name"/>                            
            </b>
        </td>
    </tr>
</thead>
<xsl:element name="tableRows">
    <xsl:attribute name="id">
        <xsl:value-of select="attribute::name"/>
    </xsl:attribute>
    <xsl:apply-templates/>
</xsl:element>

Javascript:

<script type="text/javascript" language="JavaScript" >
    $(".tableClass").click(function () {
    $header = $(this);
    $content = $header.next();
    $content.slideToggle(500, function () {
    //execute this after slideToggle is done
    //change text of header based on visibility of content div
    $header.text(function () {
        //change text based on condition
        return $content.is(":visible") ? "Collapse" : "Expand";
    });
});
</script>

Keep in mind that JQuery needs to be included in your project for this code to work.

I hope this information proves helpful.

Answer №2

Give this a shot and see if it does the trick.

$('firstRow').on('click', function(){
    $('.firstRow').slideToggle(1000);
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

storing data in a nested child object within an array

I am attempting to include variables into the existing JSON data that is received from an API whenever a user clicks on the add button. However, I encountered this error message: Cannot find a differ supporting object '[object Object]' of type & ...

What is the reason behind these sinon stubs returning undefined values?

I have created a unit test for this code snippet and used Sinon to stub the browser methods (specifically with sinon-chrome, an older but still functional library that suits my needs). /** * Returns an array of languages based on getAcceptLanguages and ge ...

Combining Angular Material with another CSS framework

I'm diving into my first Angular project and contemplating incorporating Angular Material. It offers an abundance of components, which aligns with my project needs. However, I've noticed a lack of grid system and utility classes within Angular Ma ...

Unlocking the power of AJAX to retrieve PHP responses

Is it possible to have a PHP response displayed within a <span>..</span> on an HTML web page? If so, can someone guide me on how to achieve this or point out any issues with the existing code? Thank you in advance! ^^ <html> <head& ...

Tips for creating an HTML report using Python

Currently, I am searching for a solution to convert my saved matplotlib graphs as png files along with some data frames into HTML format. This is similar to how I typically use R2HTML in R. Despite my efforts, I have not been able to locate clear informat ...

JavaScript script that parses innerHTML

Does the behavior of element.innerHTML = '<script>alert()</script>'; differ across browsers? Can I consistently expect innerHTML to not parse scripts? ...

Replacing current CSS styles within a CMS template

Working on customizing the Whitehouse WordPress theme has been quite a challenge lately. It seems that some predefined style rules within the theme are interfering with the tags I'm implementing, causing some frustrating issues to deal with. Specific ...

What is the best way to retrieve an element from a JavaScript object?

What is the best way to retrieve an item from a JavaScript object? var items = [ { ITEM:1, AMOUNT:10 }, { ITEM:2, AMOUNT:20 } ]; I am looking for a method that allows me to achieve the following: $(items).filter(ITEM == 1).AMOUNT ...

Unable to make a jQuery Ajax HTTP Request within a Chrome extension

I'm facing an issue with sending a jQuery Ajax HTTP Request within google chrome extensions. I have already imported the jQuery library and used the following code: $.ajax({ method: "PUT", url: "https://spreadsheets.google ...

Obtaining an attribute of a row in a table using Selenium and Python

I've been trying to figure out how to check if this button (image) has been clicked: https://i.sstatic.net/Nc3Pe.png It's crucial for me to interact with this button, as it allows me to modify the price of certain items and protect them when ne ...

What is the best way to set up the Sub-menu in Fusion Mega Menu to only appear when hovering over it?

I am currently using a Fusion theme for WordPress and trying to replicate the mega menu from the previous website. Take a look at our production site: Production site If you hover over "Expertise" and then "Families & Individuals," you will see the s ...

Easily adding multiple field data with the same field name into a database can be achieved using Mongoose and Node.js (specifically Express

I am new to using nodejs and exploring the creation of a project focused on generating invoices. My goal is to store product information in mongodb utilizing mongoose and express, but I'm unsure of how to proceed. Below is a snippet of my HTML code.. ...

retrieve the subscription with Meteor.subscribe within a callback function

I'm facing an issue with the following code snippet: Meteor.subscribe('getOrgDetail', {status:'active'}, function(){ var sub = this; self.setState({'subscriptions.orgs':sub{id:Organizations.find().fetch() ...

Align Bootstrap navigation bar items at the center horizontally

I am currently working on a navigation bar that features two icons, evenly distributed. To achieve this look, I have been experimenting with scaling the icons horizontally in order to make them center-aligned within the navigation bar. However, I have not ...

How can I modify the mesh structure in Three.js?

Having two meshes, mesh1 and mesh2, each with the same number of vertices and extrusion. mesh1 = 5000 vertices. mesh2 = 5000 vertices. I transfer the vertices from mesh2 to mesh1. Then I execute: mesh2.geometry.verticesNeedUpdate = true; mesh2.geometry. ...

Troubleshooting a problem with the `.toggle()` function in

My form includes a question where multiple answers, including "Others," can be selected by ticking checkboxes. When the "Others" option is ticked, a textbox should appear, and when unticked, the textbox should hide. The issue I'm facing is that even ...

Testing asynchronous functions in React with jest and rtl: a step-by-step guide

I am currently testing my asynchronous submit function in my form using RTL and Jest, but I have encountered some errors during the process. This is actually my first time delving into code testing, so I find the testing procedures quite confusing. Below ...

The HTML code is missing the special characters for less than (<) and greater than (>)

Update: July 19, 2019 Solved the issue by using $_REQUEST['editor1'] instead of $_POST['editor1']. The reason for this change is not entirely clear. Hopefully, it will be helpful to anyone facing a similar odd problem. =========== ...

Accessing state in Vuex modules is crucial for managing and manipulating data effectively

Feeling a bit lost here... I'm utilizing Vuex in my project and have a module called common stored in the file common.js: const initState = { fruits: [] } export default { state: initState, mutations: { SET_FRUITS(state, fruits) { cons ...

Tips for assigning array variables to elements in querySelectorAll [Pure JavaScript]

I need help with assigning values from an array to elements selected by the querySelectorAll function. I am trying to write code that will change the text to different values in the array when the browser width is below 768px, but I'm facing some chal ...