Using the .addParameter() function

M

Mark Constant

I have a drop-down list now and I got it so when something is selected
from the drop down list it calls a JavaScript function. I want it so
the value selected from the drop-down list is sent as a parameter to
the xslt file. When I select a value from the drop-down list nothing
appears. I want just a basic listing of Title, Image, and Description
outputed. I have done a basic JavaScript that uses the .write()
function and that worked so the value is getting sent to the
JavaScript function from the drop-down list. So the problem has to be
with the .addParameter function. What could I be missing?

Here is my javascript and drop-down menu.
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<SELECT name="select1" onchange='CallXML(this.form.select1);'>
<OPTION value="Ratchet and Clank">Ratchet and Clank</OPTION>
<OPTION value="Sly Cooper">Sly Cooper</OPTION>
</SELECT>
</form>
</body>




<script language="javascript">
function CallXML(dropdown)
{
var myindex = dropdown.selectedIndex;
var SelValue = dropdown.options[myindex].value;
xml = new ActiveXObject("Msxml2.DOMDocument.4.0");
xml.async = false;
xml.load("Games.xml");
xslt = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
xslt.async = false;
xslt.load("Games.xslt");
xslTemp = new ActiveXObject("Msxml2.XSLTemplate.4.0");
xslTemp.stylesheet = xslt;
var xslProc = xslTemp.createProcessor();
xslProc.input = xml;
xslProc.addParameter(Title, SelValue);
xslProc.transform;
xslProc.output;
}
</script>

Here is my xslt file.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lc="http://mark/DevelopmentWebsite">
<xsl:eek:utput method="html"/>
<xsl:param name="Title"/>
<xsl:template match="/">

<h2>My Game Collection</h2>
<table border="1">
<xsl:for-each select="lc:Entertainment/lc:GameList[lc:Title =
$Title]">
<tr>
<th colspan="2"><xsl:value-of select="lc:Title"/></th>
</tr>
<tr>
<td>
<xsl:element name="IMG">
<xsl:attribute name="SRC">
<xsl:value-of select="lc:Image"/>
</xsl:attribute>
</xsl:element>
</td>
<td><xsl:value-of select="lc:Description"/></td>
</tr>
</xsl:for-each>
</table>

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

Dimitre Novatchev

I don't see how you use the result from the transformation. There must be
some code that displays the result of the transformation -- e.g. assignment
to the "innerHTML" property of some html objext.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
M

Mark Constant

Dimitre Novatchev said:
I don't see how you use the result from the transformation. There must be
some code that displays the result of the transformation -- e.g. assignment
to the "innerHTML" property of some html objext.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL



Mark Constant said:
I have a drop-down list now and I got it so when something is selected
from the drop down list it calls a JavaScript function. I want it so
the value selected from the drop-down list is sent as a parameter to
the xslt file. When I select a value from the drop-down list nothing
appears. I want just a basic listing of Title, Image, and Description
outputed. I have done a basic JavaScript that uses the .write()
function and that worked so the value is getting sent to the
JavaScript function from the drop-down list. So the problem has to be
with the .addParameter function. What could I be missing?

Here is my javascript and drop-down menu.
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<SELECT name="select1" onchange='CallXML(this.form.select1);'>
<OPTION value="Ratchet and Clank">Ratchet and Clank</OPTION>
<OPTION value="Sly Cooper">Sly Cooper</OPTION>
</SELECT>
</form>
</body>




<script language="javascript">
function CallXML(dropdown)
{
var myindex = dropdown.selectedIndex;
var SelValue = dropdown.options[myindex].value;
xml = new ActiveXObject("Msxml2.DOMDocument.4.0");
xml.async = false;
xml.load("Games.xml");
xslt = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
xslt.async = false;
xslt.load("Games.xslt");
xslTemp = new ActiveXObject("Msxml2.XSLTemplate.4.0");
xslTemp.stylesheet = xslt;
var xslProc = xslTemp.createProcessor();
xslProc.input = xml;
xslProc.addParameter(Title, SelValue);
xslProc.transform;
xslProc.output;
}
</script>

Here is my xslt file.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lc="http://mark/DevelopmentWebsite">
<xsl:eek:utput method="html"/>
<xsl:param name="Title"/>
<xsl:template match="/">

<h2>My Game Collection</h2>
<table border="1">
<xsl:for-each select="lc:Entertainment/lc:GameList[lc:Title =
$Title]">
<tr>
<th colspan="2"><xsl:value-of select="lc:Title"/></th>
</tr>
<tr>
<td>
<xsl:element name="IMG">
<xsl:attribute name="SRC">
<xsl:value-of select="lc:Image"/>
</xsl:attribute>
</xsl:element>
</td>
<td><xsl:value-of select="lc:Description"/></td>
</tr>
</xsl:for-each>
</table>

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

