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 November 7th, 2006, 08:25 AM
Authorized User
 
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pre-filtering a selection list

Hi Everyone,

I have an XSL form which allows users to select the data they require from lists presented at the top of the screen. The XSLT (together with javascript) then retrieves the data and displays it in the lower half of the screen.

However, some of my lists (e.g. for 'CREDITOR') are extremely long and I would like a way to apply a pre-filter: For example the user would enter 'A' and only entries starting with A would appear.

At the end of this posting I have included two snippets of code showing how the template retrieves the Creditor code (CRED_CODE) and name (CRDTR_NAME). As you can see here I use the CODE to identify / retrieve the CREDITOR but would like the name (CRDTR_NAME) as the basis for the pre-filter.

I was considering including an empty extra text field where the user can enter one or several letters and then using the function starts-with(string1, string2) to get those entries starting with the letter or string entered by the user.

Any tips, suggestions or snippets of code would be a great help.

Regards and thanks,
Alan Searle

------------------------------------
Code Excerpt:

Template call:
<xsl:apply-templates select="/dataroot/ref_cred/CRED_CODE
   [generate-id()=generate-id(key('kdcred',.))]" mode="selectcred">
 <xsl:sort select="../CRDTR_NAME" order="ascending" data-type="text"/>
</xsl:apply-templates>

[...]
Template:
<xsl:template match="//CRED_CODE" mode="selectcred">
  <option value="{.}"><xsl:value-of select="../CRDTR_NAME"/></option>
</xsl:template>

 
Old November 7th, 2006, 08:37 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure where your problem lies. You just add a predicate to the selection:

<xsl:apply-templates select="/dataroot/ref_cred[starts-with(CRDTR_NAME, $initial]/CRED_CODE
   [generate-id()=generate-id(key('kdcred',.))]" mode="selectcred">

where $initial holds the relevant value.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 7th, 2006, 09:09 AM
Authorized User
 
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hallo Michael,

Fantastic, when I hard-coded it, it did exactly what I wanted. I tried the following ...

     select="/dataroot/ref_cred[starts-with(CRDTR_NAME, 'A')]/CRED_CODE
            [generate-id()=generate-id(key('kdcred',.))]"

... and displayed all the Creditors starting with 'A'. Excellent!

But now I am not sure how to get the value from the following field on my form ...

     <input type="text" name="credstart" />

... into a variable (e.g. $credstart) or directly into my clause.

I considered an XSL variable ...

     <xsl:variable name="credstartstore" select="cred"/>

... but that would only retrieve from the XML file (e.g. the node 'cred'), wouldn't it?

Alternatively, there is javascript syntax ...

     document.formfilt.credstart.value

... but activiting javascript just to get the value into $credstart seems a lot of overhead. But maybe that's not avoidable?

Any tips that you could give here would help me with a general understanding of how values in the HTML are passed to the XSL.

Once again many thanks,
Alan.

 
Old November 7th, 2006, 09:19 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Since you talk about the user clicking on a column heading, I assumed you had already sorted out how to fire off a client-side transformation in response to user input and to display the results. This is all Javascript stuff: collect the input value, and supply it as a parameter to the transformation using addParameter() (or is it setParameter() - depends which API you are using), which then finds its way into a top-level xsl:param declaration in the stylesheet.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 7th, 2006, 09:24 AM
Authorized User
 
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Yes, that (i.e. javascript) is the syntax that I can/will use.

I just thought there might be a way to pick it up directly from the form.

Thanks for confirming that this is the way to do it.

Cheers,
Alan.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering the list between the date range sea_aiko SharePoint Development 1 August 7th, 2008 04:21 PM
filtering files while displaying in list box anandthecoolest C# 1 March 8th, 2007 02:04 PM
filtering files while displaying in list box anandthecoolest C# 2005 0 March 8th, 2007 03:21 AM
Data List Selection Norberto_Caraballo Beginning VB 6 1 June 24th, 2006 09:41 AM
filtering data from a database using list box europhreak Dreamweaver (all versions) 4 September 25th, 2005 04:27 AM





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