Solved

NavBar Expand/Collapse values from an XML file

Posted on 2004-04-15
5
686 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Image decoding from Camera 3 106
ASP.NET reading ATOM 2 79
Eliminate additional border 1 29
write xml in vb.net 2 49
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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, …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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