Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
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
Join Date: Jul 2005
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:
?xml version="1.0" encoding="UTF-8"?>
        <category>Category 1</category>
        <category>Category 2</category>
        <category>Category 3</category>
XSLT File:
<?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 bgcolor="#9999cc">
                        <td width="50%"><strong>By Department</strong></td>
                        <td width="50%"><strong>By Keyword</strong></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>
                            <input class="button" type="submit" name="submit" />
                            <input type="text" name="bykeyword" />
                            <input class="button" type="submit" name="submit" />
                    <tr bgcolor="#9999cc">
                        <td colspan="2"><strong>Questions</strong></td>
                    <xsl:for-each select="faqs/faq">
                        <xsl:sort select="question" data-type="text" order="ascending" />
                        <xsl:if test="category = $selectcategory">

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

<%@ 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

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

'Transform file
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.

Old December 3rd, 2005, 06:14 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

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.