views:

33

answers:

1

Hi All, I have a javascript variable something like:

var str = "AA,BB,CC,AA,BB,DD";
        var totlength = str.split(",").length;
        var xx = str.split(",");
        for (var i = 0; i < totlength; i++) {
            alert(xx[i]);   

        }

and I could print this value using above method.Now the problem is I have to craete one <ul><li> structure using xslt and <li> should get populated with this js values. so the structure will be something like-

<ul>
<li>AA</li>
<li>BB</li>
<li>CC</li>
<li>AA</li>
</ul>

so the stucture will be in xslt and value will come from js, and i am writing this ina xslt file (no separate js file).How to achieve this.

A: 

There is no link with XLT in this case; I guess you can achieve what you want with something like:

<xsl:template match="LIST">
  <div id="myDiv">
    <script type="text/javascript">

    var str = "<xsl:value-of select="."/>";

    var list = document.createElement("ul");
    var totlength = str.split(",").length;
    var xx = str.split(",");
    for (var i = 0; i < totlength; i++) {
        var li = document.createElement("li") ;
        li.appendChild(document.createTextNode(xx[i])) ;    
        list.appendChild(li);
    }
    document.getElementById("myDiv").appendChild(list);
    </script>
  </div>
</xsl:template>

with the XML file containing the LIST markup:

<LIST>AA,BB,CC</LIST>
Kevin
this is simple javascript.
Wondering
@Wondering what about this one? or do you mean that you want to get rid of the JS script, and want to build you're list only with XSLT?
Kevin
yes, <ul><li> will be in xslt, values will be from js
Wondering
@Wondering: You can pass parameters to XSLT stylesheet with javascript. In this case just the string (in case there is no posiblity to get this from some XML resource...) Then tokenize and transform with XSLT. Search about passing parameter with your target browsers, and XSLT tokenize.
Alejandro