【问题标题】:How does one insert XSLT elements with attributes inside of javascript inside of a html attribute?如何在 html 属性内插入带有 javascript 内属性的 XSLT 元素?
【发布时间】:2010-10-29 15:00:06
【问题描述】:

问题摘要:我必须进行哪些更改才能使以下 xslt 文档有效。

以下是我尝试为 Gizmox WebGUI DataGrid 控件修改的主题文档的简化版本。我遇到的问题是按钮元素上可怕的 onclick 事件属性。我已经以这种方式尝试了代码,并使用" 代替" 用于属性引号。在这两种情况下,该文件均不生效。我可以在 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>

【问题讨论】:

    标签: javascript html xml xslt escaping


    【解决方案1】:

    你必须在表达式中加倍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 处理程序中调用它。

    【讨论】:

    • 感谢您的快速回复。我不知道 和 {@Attr.TotalPages} 是等价的。显然,我需要复习我的 xslt。我也必须避开大括号,这绝对是有道理的。
    猜你喜欢
    • 2017-09-22
    • 1970-01-01
    • 2014-11-23
    • 2011-01-19
    • 2018-07-20
    • 2014-10-12
    • 2011-01-11
    • 1970-01-01
    • 2012-06-25
    相关资源
    最近更新 更多