Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Change xsl param using javascript

Posted on 2008-06-13
6
Medium Priority
?
1,117 Views
Last Modified: 2013-11-18
Hi there,

I'm trying to change the 'select' value of an 'xsl:param' tag I have at the top of an xsl. I would like it to take on the value of a variable I define elsewhere, and it seems that javascript would be the best way of doing this, as I do not have access to server side technologies, such at php or asp.

I'm trying to do this to reduce the number of xsls I'll need to produce, one for every combination needed would mean creating over 4000 files, which seems a bit much when it appears logical to change a param value, based on an aggregation of a few variables, which change depending on what the user has selected.

It would be great to know how/ whether with is possible, or if there are easier ways to solve this problem.

Thanks.
0
Comment
Question by:km_team
  • 4
  • 2
6 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 21779097
>>Change xsl param using javascript. I'm trying to change the 'select' value of an 'xsl:param' tag I have at the top of an xsl.
Javascript does not process the xsl so you cannot do that directly. You will need to post some code or provide the url to you page. Not sure what you are doing, but it sounds like you need to pass parameters to your xsl processor.
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 21779119
Look at the accepted solution here:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XSLT/Q_22940685.html

Notice how in showTable(), the parameter is being passed to the processor via:
xsltProc.setParameter('', 'stateid' , stid);
0
 

Author Comment

by:km_team
ID: 21779550
Just to make it a bit clearer, I have a parameter such as this at the top of each XSL:

<xsl:param name="selected" select="portfolio_management/content[country='Ireland' or region='Group'][lob='Motor' or lob='All'][area='PSS' or alt1a='PSS' or alt2a='PSS']" />

I'm then using: <xsl:for-each select="$selected"> inside the main template to ensure that only the records which meet the above criteria are selected.

The value of the parameter changes however, and depends on country, lob and area.  To create one XSL for each of the combinations of country, lob and area that a person could want to view, means making over 4000 XSLs.  
I'm trying to find a way to reduce the number of XSLs needed.  It would be lovely to be able to refer to the parameter outside of the XSL and change it depending on the selections a user has made, but, as ever, the simplest ideas never truly are so.  
I've had a look at Xquery, but I don't think it's quite what I'm after.  

Thanks for your help so far (I'm using sarissa at the moment to change the XSLs used with the XML in a div of my HTML)  however something a bit more specific would be wonderful.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Expert Comment

by:hielo
ID: 21779964
>>I would like it to take on the value of a variable I define elsewhere
OK, but it's not clear what that parameter would be. For the sake of argument, let's say that you want to select based on the country selection. So what you would need to do is put:
<!-- make ireland your default country name; that is what will be used if the parameter is specified -->
<param name="country" select="'ireland'"/>

then at the place where you need to "execute" the query you would use:
<xsl:param name="selected" select="portfolio_management/content[country='$country' or region='Group'][lob='Motor' or lob='All'][area='PSS' or alt1a='PSS' or alt2a='PSS']" />

but you will need to pass the parameter country to the xsl file:
xsltProc.setParameter('', 'country' , 'england');//this will override the default value in the xsl -> 'ireland'
0
 

Author Comment

by:km_team
ID: 21793202
Ahh, that's marvellous.

Just one further wonder, in that I won't always have all of the selections, eg some times it will be this:

<xsl:param name="selected" select="portfolio_management/content[country='$country' or region='Group'][lob='Motor' or lob='All'][area='PSS' or alt1a='PSS' or alt2a='PSS']" />

other times it may just be this:

<xsl:param name="selected" select="portfolio_management/content[country='$country' or region='Group']"/>

...depending on what has been selected.

Is there a catch all  that I could change the value of country to, for example, if wanting to display all countries but still filter by lob and area?
0
 
LVL 82

Expert Comment

by:hielo
ID: 21842233
You can have as many <param> as you need. There is no "catch all", but you could have/define all the necessary params that you need to determine whether a particular value/selection was made.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question