Even if I change the line xslProc.output; to Title.innerHTML =
xslProc.output nothing happens.
 
D

Dimitre Novatchev

Even if I change the line xslProc.output; to Title.innerHTML =
xslProc.output nothing happens.

So, what is your complete example?

I'd recommend that you have a look at the examples from the MSXML SDK and
try them, like this one:

<HTML>
<HEAD>
<TITLE>sample</TITLE>
<SCRIPT language = "javascript">
function init()
{
var srcTree = new ActiveXObject("Msxml2.DOMDocument.4.0");
srcTree.async=false;
srcTree.load("hello.xml");

var xsltTree= new ActiveXObject("Msxml2.DOMDOCUMENT.4.0");
xsltTree.async = false;
xsltTree.load("hello.xsl");

resTree.innerHTML = srcTree.transformNode(xsltTree);
}
</SCRIPT>
</HEAD>

<BODY onload = "init()" >
<div id="resTree"></div>
</BODY>

</HTML>You can incrementally add your code step by step, until you get your
application working.=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
M

Mark Constant

Dimitre Novatchev said:
I am sorry for not including all of my code. Like I said all I want is
if the user chooses All then it will display everything. If the user
chooses a Title then it only displays the title they want. I thought I
could do this by using a <xsl:choose> statement that looks first to
see if the selected value was All and if not it would call the
<xsl:eek:therwise> statement and just display the title that the user
selected.

Games.xslt
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lc="http://mark/DevelopmentWebsite">
<xsl:eek:utput method="html"/>
<xsl:param name="Title"/>
<xsl:template match="/">

<h2>My Game Collection</h2>
<table border="0">
<xsl:choose>
<xsl:when test="$Title = 'All'">
<xsl:for-each select="lc:Entertainment/lc:GameList">
</xsl:when>

This is non-well-formed XML! The xsl:for-each element above has no ending
tag.

Correct the code and then it may run.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


<xsl:eek:therwise>
<xsl:for-each select="lc:Entertainment/lc:GameList[lc:Title =
$Title]">
</xsl:eek:therwise>
</xsl:choose>
<tr>
<th colspan="2" bgcolor="Green"><xsl:value-of
select="lc:Title"/></th>
</tr>
<tr>
<td>
<xsl:element name="IMG">
<xsl:attribute name="SRC">
<xsl:value-of select="lc:Image"/>
</xsl:attribute>
</xsl:element>
</td>
<td><xsl:value-of select="lc:Description"/></td>
</tr>
</xsl:for-each>
</table>

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

Here is my Games.xml file
<?xml version="1.0" encoding="utf-8" ?>
<Entertainment xmlns="http://mark/DevelopmentWebsite">
<GameList>
<ID>1</ID>
<Console>PS2</Console>
<Title>Sly Cooper</Title>
<Description>A witty game that is fun for everybody</Description>
<Image>images\SlyCooper.jpg</Image>
</GameList>
<GameList>
<ID>2</ID>
<Console>PS2</Console>
<Title>Ratchet and Clank</Title>
<Description>Fun</Description>
</GameList>
</Entertainment>

And here is the Javascript function in my HTML
<script language="javascript">
function CallXML(dropdown)
{
var myIndex = dropdown.selectedIndex;
var SelValue = dropdown.options[myIndex].value;
var xsltTree = new
ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
xsltTree.async = false;
xsltTree.load("Games.xslt")

var srcTree = new ActiveXObject("Msxml2.DOMDocument.4.0");
srcTree.async = false;
srcTree.load("Games.xml");

var xsltThread = new ActiveXObject("Msxml2.XSLTemplate.4.0");
xsltThread.stylesheet = xsltTree;
var xsltProc = xsltThread.createProcessor();
xsltProc.input = srcTree;
xsltProc.addParameter("Title", SelValue);

xsltProc.transform();
resTree.innerHTML = xsltProc.output;
}
</script>


I corrected the problem and everything works!! Within my <xsl:choose>
statement I used <xsl:call-template> and from there just called
different templates depending on if they selected a genre or all.
Thank you for all your help. The absolute last thing I was thinking
about doing was pagination. Do you have any websites or suggestions
for where I could read about pagination?
 
D

Dimitre Novatchev

I corrected the problem and everything works!! Within my said:
statement I used <xsl:call-template> and from there just called
different templates depending on if they selected a genre or all.
Thank you for all your help. The absolute last thing I was thinking
about doing was pagination. Do you have any websites or suggestions
for where I could read about pagination?

Yes, see the XSLT FAQ at:

http://dpawson.co.uk/xsl/index.html


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top