[Javascript] Play Tune Using Button - involves Javascript, XML, XSLT

charlie_chan charlie_chan at cox-internet.com
Wed May 11 21:21:04 CDT 2005


I do my best to pose the question.  This learning project involves
XML, XSLT, and Javascript.  I have an XML file that contains this code:
<?xml version="1.0" ?><!-- THIS IS THE TITLE SORTATION MAIN PAGE -->
<?xml-stylesheet href="Trans_Titles.xsl" type="text/xsl" ?>
<!-- Some of what follows may not be necessary. -->
<!DOCTYPE html [
<!ENTITY data SYSTEM "./data.xml" >
<!ENTITY data SYSTEM "/lulu.mp3" >
<!ELEMENT data (item+) >
<!ELEMENT item ANY >
<!ATTLIST item ref ID #IMPLIED >
<!ELEMENT title (#PCDATA) >
<!ELEMENT edition (#PCDATA) >
<!ELEMENT copyrighted (#PCDATA) >
<!ELEMENT authors (author?) >
   <!ELEMENT author (FName?, MName?, LName, degree?) >
       <!ELEMENT FName (#PCDATA) >
       <!ELEMENT MName (#PCDATA) >
       <!ELEMENT LName (#PCDATA) >
       <!ELEMENT degree (#PCDATA) >
<!ELEMENT publisher (#PCDATA) >
<!ELEMENT isbn (#PCDATA) >
<!ELEMENT lccn (#PCDATA) >
<!ELEMENT price ANY >
<!ELEMENT subject ANY >
]>
<!-- This is a reference to the entity created above.  &data; -->
<data></data>

There is a separate XML data file and the XSLT file.  I am trying to learn
how to set up a button in the XSLT file so that it will start an mp3 file
named lulu.mp3.  I have been reading a lot of info in an effort to learn 
how
but I have been unsuccessful.  A I get is a message box saying Object 
Requird
when I click the button.  Would some one please give a little help in 
solving
this.   Here is the XSLT file:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html" indent="yes" />

<xsl:template match="/">
<html>
<!-- If I set autostart="true", it plays on load. -->
<embed  name="lulu" src="lulu.mp3" loop="false" autostart="false" 
hidden="true" />
<script language="javascript">
<!--
function playSound()
{ self.document.lulu.play(); }
//-->
</script>

<bgsound src="chpv62[1].wav" class="intro" />
   <link rel="stylesheet" type="text/css" href="my_bookstyle.css" />
<head>
   <title>MY LIBRARY - SORTED BY TITLE</title>
</head>
<body>
   <table>
       <tr align="right"><td>BOOKS SORTED BY TITLE</td><td><img 
src="./CharlieChan_bw2.jpg" /></td></tr>
       <tr><td align="left"><a href="mainSubject.xml" tabindex="0">Sort 
by Subjects</a></td>
           <td align="right"><a href="mainAuthors.xml" tabindex="1">Sort 
by Authors</a></td></tr>
      <!-- BUTTON CODE BELOW -->
       <tr><td align="center">
           <xsl:element name="button" >
           <xsl:attribute name="onClick" >playSound()</xsl:attribute>
           PLAY THEME</xsl:element> </td></tr>
   </table>

   <!-- Example of using the document( ) to include a source tree from a 
separate XML document -->
   <xsl:for-each select="document('data.xml') /data/item/."><!-- Notice 
the way this code ends -->
       <xsl:sort data-type="text" select="normalize-space(title)" /><!-- 
NOTICE THE data-type ENTRY -->
           <table>
               <xsl:call-template name="aTable" /><!-- calling a named 
template -->
           </table>
   </xsl:for-each>

</body>
</html>
</xsl:template>

<!--
I used HTML tags instead of XSLT element tags to display the data in 
this table
because it is easier to work with when using a CSS document.
-->
<xsl:template name="aTable">
   <tr class="highlightBlue"><td class="aBorderTL"> TITLE </td><td 
class="aBorderTR"><xsl:value-of select="title" /></td></tr>
   <tr><td>EDITION</td><td><xsl:value-of select="edition" /></td></tr>
   <tr><td>COPYRIGHTED</td><td><xsl:value-of select="copyrighted" 
/></td></tr>
   <!-- for-each loop -->
   <xsl:for-each select="./authors/author/LName">
       <xsl:sort data-type="text" order="ascending" 
select="normalize-space(./authors/author/LName)" />
       <tr><td class="aBorderML">AUTHOR/s</td><td class="aBorderMR">
           <xsl:value-of select="parent::author/FName" /> <xsl:value-of 
select="' '" />            <xsl:value-of select="parent::author/MName" 
/> <xsl:value-of select="' '" />
           <xsl:value-of select="parent::author/LName" /> <xsl:value-of 
select="' '" />
           <xsl:value-of select="parent::author/degree" /> <xsl:value-of 
select="*/*" />
       </td></tr>          </xsl:for-each>
   <tr><td>PUBLISHER</td><td><xsl:value-of select="publisher" /></td></tr>
   <tr><td>ISBN</td><td><xsl:value-of select="isbn" /></td></tr>
   <tr><td>LCCN</td><td><xsl:value-of select="lccn" /></td></tr>
   <tr><td>PRICE</td><td><xsl:value-of select="price" /></td></tr>
   <tr><td class="aBorderBL">SUBJECT</td><td 
class="aBorderBR"><p><xsl:value-of select="subject" /></p></td></tr>
   <br />

</xsl:template>
</xsl:stylesheet>





More information about the Javascript mailing list