xsl-list
[Top] [All Lists]

[xsl] How to use a JavaScript variable in an XSL template?

2010-12-26 15:31:43

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[(_at_)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[(_at_)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
--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>