Solved

NavBar Expand/Collapse values from an XML file

Posted on 2004-04-15
5
683 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fetch XML Unions? 3 583
Unattended XML settings 4 111
AL3 Files 4 28
SQL XML ALL Nodes Compare in function 2 27
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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