0

I have the following XSLT file at the moment

  <xsl:template match="/">
    <html>
      <head>

      </head>
      <body>
        <input type="text" id="txtSearch"/>
        <input type="submit" name="btnSearch" value="Search" onclick="" />

        <br />
        <br />
        <!-- Call to the procedure/function -->
        <xsl:apply-templates select="CommercialClients">
        </xsl:apply-templates>        
      </body>
    </html>
  </xsl:template>

  <!-- Procedure/function -->
  <!-- Loop through each AClient and retrieve CompanyName-->
  <xsl:template match="CommercialClients">
    <xsl:for-each select="AClient[starts-with(CompanyName,'L')]">
      <xsl:sort select="CompanyName" order="ascending"/>
        <xsl:value-of select="CompanyName"/>
        <br />
    </xsl:for-each>
  </xsl:template>

And I also have an XML document which goes with it like this:

<CommercialClients>
<AClient>
<ClientNo>1813</ClientNo><CompanyName>K Plastics</CompanyName><FullAddress>
  <Address>Cleveragh Industrial Estate </Address>
  <Town>SLIGO</Town>
  <Country>IRELAND</Country>
  <PostCode>00353 7166</PostCode>
</FullAddress><TelephoneNo/>
</AClient>

My problem: I want to use the button I have made so that when the user clicks the button, it takes in the user's input from the textbox and filters the data to display.

So if the user enters into the textbox "L", it will only display companies beginning with the letter "L". At the moment it is hard coded to only display companies with "L" and I am unsure of how to make it user defined.

Any help or ideas? Here is the ASPX file but I have no idea how to use all of this to edit the filter!

//from the request object get the value of the filter
string AFilter = Request.QueryString["txtFilter"];
//if there is no filter
if (AFilter == null)
{
    //make the filter a blank string (a null value will crash the program)
    AFilter = "";
}
//create an instance of the XML Conduit class passing the name of the xml file to the constructor
MyClassLibrary.clsXMLConduit MyXMLConduit = new MyClassLibrary.clsXMLConduit("commercial.xml");
//add a parameter to filter the data on company name
MyXMLConduit.AddParameter("CompanyFilter", AFilter);
//perform the transformation using the xslt file commercial.xslt
MyXMLConduit.Execute("commercial.xslt");
//set the character set encoding for the output stream
Response.Charset = "UTF-8";
//output the transformed document to the requesting browser
Response.Write(MyXMLConduit.TransformedOutput);
1
  • Tried calling the procedure within the onclick function of the button but no luck Commented Aug 7, 2012 at 0:32

1 Answer 1

1

It looks like in your ASP.Net code, you are at least passing the filter value as a parameter to the XSLT

MyXMLConduit.AddParameter("CompanyFilter", AFilter); 

In which case you need to declare the parameter within the XSLT itself. This would go at the top of the XSLT stylesheet, outside of any xsl:template element

<xsl:param name="CompanyFilter" />

If you wanted, you could give it a default value

<xsl:param name="CompanyFilter" select="'L'" />

Then, to use it instead of doing any hard-coding, it would be just like using a normal variable (prefixed with a $symbol)

<xsl:for-each select="AClient[starts-with(CompanyName, $CompanyFilter)]">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.