xsl-list
[Top] [All Lists]

Re: [xsl] Displaying one section of XML file at a time -- posting again

2006-03-27 15:27:35


--- Wendell Piez <wapiez(_at_)mulberrytech(_dot_)com> wrote:
The easiest way to figure out how to do it is to 
start by mocking up a 
functioning HTML/Javascript page with the behavior,
and then to 
determine how to write the XSLT to generate it.

We can help with the second part,  I'd 
recommend looking in an HTML or Javascript forum to
find your 
example, and then coming back if you can't figure
out how to compose XSLT to create it. 

Wendell, Jon,
Sorry to bother you, but have been working on this one
for a few days and couldn't make it work in XSLT. The
display/hide function works well in the
HTML/Javascript example page that I built, but having
problems in XLT. The problem is that it displays only
one table.
Will appreciate if you could take a look at my
XML/XSLT/JS code and let me know what is missing or
where I am going wrong.

My XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="simple.xsl"?>

<catalog>
<cd id="1">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
<year>1985</year>
</cd>
<cd id="2">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>
---------------------------------------------------------
My XSLT style sheet looks like this:
<?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"/>

<xsl:template match="/">

<html>
<head>
<script type='text/javascript'
src="expand.js"></script>
</head>

<body>
<h2>My CD Collection</h2>
<xsl:apply-templates select="catalog/cd"/>
</body>
</html>
</xsl:template>

<xsl:template match="cd">
<xsl:variable name="id" select="@id"/>
<h2>
<a href='javascript:void(0);' onClick="toggle('$id')">
<xsl:value-of select="title"/>
</a>
</h2>

<div style="display:none" id="$id">
<table border="1">
<tr>
<th>Artist</th>
<th>Price</th>
<th>Year</th> 
</tr>

<tr>
<td> <xsl:value-of select="artist"/> </td>
<td> <xsl:value-of select="price"/> </td>
<td> <xsl:value-of select="year"/> </td>
</tr>
</table>
</div>
</xsl:template>

</xsl:stylesheet>
---------------------------------------------------

Here is my JavaScript function:

// Show/hide document sections

function toggle(currentVdd) {
 if (document.getElementById){
         thisTable =
document.getElementById(currentVdd).style;
   if(thisTable.display == "block"){
                 thisTable.display = "none"
   }
         else{
                 thisTable.display = "block"
   }
         return false
 }else{
  return true
 }

}
----------------------------------------------------

Thanks,
Gowri



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--