Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在使用JavaScript函数(其值由XSLT提供)检查条件后突出显示表单元格_Javascript_Html_Xml_Xslt - Fatal编程技术网

如何在使用JavaScript函数(其值由XSLT提供)检查条件后突出显示表单元格

如何在使用JavaScript函数(其值由XSLT提供)检查条件后突出显示表单元格,javascript,html,xml,xslt,Javascript,Html,Xml,Xslt,我不熟悉JavaScript,如果整行的值不相同,我想突出显示表行,因为我知道我使用XSLT使用循环从XML文件中提取值。我该怎么做 我想将变量compare存储在数组中。然后循环检查所有值是否相等。否则,我需要使用JavaScript突出显示该行。 这段代码不包括JavaScript,我只是不知道如何与XSLT结合使用。这里是一个将XSLT和JavaScript结合使用的现有示例 此转换生成一个带有javascript的html页面,在该页面中,按下数字按钮可生成该数字的平方: <x

我不熟悉
JavaScript
,如果整行的值不相同,我想突出显示表行,因为我知道我使用
XSLT
使用循环从
XML
文件中提取值。我该怎么做


我想将变量
compare
存储在
数组中。然后循环检查所有值是否相等。否则,我需要使用
JavaScript
突出显示该行。
这段代码不包括
JavaScript
,我只是不知道如何与
XSLT

结合使用。这里是一个将XSLT和JavaScript结合使用的现有示例

此转换生成一个带有javascript的html页面,在该页面中,按下数字按钮可生成该数字的平方:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
<!-- squareAsHTMLJS1.xml: create an HTML document with JavaScript that
     interactively computes the square of each "number" element read from 
     the source tree. -->

  <xsl:template match="/"> <!-- Set up web page -->
    <html>
      <head>
        <title>Squares</title>
         <script language="JavaScript1.2">
           function showSquare(n) {
            alert("the square is " + n*n);
           }
        </script>
        <style> <!-- Put a little CSS in -->
           body { font-family: arial,helvetica; }
           h1   { font-size: 14pt }
           p    { font-size: 10pt}
        </style>
      </head>
      <body>
        <h1>Squares</h1>
        <p>Click a button to see the square of that number.</p>
        <form>
        <xsl:apply-templates/>
        </form>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="number">
    <p><input type="button" value=" {.} " onClick="showSquare({.})"/></p>
  </xsl:template>

</xsl:stylesheet>

方格
函数showSquare(n){
警报(“正方形为“+n*n”);
}
正文{字体系列:arial,helvetica;}
h1{字体大小:14pt}
p{字体大小:10pt}
方格
单击按钮查看该数字的平方

当此转换应用于此XML文档时

<numbers>
  <number>2</number>
  <number>11</number>
  <number>100</number>  
  <number>-5</number>
</numbers>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <title>Squares</title><script language="JavaScript1.2">
           function showSquare(n) {
            alert("the square is " + n*n);
           }
        </script><style> 
           body { font-family: arial,helvetica; }
           h1   { font-size: 14pt }
           p    { font-size: 10pt}
        </style></head>
   <body>
      <h1>Squares</h1>
      <p>Click a button to see the square of that number.</p>
      <form>

         <p><input type="button" value=" 2 " onClick="showSquare(2)"></p>

         <p><input type="button" value=" 11 " onClick="showSquare(11)"></p>

         <p><input type="button" value=" 100 " onClick="showSquare(100)"></p>

         <p><input type="button" value=" -5 " onClick="showSquare(-5)"></p>

      </form>
   </body>
</html>

2.
11
100
-5
结果是

<numbers>
  <number>2</number>
  <number>11</number>
  <number>100</number>  
  <number>-5</number>
</numbers>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <title>Squares</title><script language="JavaScript1.2">
           function showSquare(n) {
            alert("the square is " + n*n);
           }
        </script><style> 
           body { font-family: arial,helvetica; }
           h1   { font-size: 14pt }
           p    { font-size: 10pt}
        </style></head>
   <body>
      <h1>Squares</h1>
      <p>Click a button to see the square of that number.</p>
      <form>

         <p><input type="button" value=" 2 " onClick="showSquare(2)"></p>

         <p><input type="button" value=" 11 " onClick="showSquare(11)"></p>

         <p><input type="button" value=" 100 " onClick="showSquare(100)"></p>

         <p><input type="button" value=" -5 " onClick="showSquare(-5)"></p>

      </form>
   </body>
</html>

方格
函数showSquare(n){
警报(“正方形为“+n*n”);
}
正文{字体系列:arial,helvetica;}
h1{字体大小:14pt}
p{字体大小:10pt}
方格
单击按钮查看该数字的平方

你可以在这里玩:

并在此处查看作者的更多解释:此样式表:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <xsl:template match="numbers">
        <html>
            <head>
                <style>.all-equal {background-color:yellow;}</style>
            </head>
            <body>
                <table>
                    <thead>
                        <tr>
                            <th>Value</th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:apply-templates>
                            <xsl:with-param name="all-equal"
                            select="not(number[1] != number[position()!=1])"/>
                        </xsl:apply-templates>
                    </tbody>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="number">
        <xsl:param name="all-equal"/>
        <tr>
            <td>
                <xsl:if test="$all-equal">
                    <xsl:attribute name="class">all-equal</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="."/>
            </td>
        </tr>
    </xsl:template>
</xsl:stylesheet>

.全部相等{背景色:黄色;}
价值
一律平等
通过此输入:

<numbers>
  <number>20</number>
  <number>20</number>
  <number>20</number>
</numbers>

20
20
20
输出:

<html>
    <head>
        <style>.all-equal {background-color:yellow;}</style>
    </head>
    <body>
        <table>
            <thead>
                <tr>
                    <th>Value</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td class="all-equal">20</td>
                </tr>
                <tr>
                    <td class="all-equal">20</td>
                </tr>
                <tr>
                    <td class="all-equal">20</td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

.全部相等{背景色:黄色;}
价值
20
20
20

到目前为止,您发布的XSL与javascript无关。为什么你认为你需要javascript来实现这一点?你能编辑你的问题并明确你想要达到的目标吗?发布你想看到的HTML。是的,它没有JAVASCRIPT。。我想使用javascript将变量“compare”存储在一个数组中。然后循环遍历它并检查所有值是否相等,否则我需要使用javascript突出显示该行。这段代码不包含javascript,我只是不知道如何将它与XSLT结合起来。我希望我足够清楚。谢谢..好问题(+1)。有关如何使用XSLT创建包含javascript函数的页面的示例,请参见我的答案。如果要比较的值位于某个XML树中(您没有发布任何输入示例),则可以使用td上的某个@class生成表,如果它们具有相同的值。稍后我将发布一个示例。