How to pass js var in xslt
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 cou开发者_如何学Cld 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.
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>
精彩评论