• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1150
  • Last Modified:

Change xsl param using javascript

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
km_team
Asked:
km_team
  • 4
  • 2
1 Solution
 
hieloCommented:
>>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
 
hieloCommented:
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
 
km_teamAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hieloCommented:
>>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
 
km_teamAuthor Commented:
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
 
hieloCommented:
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now