How to build variables dynamically?

Is there a way to port the following javascript to XEL

function getSelectedContentProvidersAsString() {
var cpCheckboxes = document.getElementsByName("cp");
var strSelectedContentProviders = "";
for (i=0; i<cpCheckboxes.length; i++) {
var curCpChecbox = cpCheckboxes[i];
if (curCpChecbox.checked && !curCpChecbox.disabled) {
strSelectedContentProviders+=curCpChecbox.value;
strSelectedContentProviders+=",";
}
}
return strSelectedContentProviders;
}

I want to store the return value of this function in a variable.
Currently this looks like the following:

<e:variable name="strSelectedContentProviders" select="javascript:getSelectedContentProvidersAsString()"/>

I would rather port this function to XEL for compatibility reasons and because it is a requirement to the product.

TIA,

Hi, You can XPath to do the

Hi,

You can XPath to do the same, something like:

<e:variable name="strSelectedContentProviders" select="string-join(//cp[property::checked and property::disabled]/property::value, ',')"/>

- string-join() function joins a resultset (http://www.w3.org/TR/xpath-functions/#func-string-join)
- //cp selects all CP tags in the document
- [property::checked and property::disabled] filters the resultset to only those with property checked is true and property disabled is true
- /property::value selects the actual value of the resultset and not the nodes

document.getElementsByName

document.getElementsByName returns the tags which's name attribute is the given value and i wanted the elements which are enabled (not disabled),
but i assume that the statement should look like:

<e:variable name="strSelectedContentProviders" select="string-join(//input[property::checked property::name='cp' and property::type='checkbox' and not property::disabled]/property::value, ',')"/>