Solved

Change xsl param using javascript

Posted on 2008-06-13
6
1,076 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 500 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now