Problem with a javascript toggle switch in xsl
This is basically what I want to do:
<xsl:template match="/">
<html>
<body>
<script type="text/javascript">
function toggle(id)
{
var e = document.getElementById(id);
if (e.style.display == '')
e.style.display = 'none';
else
e.style.display = '';
}
</script>
<xsl:for-each select="s:measCollecFile/s:measData/s:measInfo">
<a href="#" onclick="toggle(s:measValue/@measObjLdn开发者_开发知识库)"><xsl:value-of select="s:measValue/@measObjLdn"/></a>
<div id="s:measValue/@measObjLdn" style="display:none">
some text.
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
My problem is that I cannot get the @value to work. If I hardcode a string instead of the @value, it works fine. So the code is esentially working.
EDIT: real path names
function toggle(ele)
{
if (ele.style.display == '')
ele.style.display = 'none';
else
ele.style.display = '';
}
Use this as current object.
<a href="#" onclick="toggle(this)">
Alterntively, use xsl:attribute to set attribute value
<a href="#" >
<xsl:attribute name="onclick">
toggle('<xsl:value-of select="@value"/>');
</xsl:attribute>
<xsl:value-of select="@value"/>
</a>
精彩评论