Solved

NavBar Expand/Collapse values from an XML file

Posted on 2004-04-15
5
682 Views
Last Modified: 2010-05-18
Here's a previous excepted answer:
http://www.experts-exchange.com/Web/Web_Languages/XML/Q_20952554.html

The problem:
I'd like to expand/collapse the values to one more row.
0
Comment
Question by:evvsupport
  • 3
5 Comments
 
LVL 5

Expert Comment

by:alambres
ID: 10834364
do you mean?

in example

Artist
     Title
         Song
         Song
         ...
0
 
LVL 3

Expert Comment

by:ljfernandez
ID: 10835294
OK, this goes down another level, artist, title then year:

--Lisa

=================================
XML
=================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xsl1.xsl"?>
<catalog>
     <artist>
          <name>Bob Dylan</name>
          <albums>
               <album>
                    <title>Empire Burlesque</title>
                    <year>1985</year>
               </album>
               <album>
                    <title>Desire</title>
                    <year>1975</year>
               </album>
          </albums>
     </artist>
     <artist>
          <name>Led Zeppelin</name>
          <albums>
               <album>
                    <title>Hoses of the Holy</title>
                    <year>1973</year>
               </album>
               <album>
                    <title>Physical graffiti</title>
                    <year>1975</year>
               </album>
          </albums>
     </artist>
</catalog>
=================================
XML
=================================

=================================
XSL
=================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" encoding="ISO-8859-1" />

<xsl:template match="/">
 
  <html>
  <head>
  <title>Catalog</title>
  <script type="text/javascript">
       function showHideAlbums (obj)
       {
            var disp = obj.getAttribute("displayed")=="1"?"none":"block";
            obj.setAttribute("displayed", obj.getAttribute("displayed")=="1"?"0":"1");
            document.getElementById("list"+obj.getAttribute("ind")).style.display = disp;
       }
         function showHideYears (obj)
       {
            var disp = obj.getAttribute("displayed")=="1"?"none":"block";
            obj.setAttribute("displayed", obj.getAttribute("displayed")=="1"?"0":"1");
            document.getElementById("listy"+obj.getAttribute("ind")).style.display = disp;
       }
  </script>
  </head>
  <body>
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <th align="left">Catalog</th>
    </tr>
    <xsl:for-each select="catalog/artist">
         <xsl:variable name="ind"><xsl:value-of select="position()"/></xsl:variable>
          <tr>
                <td>
                     <a href="javascript:void(0);" displayed="0">
                          <xsl:attribute name="ind"><xsl:value-of select="$ind"/></xsl:attribute>
                          <xsl:attribute name="onclick">showHideAlbums (this);</xsl:attribute>
                          <xsl:value-of select="name"/>
                     </a>
                </td>
         </tr>
         <tr>
                <td>
                   <span style="display:none;">
                        <xsl:attribute name="id">list<xsl:value-of select="$ind"/></xsl:attribute>
                        <table>
                             <xsl:for-each select="albums/album">
                             <tr>
                                  <td style="padding-left:30px">
                                                               <a href="javascript:void(0);" displayed="0">
                                                                    <xsl:attribute name="ind"><xsl:value-of select="$ind"/></xsl:attribute>
                                                                    <xsl:attribute name="onclick">showHideYears (this);</xsl:attribute>
                                                                     <xsl:value-of select="title"/>
                                                             </a>
                                                              <span style="display:none;">
                                                                        <xsl:attribute name="id">listy<xsl:value-of select="$ind"/></xsl:attribute>
                                                                        <table>
                                                                               <tr>
                                                                                      <td style="padding-left:30px">
                                                                                                <xsl:value-of select="year"/>
                                                                                          </td>
                                                                               </tr>
                                                                        </table>
                                                               </span>
                                    </td>
                             </tr>
                             </xsl:for-each>
                        </table>
                   </span>
              </td>
         </tr>
    </xsl:for-each>
    </table>
  </body>
  </html>

</xsl:template>

</xsl:stylesheet>
=================================
XSL
=================================
0
 
LVL 3

Expert Comment

by:ljfernandez
ID: 10835808
sorry the above has a bug. Will post update shortly.
0
 
LVL 3

Accepted Solution

by:
ljfernandez earned 500 total points
ID: 10835878
OK the below xsl works correctly.

=================================
XSL
=================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" encoding="ISO-8859-1" />

<xsl:template match="/">
 
  <html>
  <head>
  <title>Catalog</title>
  <script type="text/javascript">
       function showHideAlbums (obj)
       {
            var disp = obj.getAttribute("displayed")=="1"?"none":"block";
            obj.setAttribute("displayed", obj.getAttribute("displayed")=="1"?"0":"1");
            document.getElementById("list"+obj.getAttribute("ind")).style.display = disp;
       }
         function showHideYears (obj)
       {  
            var disp = obj.getAttribute("displayed")=="1"?"none":"block";
            obj.setAttribute("displayed", obj.getAttribute("displayed")=="1"?"0":"1");
            document.getElementById("listy"+obj.getAttribute("ind")).style.display = disp;
       }
  </script>
  </head>
  <body>
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <th align="left">Catalog</th>
    </tr>
    <xsl:for-each select="catalog/artist">
         <xsl:variable name="ind"><xsl:value-of select="position()"/></xsl:variable>
          <tr>
                <td>
                     <a href="javascript:void(0);" displayed="0">
                          <xsl:attribute name="ind"><xsl:value-of select="$ind"/></xsl:attribute>
                          <xsl:attribute name="onclick">showHideAlbums (this);</xsl:attribute>
                          <xsl:value-of select="name"/>
                     </a>
                </td>
         </tr>
         <tr>
                <td>
                   <span style="display:none;">
                        <xsl:attribute name="id">list<xsl:value-of select="$ind"/></xsl:attribute>
                        <table>
                             <xsl:for-each select="albums/album">      
                             <tr>
                                  <td style="padding-left:30px">
                                                               <a href="javascript:void(0);" displayed="0">
                                                                    <xsl:attribute name="ind"><xsl:value-of select="title"/></xsl:attribute>
                                                                    <xsl:attribute name="onclick">showHideYears (this);</xsl:attribute>
                                                                     <xsl:value-of select="title"/>
                                                             </a>
                                                              <span style="display:none;">
                                                                        <xsl:attribute name="id">listy<xsl:value-of select="title"/></xsl:attribute>
                                                                        <table>
                                                                               <tr>
                                                                                      <td style="padding-left:30px">
                                                                                                <xsl:value-of select="year"/>
                                                                                          </td>
                                                                               </tr>
                                                                        </table>
                                                               </span>
                                    </td>
                             </tr>
                             </xsl:for-each>
                        </table>
                   </span>
              </td>
         </tr>
    </xsl:for-each>
    </table>
  </body>
  </html>

</xsl:template>

</xsl:stylesheet>


=================================
XSL
=================================
0
 

Author Comment

by:evvsupport
ID: 10835912
Awesome.. Thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get the parent segment field value in an xml using XSLT 6 35
c# & linq 7 87
Merge XML into DOM 5 37
Adding Namespace to the second node of the xml 16 60
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now