2

I have been looking for a solution and unable to find one.

I have an xml file and xsl file that is used to transform and display the xml file. I can sort and filter the xml document through the xsl file and it works fine.

<xsl:variable name="filval" select="'720p'" />
<xsl:for-each select="Movie_Prices/price[quality=$filval]">

I would like to have a html form with a select box and onchange event associated with it that when the user changes the value of the selectbox, the value is taken and replaces the select="'720p'" in the variable or directly into the Xpath to update the results.

<Movie_Prices>  
    <price id="1" status="use">         
        <quality>720p</quality>         
        <amount currency="LKR">20</amount>  
    </price>    
    <price id="2" status="void">        
        <quality>720p</quality>         
        <amount currency="LKR">30</amount>  
    </price>    
    <price id="3" status="use">         
        <quality>1080p</quality>        
        <amount currency="LKR">40</amount>  
    </price>    
    <price id="4" status="void">        
        <quality>1080p</quality>        
        <amount currency="LKR">50</amount>  
    </price>    
    <price id="5" status="use">         
        <quality>3D</quality>       
        <amount currency="LKR">80</amount>  
    </price>    <price id="6" status="void">        
        <quality>3D</quality>       
        <amount currency="LKR">120</amount>     
    </price> 
</Movie_Prices>

is this possible? any combination of xsl or javascript would be enough as long as the result works fine. Have searched alot and did not come up with a solution.

Any help appreciated and thanks in advance

1
  • If you can manage to load the XSL dynamically (via JavaScript, perhaps) you might be able to use a global parameter and a top-level <xsl:param name="filval"> to pass the values. I'm not sure if there is a way to do that in the browser, and if there is you would have to recompile your XSLT since variable and parameter binding is part of the static context. It would probably be more efficient to alter your XML via the JavaScript DOM API. Commented May 16, 2014 at 17:47

1 Answer 1

1

Depending on how many options you have, you could simply use multiple stylesheets just holding the filvalvariable and import the rest using xsl:include:

720p.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:variable name="filval" select="'720p'" />
    <xsl:include href="main.xsl"/>
</xsl:stylesheet>

Do the same for 1080p.xsl and 3d.xsl and put all your template rules in main.xsl then select the corresponding file with the onchange of the select box with javascript.

Sign up to request clarification or add additional context in comments.

1 Comment

Having done that, how would you bind the xml to the xsl?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.