0

The xsl contains function uses string values... but how can the value of the searchedforstring be assigned dynamically? It should be possible to assign the value of a text entry field in an html form to a variable and use this as the value of the searched for string in the xsl document.

The following script snippet gets the value of the text entered and assigns it to the global variable strName*. The problem is to use the value of strName in place of the searched for string.

<script language="text/javascript">
var strName;
function nameDetails()
{var strName = getElementById("txtField1").value;}
</script>
4

3 回答 3

0

Your question isn't entirely clear, but I think this might suffice.

You can assign the value to some node in your XML document, and then pick that up from your XSL (maybe assigning it into an XSL Variable or something). You can then use the XSL variable in your XSL.

Unless I have misunderstood, in which case, can you elaborate more.

于 2009-12-24T11:38:02.443 回答
0

正如 anthony 指出的那样,我认为您想在样式表中使用一个参数,以便您可以传入要匹配的值。

使用您的样式表,我添加了参数“作者”,您可以传入任何值。

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="author"/>
  <xsl:output method="html"
     omit-xml-declaration="yes"/>

  <xsl:template match="/">
    <html>
       <head>
       <title>books example</title>
       </head>

    <body>
       <xsl:apply-templates select="//book"/>
    </body>
    </html>
  </xsl:template>


  <xsl:template match="book">
       <xsl:if test="contains(author, $author)">

       <DIV>
         <I><xsl:value-of select="title"/></I> by
         <J><xsl:value-of select="author"/></J> genre
         <B><xsl:value-of select="book_genre"/></B>

       </DIV>
     </xsl:if>
  </xsl:template>
  </xsl:stylesheet>

不知道你是如何调用你的样式表,但传递一个参数会是这样的:

xslProc.addParameter("author", strName);
于 2009-12-25T15:42:02.613 回答
0

您问题的内容似乎与 XSL 没有任何关系。我的猜测是您正在寻找一种将参数传递给 XSL 处理的方法。我在这个问题上的回答可能会提供一些线索。如果您可以更详细地澄清您的问题,那么也许可以制定一个更具体的例子。

于 2009-12-24T11:57:52.500 回答