wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Access xsl variable between pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Access xsl variable between pages" Watch "Access xsl variable between pages" New topic
Author

Access xsl variable between pages

shanta raja
Greenhorn

Joined: Apr 01, 2010
Posts: 8
I have a dropdown in the xsl form. When I select a value from the dropdown, I would like to retain the selected value for further calculations, when the onLoad() function is called. I have tried retrieving the selected value using the onchange function and passing it to onLoad(). But the variable does not get passed. I also tried hidden variables, but nothing works. I'm not sure where I'm going wrong. The following is my code

<xsl:template .................................../>
..
..
<script type="text/javascript">
function onLoad() {
alert(document.getElementId('selectedYear').value);
}

function getSelectedYear() {
var yearOptions = document.getElementId('year').options;
selectedYear=yearOptions[yearOptions.selectedIndex].value;
dcoument.mainForm.selectedYear.value = selectedYear;
}
</script>

<table>
<tr>
<td>
<SELECT NAME="year" id="year" onchange="getSelectedYear()">
<!-- xsl:variable attribute name="selectedYear"><xsl:value-of select="year"
/></xsl:attribute>

.
.
</SELECT>

...
...

type="hidden" name="selectedYear" value="{selectedYear}" />

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

First you have to let go of the peculiar concept of an "XSL form". You don't have any such thing. You have -- if I understand your post correctly -- an XSL transformation which generates HTML. And in that HTML you have some Javascript, also generated by the transformation.

Now if I understand your post correctly, you want to pass information from that page (which is HTML, remember) via the form to the next HTML page which is displayed. So when the form is submitted, it has to include that information.

It's impossible to deal with the problem if you only display the XSLT code which generates the page. You have to look at the generated HTML and figure out how to make that HTML do what you need it to do. Then when you have done that, fix the XSLT code to generate HTML which does what you need it to do.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
There is no concept of global state in the eXtensible Stylesheet Language. Only local static variables in a single template element.
 
jQuery in Action, 2nd edition
 
subject: Access xsl variable between pages
 
Similar Threads
calling function on the basis of option value?
html:select tag with javascript function
correct Ajax script syntax for second DropDown
Show a hidden text field
INSERT THE VALUE OF A FORM FIELD INTO A JAVA STRING (without page refresh)