2010-10-29 85 views
0

问题摘要:为使下列xslt文档有效,必须做出哪些更改。如何在html属性内插入带有javascript属性的XSLT元素?

以下是我试图修改Gizmox WebGUI DataGrid控件的主题文档的简化版本。我遇到的问题是按钮元素上的可怕的onclick事件属性。我已经用这种方法尝试了代码,并用&quot;代替"作为属性引号。在这两种情况下,文件都没有验证。我可以在javascript方法中完成一些工作,并且可能在完成之前完成,但在这种情况下,我仍然需要传递值<xsl:value-of select="@Attr.TotalPages"/>作为参数。

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:WC="wgcontrols"> 
    <xsl:template name="tplListDrawPaging"> 
    <table border="0" cellpadding="0" cellspacing="0" class="List-PagingPanel" dir="{$dir}" align="center"> 
     <tr> 
      <td width="150px" align="right" class="Common-FontData" dir="ltr"> 
       <span>Go to page:</span> 
       <input type="text" id="{@Id}-goToPageTextBox" name="{@Id}-goToPageTextBox" style="width:35px;" /> 
       <button type="button" onclick="var goToValue = getElementById('{@Id}-goToPageTextBox').value; 
             if(goToValue &lt;= 0){goToValue = 1;} 
             else if(goToValue &gt; <xsl:value-of select="@Attr.TotalPages"/>){goToValue = <xsl:value-of select="@Attr.TotalPages"/>;}) 
             List_NavigateTo('{@Id}',goToValue);">Go</button> 
     </td> 
     </tr> 
    </table> 
    </xsl:template> 
</xsl:stylesheet> 

回答

3

你必须escape the curly braces表达里面被他们加倍:

<button type="button" onclick="var goToValue = document.getElementById('{@Id}-goToPageTextBox').value; if (goToValue &lt;= 0) {{ goToValue = 1; }} else if (goToValue &gt; {@Attr.TotalPages}) {{ goToValue = {@Attr.TotalPages}; }} List_NavigateTo('{@Id}', goToValue);">Go</button> 

我一定会把这些代码自身的函数中,并调用从onclick处理器,虽然。

+0

+1好答案。 – 2010-10-29 15:17:43

+0

感谢您的快速响应。我不知道select =“@ Attr.TotalPages”/>和{@ Attr.TotalPages}的 2010-10-29 15:22:52