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

Re: How to use a JavaScript variable in an XSL templat

Subject: Re: How to use a JavaScript variable in an XSL template?
From: Ryan Scott Bardsley <bardsley@xxxxxxxxx>
Date: Sun, 26 Dec 2010 18:12:04 -0500
Re:  How to use a JavaScript variable in an XSL templat
Hi Michael, thanks, that is very helpful. Is there a way to read a variable
stored using the HTML5 local storage model and XSLT? Any examples for invoking
an XSLT transformation from JavaScript?

You are correct, I am not doing it the way you suggested. I am open to any
suggestion on how it can be done better! The majority of the site is in HTML5
and uses JavaScript to read a million localStorage variables.

My problem is with a single case. Argh.

Thanks!

Ryan


On Dec 26, 2010, at 5:10 PM, Michael Kay wrote:

> You need to understand the processing model.
>
> XSLT is used to generate HTML from the XML.
>
> Then the user interacts with the generated HTML and Javascript gets invoked
to process the resulting events.
>
> By the time the Javascript executes, the XSLT has finished its job and is no
longer active.
>
> If you want XSLT code to respond to user input, you can do this, but it
involves invoking the XSLT transformation from the Javascript code that
handles the user event. This doesn't seem to be what you are doing.
>
> Michael Kay
> Saxonica
>
>
> On 26/12/2010 21:31, Ryan Scott Bardsley wrote:
>> Hello, this is my first post and I am somewhat new to XSL. I am trying to
do the following:
>>
>> 1) Use XSL to parse an XML file and build an HTML table of data retrieved
from the XML file.
>> 2) I am using an HTML5 localStorage variable to determine which "type" of
user the user selects from a previous combo box. Once selected in the combo
box, this variable is written out with JavaScript.
>> 3) My XSL template will check this variable and parse the XML according to
what "type" of user is selected.
>>
>> Here is the XLS headers I am using:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:set="http://exslt.org/sets" exclude-result-prefixes="set">
>>
>> And here is my dream code:
>>
>> <xsl:for-each select="user[@type='JAVASCRIPT_VARIABLE']">
>>
>> I can't get the syntax for the above line of code to work. I have the
JavaScript working alone. I have the XSL working when I hardcode
JAVASCRIPT_VARIABLE to be equal to the userType that is stored. But I can't
get the XSL syntax right to allow me to swap in a JavaScript variable into a
line of XSL code.
>>
>> This works fine:
>> <xsl:for-each select="user[@type='novice']">
>>
>> Basically, I need to replace "novice" with whatever the JavaScript function
returns. It could be novice, advanced, or expert.
>>
>> Any ideas? Thank you in advance for your help. I couldn't find anything in
the archives that worked. Trust me, I am on day three of trying to fix a
single line of code. :)
>>
>> Ryan
>> Cambridge, MA

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.