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 t开发者_如何学JAVAhe searched for string.
<script language="text/javascript">
var strName;
function nameDetails()
{var strName = getElementById("txtField1").value;}
</script>
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.
The content of you question doesn't seem to bear any relation to XSL. My guess is you are looking for a way to pass a parameter to the processing of an XSL. My answer in this question may well provide some clues. IF you can clarify your question with more detail then perhaps a more specific example can be formulated.
As anthony pointed out, I think you want to use a parameter with your stylesheet so that you can pass in the value to match on.
Using your stylesheet, I added the param "author", which you can pass in any value.
<?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>
Not sure how you are invoking your stylesheets, but passing a param would be something like:
xslProc.addParameter("author", strName);
精彩评论