Solved

Change xsl param using javascript

Posted on 2008-06-13
6
1,096 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

617 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