?
Solved

NavBar Expand/Collapse values from an XML file

Posted on 2004-04-15
5
Medium Priority
?
688 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

801 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