Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Javascript variable to xsl.....again

Status
Not open for further replies.

Endbringer

Technical User
Jan 18, 2002
28
US
I'm trying to pass a javascript result as text into a XSL variable. I'm not sure how to go about it. Any help would be appriciated.

I need something similar to this, but this doesn't work.
<xsl:variable name=&quot;searchItem&quot;>
searchForm.searchfield.value
</xsl:variable>

Thanks,
Robert
 
You could include the text in your xml, but considering that's the most logical thing to do (and you thought of it), it probably isn't an option.

Secondly you could parse a parameter to your stylesheet, similar like a querystring in html or asp:

Considering you xml file is called myxml.xml you could parse a parameter like this:

myxml.xml?searchItem=blablabla

In yopur stylesheet you must have a xsl:param element directly following your xsl:stylesheet element:
Code:
<xsl:stylesheet etc, etc, etc>
<xsl:param name=&quot;searchItem&quot;>defaultvalue</xsl:param>

Good luck!

Jordi Reineman
 
Hi jordi,

I'm still having dificulty figuring this one out. Here is a sample of my XML.

<archive>
<cabinet content=&quot;City Projects&quot; number=&quot;1&quot;>
<project type=&quot;Profiles&quot;>
<name>Ashley Street</name>
<year/>
<pages>3</pages>
</project>
<project type=&quot;Const&quot;>
<name>Baxter Street</name>
<year>1993</year>
<pages>12</pages>
</project>
</cabinet>
</archive>

What I'm trying to do is let someone type the name of a project into a text field and it search throughout my XML to display only the ones that match what was typed. I've tried using pure XSL and I'm unable to get it to work. I've dabbled a little with Javascript, but I still don't know how to do it. If there was a way to make the <input> tag value go into a XPath expression, that would be perfect, but I can't get it to work. Something like this would be perfect:

<xsl:for-each select=&quot;name[contains( $projectname,result)]&quot;>

where result is what the the person typed.

Sorry if I sound out of my league, but I know this can be done somehow.

Robert
 
Of course it can be done!

In fact it's relatively easy.

You can use a stylesheet to create the results page, but you can also use javascript and the xml DomDocument object to filter your xml.

You can't access form values from inside a stylesheet, so
if you want to use a stylesheet you will have to parse the name of the project to the stylesheet as mentioned in my previous posting.

Perhaps if you tell me how you performed your transformation using the stylesheet (did you include a reference to the stylesheet in your xml or did you use objects to perfoprm the transformation?), I can give you some samplecode.

Jordi Reineman
 
Hello again.....I've been working on other stuff so I've kinda let this one go for a while. I'm referencing the following stylesheet to display the data. Here's part of my stylesheet.

<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot;>
<xsl:eek:utput method=&quot;xml&quot; indent=&quot;yes&quot; omit-xml-declaration=&quot;yes&quot;/>

<xsl:template match=&quot;archive&quot;>

<html xmlns=&quot;<head>
<title>Engineering Archive</title>

</head>
<body>
<b>Cabinet Name: <xsl:value-of select=&quot;cabinet[1]/@content&quot;/> <xsl:value-of select=&quot;cabinet[1]/@number&quot;/></b>
<p/>

<table border=&quot;1&quot;>
<tr>
<td width=&quot;400&quot;><center><b>Project Name</b></center></td>
<td width=&quot;100&quot;><center><b>Number of Sheets</b></center></td>
<td width=&quot;25&quot;><center><b>Year</b></center></td>
</tr>


<xsl:for-each select=&quot;cabinet[1]/project&quot;>
<tr>
<td width=&quot;400&quot;><xsl:value-of select=&quot;name&quot;/></td>
<td width=&quot;100&quot;><xsl:value-of select=&quot;pages&quot;/></td>
<td width=&quot;25&quot;><xsl:value-of select=&quot;year&quot;/></td>
</tr>
<tr>
<td width=&quot;400&quot;><xsl:value-of select=&quot;name[2]&quot;/></td>
<td width=&quot;100&quot;><xsl:value-of select=&quot;pages[2]&quot;/></td>
<td width=&quot;25&quot;><xsl:value-of select=&quot;year[2]&quot;/></td>
</tr>
</xsl:for-each>
</table></body>
</html>
</xsl:template>
</xsl:stylesheet>

This is how I display what's in there, but I don't know how to make this display just the results of a search someone puts in. I'm not quite following your parameters idea, so if you could inform me a little more, I'd be much appreciative.
 
Hi Robert,

Take a look at Thread426-173302 for some further help.

Good luck!

Jordi Reineman
 
Hey! I got it working! I'm not sure what it was that I was doing wrong, but it's working now. Thanks for the help


Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top