Background: I need to use XSLT 2.0 within the web browser to execute another XSLT 2.0 transform - this is to be used in a test-driver for the XSLT processor. The JavaScript API for the processor lets you build a literal command object that is passed as a parameter to a run function to execute the transform.
Building the command object is quite straightforward from JavaScript, but from XSLT I need to use built-in JavaScript extensions with user-defined JavaScript functions to convert XSLT data into a JavaScript object. There's an issue in that XPath 2.0 works with sequences of items, but sequences of sequences are not permitted. The approach I’m currently using is shown in the following XSLT snippet which declares a variable, cmd:

The equivalent JavaScript is shown below, for reference:
var cmd= {
initialTemplate: initialTemplate,
stylesheet: stylesheet,
source: 'uk-maps.xml',
parameters: {
country: 'UK',
city: 'Cheltenham',
color: [28, 329, 767]
}
};
When crossing into JavaScript, the XSLT processor converts the sequence to an array of JavaScript objects. The user-defined JavaScript function js:object processes the array and creates properties for the odd items and asigns property values from the corresponding even items. The js:object function can be called recursively to assign JavaScript objects to properties of the new object. My other workaround is the user-defined js:array function, this wraps an XPath sequence in a JavaScript object to allow it to be embedded as a sequence item. The js:object function must detect and unwrap these js:array objects.
So, the question is: this is one way to build a JavaScript literal object from within XSLT 2.0, but it involves some workarounds that might no suit everyone. What other methods could be used? Perhaps I should use an existing JavaScript library function that converts XML to a literal JavaScript object? Would XSLT 3.0 maps (not yet available in this processor) provide a better solution? What progress has been made on the proposed JSON / XSLT compatibility features? Would it be better if js:object and js:array were extension functions built into the processor?
eval()function on this string -- as described here: json.org/js.html - Dimitre Novatchev