2012-11-23 41 views
1

我想用下面XSLT是例获取输入费尔德值:如何使用XSLT获取输入字段值?

例子:http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=tryxsl_if

,并替换为下面的XSLT代码,

<?xml version="1.0" encoding="ISO-8859-1"?> 
<!-- Edited by XMLSpy® --> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> 
<xsl:template match="/"> 
    <html> 
    <body> 
    <input type="text" name="testTextBox" value="testValue"/> 
    value here -->> <xsl:value-of select=".//x:TextBox[@Name = 'testTextBox']" /> 
    <h2>My CD Collection</h2> 
    <table border="1"> 
     <tr bgcolor="#9acd32"> 
     <th>Title</th> 
     <th>Artist</th> 
    </tr> 
    <xsl:for-each select="catalog/cd"> 
    <xsl:if test="price>10"> 
     <tr> 
     <td><xsl:value-of select="title"/></td> 
     <td><xsl:value-of select="artist"/></td> 
    </tr> 
    </xsl:if> 
    </xsl:for-each> 
    </table> 
    </body> 
    </html> 
</xsl:template> 
</xsl:stylesheet> 

那么下面你将看到输入字段 - 所以我的要求是这样的:

  • 什么文本用户在输入字段中写我想显示值使用g输入栏前面的XLT。

感谢 苏希尔

+0

有益尝试初学者虽然,所以+1 –

+1

请,包括源XML文档(不只是重定向),并指定确切想从转型的结果。 w3schools不是一个很好的XSLT学习网站 - 看看为什么在这里:http:www.w3fools.com –

+0

Dimitre是对的! @Sushil,我已经做了小版本的代码,它将从文本框中复制文本到跨区域..但是我恐怕它不能在W3Schools中尝试它的窗口.. –

回答

1

不可能的XSLT。这是你正在寻找的DOM,可能你应该去浏览器脚本像Javascript!

<?xml version="1.0" encoding="iso-8859-1"?> 
<!-- Edited by XMLSpy® --> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> 
    <xsl:output method="html"/> 
    <xsl:template match="/"> 
     <html> 
     <head> 
      <script language="javascript" type="text/javascript"> 
      function copytext() 
      { 
      document.getElementById("copytext").innerHTML=document.getElementById("inputText").value; 
      } 
      </script> 
     </head> 
     <body onload="copytext()"> 
      <input id="inputText" type="text" name="testTextBox" value="testValue" onkeydown="copytext()"/> 
      value here -->> <span id="copytext"/> 
      <h2>My CD Collection</h2> 
      <table border="1"> 
      <tr bgcolor="#9acd32"> 
       <th>Title</th> 
       <th>Artist</th> 
      </tr> 
      <xsl:for-each select="catalog/cd"> 
       <xsl:if test="price>10"> 
       <tr> 
        <td> 
        <xsl:value-of select="title"/> 
        </td> 
        <td> 
        <xsl:value-of select="artist"/> 
        </td> 
       </tr> 
       </xsl:if> 
      </xsl:for-each> 
      </table> 
     </body> 
     </html> 
    </xsl:template> 
    </xsl:stylesheet> 
+0

同时,我会尝试使用javascript结束并让你知道。 –

+0

非常感谢:) –

+0

@SushilRaghav,这不适用于w3schools ..他们禁用了脚本! –

相关问题