[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Javascript variable to XSL variable

Subject: Re: Javascript variable to XSL variable
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Thu, 17 Feb 2005 10:16:25 -0800
javascript variable onchange
Camalesn wrote:
On Thu, 17 Feb 2005 08:53:19 -0800, Robert Koberg wrote:


This isn't an XSL problem. You should get this working in plain HTML
first. You probably want something like:

<select name="combo1" onchange="transformSelection(this.value)">
<option value="file1.xml">Option1</option>


Well, is not as easy as it seems. ;-)

it seems like it is :)



I need the value of the combo box in order to use it as XSL variable:


<select name="combo1">
<option select="{$nodevalue}">Option1</option>
<option select="{$nodevalue}">Option2</option>
<option select="{$nodevalue}">Option3</option>
<option select="{$nodevalue}">Option4</option>
</select>

Why are you using a select attribute? Why not just:


<xsl:template match="files">
  <select name="combo1" onchange="transformSelection(this.value)">
    <xsl:apply-templates mode="create-options"/>
  </select>
</xsl:template>

<!-- I would use the same elem name for 'files' children, but -->
<xsl:template match="*" mode="create-options">
  <option value="normalize-space(.)">
    <xsl:value-of select="."/>
  </option>
</xsl:template>

This will create the dropdown. Then, when running in the browser, the user selects an option and triggers the onChange event. You send the current value of the select to a javascript function that loads the file and uses it as the XML source in a client-side transform. Use another XSL that works with this source. Place the result of the transform in some HTML div or what-have-you -- or rewrite the whole page if you need to.



Where $nodevalue is the value of one XML node.


<files>
<node1>file1.xml</node1>
<node2>file2.xml</node2>
<node3>file3.xml</node3>
<node4>file3.xml</node4>
</files>

After that, on every "onchange" event I need to display some information:

<xsl:value-of select="document('$nodevalue')/select/some/other/node/value"/>

Well, you can't communicate the onchange event to the transformation. You have to use javascript to communicate and setup another transformation. Hopefully what I wrote above makes sense.


best,
-Rob


If user selects "Option 1" in combo box, I have to load file1.xml If the user selects "Option 2 " in combo box, I have to load file2.xml, and so on.

Thanks for your ideas, they are very welcome.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.