Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

XML XSLT parameters Javascript - how to make it work in Mozilla...

Avatar of yellow1234
yellow1234 asked on
XML
13 Comments1 Solution4855 ViewsLast Modified:
Yes - I ve seen similair questions before and I searched the web but I cannot get it to work in Mozilla -  (works fine in IE with the ActiveXObjects). What I like to achieve is a much more complicated then this - but I ve seen to many times pages and pages of code where a basic example would have done OK... so I narrowed down the code to this:
The basic idea is that through Javascript you set a variable in the xsl document, the xml and xsl is loaded again and the hml document shows the data according to the parameter. I quess my question is what's the ActiveX equivalent in Mozilla and how do i set a parameter then?  Thanks everybody - 3 files below - copy and paste it and you'll see works OK in IE

1. The XML file (four books - Author, Title and Price): books.xml
=========================================
<?xml version='1.0' encoding='ISO-8859-1'?>
<Catalog>
<Book>
<Title>On holiday in Turkey</Title>
<Author>O Arslan</Author>
<Price>20</Price>
</Book>
<Book>
<Title>South Coast of Turkey</Title>
<Author>Peter Jones</Author>
<Price>18</Price>
</Book>
<Book>
<Title>Istanbul and the West Coast</Title>
<Author>John Apple</Author>
<Price>19</Price>
</Book>
<Book>
<Title>The Turkish Black Sea Coast</Title>
<Author>John Deniz</Author>
<Price>19.5</Price>
</Book>
</Catalog>

2.  The XSL file, to display the items sorted by price: sort.xsl
Note the parameter at the top for sorting
=======================================
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="sortOrder" select="'ascending'" />
 
<xsl:template match="/">
      <xsl:for-each select="Catalog/Book">
                <xsl:sort select="Price" data-type="number" order="{$sortOrder}"/>
            <xsl:call-template name="ShowBooks" />
            </xsl:for-each>
</xsl:template>

<xsl:template name="ShowBooks">
      <xsl:value-of select="Author"/> /
      <xsl:value-of select="Title"/>  / USD
      <xsl:value-of select="Price"/>  <br />
</xsl:template>

</xsl:stylesheet>


3. The HTML file including Javascript. The Javascript
loads the XML and XSL and displays it in a <div>
When changing the select, the Javascript runs again, assigning a value
to the parameter in the xsl file:
=============================================
<html>

<head>
<script language="javascript">

function sortlist(myvalue)   {

    var xslt = new ActiveXObject("Msxml2.XSLTemplate");
    var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
    var xslProc;
    xslDoc.async = false;
    xslDoc.resolveExternals = false;
    xslDoc.load("sort.xsl");
    xslt.stylesheet = xslDoc;
    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
    xmlDoc.async = false;
    xmlDoc.resolveExternals = false;
    xmlDoc.load("books.xml");
    xslProc = xslt.createProcessor();
    xslProc.input = xmlDoc;

    xslProc.addParameter("sortOrder", myvalue);

    xslProc.transform();
    var str;
    str = xslProc.output;
    document.getElementById('books').innerHTML=str;
}

</script>

</head>
<body  onLoad="sortlist('ascending')">
<h2>Books</h2>

<form name='ascdesc'>
Sort price
<select  name ='SortOrder'
onChange="sortlist(ascdesc.SortOrder.options[ascdesc.SortOrder.selectedIndex].value)">
      <option value='ascending' selected>Ascending</option>
      <option value='descending'>Descending</option>
</select>
</form>

<div id='books'></div>

</body>
</html>


=====


ASKER CERTIFIED SOLUTION
Avatar of sybe
sybe

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answers