0

这是我的 XSLT 文件:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/> 
     <xsl:template match="/">
            <xsl:for-each select="//child_4331">
              <xsl:value-of select="*"/>
              <xsl:value-of select="@value" />   
                  <xsl:attribute name="onclick">
                    <xsl:call-template name="GetOnClickJavaScript" />
                  </xsl:attribute>  
             </xsl:for-each>
      </xsl:template>
  </xsl:stylesheet>

如何在child_4331值上设置点击事件?

4

1 回答 1

1

您没有说,但我假设您要复制child_4331元素并添加onclick属性。

我会摆脱匹配' /'的模板并创建一个匹配' child_4331'。用于xsl:copy创建元素的副本并在其中添加属性。如果child_4331元素具有属性或子元素,您将要使用xsl:apply-templates它们来获取它们。

这是一个示例片段。您的解决方案可能会因您所需的输出而异。如果不知道您的源 XML 是什么样子以及您期望在结果中看到什么,我无法提供更多信息。

<xsl:template match="child_4331">
  <xsl:copy>
    <xsl:attribute name="onclick">
      <xsl:call-template name="GetOnClickJavaScript" />
    </xsl:attribute>
  </xsl:copy>  
</xsl:template>
于 2013-02-09T14:43:05.013 回答