這裏使用腳本標籤中的位置功能是完整的代碼:在XSLT
<xsl:for-each select="/*/hundreds/hundred">
<div class="page_spacer" />
<div class="page_section" style="{./style}">
<h2><xsl:value-of select="./label"/></h2>
<div id="graphDiv{position()}"></div>
<script>
var ctx = createCanvas("graphDiv{position()}");
var graph = new BarGraph(ctx);
graph.maxValue = 30;
graph.margin = 2;
graph.colors = ["#49a0d8", "#d353a0", "#ffc527", "#df4c27"];
graph.xAxisLabelArr = ["North", "East", "West", "South"];
setInterval(function() {
graph.update([Math.random() * 30, Math.random() * 30, Math.random() * 30, Math.random() * 30]);
}, 1000);
</script>
<xsl:value-of select="./descriptiontext" />
<button onclick="javascript:window.location.href='{./viewalllink}'"><xsl:value-of select="./viewalllabel" /></button>
<br/>
<xsl:for-each select="./contendors/contendor">
<a href="/location/{./locid}" ><img class="locationthumb" src="/act/locationthumb/{./locid}"/></a>
</xsl:for-each>
</div>
</xsl:for-each>
我正在尋找實現如下:
<div id="graphDiv{position()}"></div>
<script>
var ctx = createCanvas("graphDiv{position()}");
如果你看看,在我XSLT我將div
指定爲graphDiv1
,如果它位於第一位。在我的劇本中,我打電話給createCanvas function
。不幸的是,我需要將值graphDiv1
傳遞給createCanvas function
。
所以,我需要把position
放入script
那叫createCanvas
。
我確定我做的不正確,這只是我第二天使用XSLT。
這裏是我的XML
:
<hundreds>
<hundred>
<style>test</style>
<label>label</label>
<descriptiontext>something description</descriptiontext>
<viewalllink>viewurl</viewalllink>
<viewalllabel>viewurl</viewalllabel>
<contendors>
<contendor>
<locid>810</locid>
</contendor>
<contendors>
</hundred>
</hundreds>
你可以提供你的源xml嗎? –
@RashmiPandit添加 – jkushner