[xsl] Fwd: Not able to display Information after selecting elements from a drop down list

Subject: [xsl] Fwd: Not able to display Information after selecting elements from a drop down list
From: Mulberry Technologies List Owner <xsl-list-owner@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 17 Sep 2003 19:17:29 -0400
>Date: Wed, 17 Sep 2003 14:21:18 -0700
>From: Nishi Bhonsle <nishi.bhonsle@xxxxxxxxxx>
>To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>Subject: Not able to display Information after selecting elements from a drop
> down list
>
> 
>Resending this query since I did not hear from anyone.............................Thank you.
>
>> 
>>Hi:
>>I have a xsl file that has 2 drop down boxes. My purpose is to select element1 from drop down list box A and element2 from drop down list box B and display some information that pertains to that combination.
>>But everytime I try to apply the xsl on the xml (using XMLSPY) and then try to select and choose elements from either of the lists, i get a oXSLDoc Var is NULL or not an object error.
>>I also do not see new information displayed for every combination I choose either, which i think is because of the error from oXSLlDoc initialisation.
>>The code was picked up from some sample code available on the web.
>>
>>dropdown.xml-->
>><?xml version="1.0"?>
>><?xml:stylesheet type="text/xsl" href="dropdown.xslt"?>
>><sites>
>>   <location name="site 1" id="1">
>>        <customer name="Customer!" id="11">
>>             <host name="host 1" id="111"/>
>>             <host name="host 1" id="112"/>
>>             <host name="host n" id="11n"/>
>>        </customer>
>>        <customer name="Customer!!!!" id="1a1">
>>             <host name="host 1" id="11a1"/>
>>             <host name="host 1" id="1s12"/>
>>             <host name="host n" id="1s1n"/>
>>        </customer>
>>   </location>
>>   <location name="site n" id="n">
>>        <customer name="cust 1" id="11">
>>             <host name="host 1" id="111"/>
>>             <host name="host 1" id="112"/>
>>             <host name="host n" id="11n"/>
>>        </customer>
>>        <customer name="cust n" id="1a1">
>>             <host name="host 1" id="11a1"/>
>>             <host name="host 1" id="1s12"/>
>>             <host name="host n" id="1s1n"/>
>>        </customer>
>>   </location>
>></sites>
>>
>>dropdown.xslt-->
>><?xml version="1.0"?>
>><xsl:stylesheet version="1.0" xmlns:xsl="<http://www.w3.org/1999/XSL/Transform>http://www.w3.org/1999/XSL/Transform";>
>>
>><!-- These are the params for specifying the locationid and customerid for the default selection in each dropdown list box-->
>><xsl:param name="DefaultSelectedLocationID" select="string(/sites/location[1]/@id)" />
>><xsl:param name="DefaultSelectedCustomerID" select="string(/sites/location[@id=$SelectedLocationID]/customer[1]/@id)" />
>>
>><!-- These are the variable for storing the locationid and customerid for the current selection in each dropdown list box-->
>><xsl:variable name="SelectedLocationID" select="$DefaultSelectedLocationID" />
>><xsl:variable name="SelectedCustomerID" select="$DefaultSelectedCustomerID" />
>>
>><xsl:template match = "/">
>><html>
>> <head>
>> <script type = "text/javascript" language = "javascript">
>>     <![CDATA[
>>        var oXSLDoc = document.XSLDocument;
>>        var oXMLDoc = document.XMLDocument;
>>
>>     //Updates XSL variable
>>        function updateVar(sName, sValue)
>>        {
>>             //select the xsl:variable node. This is for storing the item selected in each drop down list
>>             var oVarNodeSelectAttr = oXSLDoc.selectSingleNode( "//xsl:variable[@name='" + sName + "']/@select" );
>> 
>>
>>          //reset to default or store the selected value
>>             if (sValue == '_default')
>>                   oVarNodeSelectAttr.nodeValue = "$Default" + sName;
>>          else
>>                  oVarNodeSelectAttr.nodeValue = "string('" + sValue + "')";
>> 
>>
>>         }
>>
>>         //retransform the current XML document with the current XSL document
>>        function reDisplay()
>>        {
>>             //we only want to transform from the root node. This is so we dont repeat the headers and script sections
>>           divResults.innerHTML = oXMLDoc.documentElement.transformNode( oXSLDoc );
>>
>>        }
>>     ]]>
>>   </script>
>>   </head>
>>  <body>
>>     <div ID = "divResults">
>>            <!-- This is a place holder for the dropdown lists which will by replaced with the above javascript -->
>>        <xsl:apply-templates select="sites"/>
>>     </div>
>>  </body>
>></html>
>>
>></xsl:template>
>>
>><xsl:template match = "sites">
>>    Location:
>>    <select name="LocationList" onchange="updateVar('SelectedLocationID', this.value);updateVar('SelectedCustomerID', '_default');reDisplay()">
>>         <xsl:apply-templates select="location">
>>              <xsl:sort select="@name"/>
>>         </xsl:apply-templates>
>>    </select>
>>    <br/>
>>    <br/>
>>    Customer:
>>    <select name="CustomerList" onchange="updateVar('SelectedCustomerID', this.value);reDisplay()">
>>         <xsl:apply-templates select="location[@id = $SelectedLocationID]/customer">
>>              <xsl:sort select="@name"/>
>>         </xsl:apply-templates>
>>    </select>
>>
>>    <br/>
>>    <br/>
>>    <table border="1">
>>    <tr><th>host</th><th>host id</th></tr>
>>         <xsl:apply-templates select="location[@id = $SelectedLocationID]/customer[@id = $SelectedCustomerID]/host">
>>              <xsl:sort select="@name"/>
>>         </xsl:apply-templates>
>>    </table>
>> 
>>
>></xsl:template>
>>
>><xsl:template match = "location">
>>    <option>
>>          <xsl:attribute name="value">
>>              <xsl:value-of select="@id"/>
>>          </xsl:attribute>
>>          <xsl:if test="@id = $SelectedLocationID">
>>            <xsl:attribute name="selected">selected</xsl:attribute>
>>          </xsl:if>
>>          <xsl:value-of select="@name"/>
>>    </option>
>></xsl:template>
>> 
>>
>><xsl:template match = "customer">
>>    <option>
>>          <xsl:attribute name="value">
>>              <xsl:value-of select="@id"/>
>>          </xsl:attribute>
>>          <xsl:if test="@id = $SelectedCustomerID">
>>            <xsl:attribute name="selected">selected</xsl:attribute>
>>          </xsl:if>
>>          <xsl:value-of select="@name"/>
>>    </option>
>></xsl:template>
>>
>><xsl:template match = "host">
>>    <tr>
>>         <td><xsl:value-of select="@name"/></td>
>>         <td><xsl:value-of select="@id"/></td>
>>    </tr>
>></xsl:template>
>>
>></xsl:stylesheet>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread