Using the .addParameter() function

Discussion in 'XML' started by Mark Constant, Nov 14, 2003.

  1. 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>
    Mark Constant, Nov 14, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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>
    Dimitre Novatchev, Nov 14, 2003
    #2
    1. Advertising

  3. "Dimitre Novatchev" <> wrote in message news:<bp1s5u$1icjgj$-berlin.de>...
    > 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" <> wrote in message
    > news:...
    > > 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.
    Mark Constant, Nov 15, 2003
    #3
  4. > 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
    Dimitre Novatchev, Nov 15, 2003
    #4
  5. "Dimitre Novatchev" <> wrote in message news:<bpb3p6$1mjcb8$-berlin.de>...
    > > 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?
    Mark Constant, Nov 18, 2003
    #5
  6. > 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?


    Yes, see the XSLT FAQ at:

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


    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL
    Dimitre Novatchev, Nov 18, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benny Ng
    Replies:
    3
    Views:
    970
    Benny Ng
    Sep 2, 2005
  2. James Vanns
    Replies:
    7
    Views:
    7,035
    Evan Carew
    Jan 21, 2004
  3. komal
    Replies:
    6
    Views:
    1,421
    msalters
    Jan 25, 2005
  4. Replies:
    2
    Views:
    922
    Bengt Richter
    Aug 1, 2005
  5. Giannis Papadopoulos

    Function pointer to void function and int function

    Giannis Papadopoulos, Sep 5, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,236
    Barry Schwarz
    Sep 5, 2005
Loading...

Share This Page