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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Parameter from URL String

Status
Not open for further replies.

Angel2228

Programmer
Feb 22, 2001
26
0
0
US
I was wondering if it is at all possible to pass a value into an XSLT file from a URL string. I read in some thread that I can use the <xsl:param />, but I am not familiar with this element. Can anyone give examples? This has to be client side.

Thanks!!
Angel
 
If it has to be client-side you must have IE 6.0 or have msxml 3.0 installed in replace mode. Earlier versions don't support the param element.

In your stylesheet you can then define a param element directly beneath the stylesheet element:
Code:
<xsl:stylesheet etc, etc, etc>
  <xsl:param name=&quot;FamilyName&quot;>Default value</xsl:param>

<xsl:template match=&quot;/&quot;>
 This is the family <xsl:value-of select=&quot;$FamilyName&quot;/>
</xsl:template>

</xsl:stylesheet>
[\code]

If you have a xml file with in it a link to the stylesheet you can now pass the parameter using the following syntax:

(assuming your xml file is called myxml.xml)
myxml.xml?FamilyName=Reineman

If you use scripting and objects, then you will have to use the XSLTemplate object and the IXSLProcessor object.

Good luck!

Jordi Reineman
Cap Gemini Ernst & Young
 
I've tried the above, but I can't get it to work. I've got a form in an HTML that has a textfield named projectName and a person types in a value. On submiting the form to my XML file, the stylesheet just displays the default parameter value. Here are my files.

My HTML file.
<form action=&quot;archive.xml&quot; method=&quot;GET&quot; name=&quot;searchForm&quot;>
Name:<input type=&quot;text&quot; name=&quot;projectName&quot; width=&quot;150&quot;/>
<input type=&quot;submit&quot; name=&quot;submitButton&quot; value=&quot;Find It&quot; />
</form>


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;html&quot; indent=&quot;yes&quot; omit-xml-declaration=&quot;yes&quot;/>
<xsl:param name=&quot;projectName&quot;>Default value</xsl:param>

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

<html xmlns=&quot;
<head></head>

<body>

<xsl:apply-templates />

</body>
</html>


</xsl:template>

<xsl:template match=&quot;cabinet&quot;>
<xsl:value-of select=&quot;$projectName&quot; /><br />
</xsl:template>

</xsl:stylesheet>
 
Well, I've retried doing this and still can't get it to work. I'm using 3 files:
1)HTML file with form and javascript
2)XML file
3)XSL file

---Stylesheet------

<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot;>
<xsl:param name=&quot;projectName&quot;>Default value</xsl:param>

<xsl:eek:utput method=&quot;html&quot; indent=&quot;yes&quot; omit-xml-declaration=&quot;yes&quot;/>

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

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

<body>
Project Name = <xsl:value-of select=&quot;$projectName&quot;/>
</body>
</html>


</xsl:template>


</xsl:stylesheet>


------HTML--------

<html>
<head>
<title>Archive Search Page</title>
<script language=&quot;JavaScript&quot;>
var xslt = new ActiveXObject(&quot;Msxml2.XSLTemplate.4.0&quot;)
var xslDoc = new ActiveXObject(&quot;Msxml2.FreeThreadedDOMDocument.4.0&quot;)
var xslProc;
xslDoc.async = false;
xslDoc.load(&quot;archive search.xsl&quot;);
xslt.stylesheet = xslDoc;
var xmlDoc = new ActiveXObject(&quot;Msxml2.DOMDocument.4.0&quot;);
xmlDoc.async = false;
xmlDoc.load(&quot;archive.xml&quot;);

function getName() {
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
pName = searchForm.projectName.value
xslProc.addParameter(&quot;projectName&quot;, pName);
xslProc.transform();

}


</script>
</script>
</head>
<body>

<form name=&quot;searchForm&quot;>
Name:<input type=&quot;text&quot; name=&quot;projectName&quot; width=&quot;150&quot;/>
<input type=&quot;button&quot; onClick=&quot;getName()&quot; name=&quot;submitButton&quot; value=&quot;Find It&quot; />
</form>

</body>
</html>


---------XML-----------

<?xml version=&quot;1.0&quot;?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;./archive search.xsl&quot;?>
<archive name=&quot;Engineering's Archive&quot;>
<cabinet type=&quot;hanging&quot; 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>
<project type=&quot;Const&quot;>
<name>Baxter Street</name>
<year>1997</year>
<pages>12</pages>
</project>
<project type=&quot;Drainage&quot;>
<name>Broadmoore Drive</name>
<year>1991</year>
<pages>3</pages>
</project>
</cabinet>
</archive>


What I'm trying to test is showing the textfield's value through XSL. I know I've been kinda annoying with this, but it's driving me nuts not figuring it out.

Robert
 
i've got it to work. I had forgot to add the xslProc.output to the window that i'm working with.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top