Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 2nd, 2005, 11:58 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Query XML Data from XSLT Form

I'm trying to create a form in XSLT that will query data from an XML file. Since I'm transorming the XML & XSLT on the server using the transformNode method, I thought that this setup would work best for what I need:
XML File:
Code:
?xml version="1.0" encoding="UTF-8"?>
<faqs>
    <faq>
        <category>all</category>
        <question>##QUESTION##</question>
        <answer>##ANSWER##</answer>
    </faq>
    <faq>
        <category>Category 1</category>
        <question>##QUESTION##</question>
        <answer>##ANSWER##</answer>
    </faq>
    <faq>
        <category>Category 2</category>
        <question>##QUESTION##</question>
        <answer>##ANSWER##</answer>
    </faq>
    <faq>
        <category>Category 3</category>
        <question>##QUESTION##</question>
        <answer>##ANSWER##</answer>
    </faq>
</faqs>
XSLT File:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>

<xsl:param name="selectcategory" select="'all'" />
<xsl:param name="txtkeyword" select="''"/>
    <xsl:template match="/">
        <form name="faqsearch" action="THISPAGE.ASPX" method="get">
                <table class="navyblueborder" width="100%">
                    <tr bgcolor="#333366">
                        <td colspan="2"><h6>FAQ's Search</h6></td>
                    </tr>
                    <tr bgcolor="#9999cc">
                        <td width="50%"><strong>By Department</strong></td>
                        <td width="50%"><strong>By Keyword</strong></td>
                    </tr>
                    <tr>
                        <td>
                            <select name="bydept">
                                <option value="" selected="true">- Select a Category -</option>
                                <option value="all">General</option>                                                    <option value="cat1">Category 1</option>
                                <option value="cat2">Category 2</option>
                                <option value="cat3">Category 3</option>
                            </select>
                            <input class="button" type="submit" name="submit" />
                        </td>
                        <td>
                            <input type="text" name="bykeyword" />
                            <input class="button" type="submit" name="submit" />
                        </td>
                    </tr>
                    <tr bgcolor="#9999cc">
                        <td colspan="2"><strong>Questions</strong></td>
                    </tr>
                    <xsl:for-each select="faqs/faq">
                        <xsl:sort select="question" data-type="text" order="ascending" />
                        <xsl:if test="category = $selectcategory">

                            <tr>
                                <xsl:if test="position() mod 2 != 1">
                                    <xsl:attribute name="style">background-color:#ccccff</xsl:attribute>
                                </xsl:if>
                                <td colspan="2"><a href="#"><xsl:value-of select="question" /></a></td>
                            </tr>
                        </xsl:if>
                    </xsl:for-each>
                </table>
            </form>


ASP.NET File:
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="true" %>
<%@ OutputCache Duration="10" VaryByParam="*" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Xml" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
'Pull in form data and assign to parameter
If Not Page.IsPostBack then

    Dim category_form = Request.Form("selectcategory")
    Dim keyword_form = Request.Form("txtkeyword")

    Dim category
    category = xsl.selectSingleNode("//xsl:param[@name='selectcategory']")
    category.SetAttribute("select", "'" & category_form & "'")

    Dim keyword
    keyword = xsl.selectSingleNode("//xsl:param[@name='txtkeyword']")
    keyword.SetAttribute("select", "'" & keyword_form & "'")

End If

'Declare XML and XSL file paths
Dim xmlURL As String, xslURL As String
xmlURL = "THISFILE.xml"
xslURL = "THISFILE.xsl"

'Load XML
'Dim xml = Server.CreateObject("Microsoft.XMLDOM")
Dim xml = Server.CreateObject("MSXML.DOMDocument")
xml.async = false
xml.load(xmlURL)

'Load XSL
'Dim xsl = Server.CreateObject("Microsoft.XMLDOM")
Dim xsl = Server.CreateObject("MSXML.DOMDocument")
xsl.async = false
xsl.load(xslURL)

'Transform file
Response.Write(xml.transformNode(xsl))
%>
My problem is that the XSLT parameter is not being reset to the newly entered parameter from the user. It's just keeping the original parameter value (all) whenever the form is submitted. I'm sure that the problem likely lies in either the "action" property for the form, or in the submit button's properties.

So I'd like some advice on what I need to do to complete my setup. I'd also love to hear whether or not there are other simple solutions for accomplishing the same thing. Is there a way to create an input form in XSLT that doesn't need any scripting? If so, how should I go about it? Thanks.

P.S. I'm currently using XSLT 1.0.

KWilliams
 
Old December 3rd, 2005, 06:14 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Maybe because the second time you call the page it is a PostBack so the code that sets the category is not run.

Try removing the "If Not Page.IsPostBack" check.

--

Joe (Microsoft MVP - XML)




Similar Threads
Thread Thread Starter Forum Replies Last Post
how to populate a table with xml data in xslt miccipynewbie XSLT 6 May 28th, 2007 07:29 AM
Transforming XML data in an ASP file using XSLT hussainm Classic ASP XML 0 May 31st, 2006 03:21 PM
constructing a HTML table from xml data using xslt rameshnarayan XSLT 0 September 19th, 2005 06:53 AM
using 2 sets of xml data from 1 xslt davepass XSLT 2 April 1st, 2005 06:31 PM
HELP ME PLEASE!!! XML to XSLT FORM GEN elysio XSLT 1 November 15th, 2003 05:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.