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