Subject: Re: [xsl] How to obtain parameters with the xsl? From: Mike Brown <mike@xxxxxxxx> Date: Mon, 4 Nov 2002 04:37:56 -0700 (MST) |
Steve Clay wrote: > I've been struggling with this too. I have some xml which I want to display in a browser, having transformed it to html using xslt. The stylesheet needs to select just some of the data: which data exactly is known only at runtime. So ideally I'd like to pass a parameter on the url like you can do with html pages: > > (a) html like this: "http://somewhere/myhtmlpage.htm?some-param. That only "works" in the sense that it implies that a resource known locally as "/myhtmlpage.htm" on host "somewhere" might be accessible via HTTP on port 80, and you know that according to protocol, the HTTP server is going to make "some-param" available to whatever is processing the request. It's still up to the CGI app or PHP engine or whatever to make use of that info; the semantics of "some-param" are not built-in to the HTTP protocol or the URI syntax. That is, the fact that it might be URL-encoded HTML form data is not implicit. It's simply the query-part of the Request-URI, just a string. > (b) xml like this?: "file:///c:\path\filename.xml?some-param The 'file' URI scheme has no implicit protocol; it's meaning is OS-dependent. There's nothing stopping an OS from doing something with some-param, but it would be quite a leap to say "it means dissect and pass some-param as top-level params to the stylesheet(s) indicated in xml-stylesheet PIs in filename.xml". > I have managed to do this by 1) having a real html file with a body consisting of a single <div/> element, (2) loading the xml file, (3) creating a new node, (4) extracting the url parameter using the javascript "document.location.search.substring(1);", (5) setting the new node's value to this parameter and finally (5) loading the xslt, which can now access the node I just added and use it to select just the data required before assigning it to the <div> element in the body of the page. Phew! Is there an easier and more elegant way? I am 99% sure there are examples on the msdn.microsoft.com site that explain how to invoke MSXML from code. You load up an HTML page that contains VBScript or JavaScript that invokes the transformation, possibly passing in parameters. Presumably the browser makes available the URL for the script to dissect? If it doesn't, then you'll have to do the transformation on the server. There's only so much the client can do. Interpreting query data in URLs is the server's job. But I'm just guessing. It didn't take long to find the relevant part of the MSXML SDK documentation on the MSDN site... http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/xsl_advanced1_82yb.asp > On this topic Jarno.Elovirta said "Top-level xsl:param element with the same name." I wondered if this meant I could just put "<?xml-stylesheet type="text/xsl" href="Data.xslt"?> at the top of my xml file and load it in Explorer using something like (b) above but if I have a stylesheet with a parameter element at the top level MXSML v4.0 just says "Keyword xsl:stylesheet may not contain xsl:parameter." So, I'm sorry Jarno but I don't understand what you meant. Well, for one thing, he said xsl:param, not xsl:parameter. Perhaps you did type xsl:param and just forgot to use the XSLT 1.0 namespace instead of the 4 year old, never-approved WD-XSL namespace that Microsoft won't let die? Anyway, he was saying that you import the parameter in to the stylesheet by using xsl:param at the top level. <xsl:stylesheet...> <xsl:param name="foo"/> <xsl:template...> ...and so on. $foo can be used in XPath expressions therein. The trick is to tell the XSLT processor, MSXML in your case, to set foo, since it doesn't do you any good to import a parameter that hasn't been set (it'll just default to an empty string). For better answers to MSXML specific questions, ask on one of the microsoft.public newsgroups. - Mike ____________________________________________________________________________ mike j. brown | xml/xslt: http://skew.org/xml/ denver/boulder, colorado, usa | resume: http://skew.org/~mike/resume/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How to obtain parameters , Marcial Atienzar Nav | Thread | [xsl] XML-Data from JavaScript into, Johannes . Becker |
RE: [xsl] XML-Data from JavaScript , Robert Koberg | Date | Re: [xsl] accessing URL parameters , Oleg Tkachenko |
Month |