This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: linking stylesheet in XML document, what about .php file?
- From: Mike Brown <mike at skew dot org>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Fri, 14 Jun 2002 12:09:03 -0600 (MDT)
- Subject: Re: [xsl] linking stylesheet in XML document, what about .php file?
- Reply-to: xsl-list at lists dot mulberrytech dot com
William S. wrote:
> I would like to use one stylesheet for all my XML
> files. Apparently, I can do this by putting something
> like the following header in each XML file:
>
> <?xml-stylesheet href="mystyle.xsl" type="text/xsl"?>
>
> But how can I deal the need to use a .php file
> to make the Sablotron transformation?
No.
> Can I
> include the content of the .php file inside
> the .xsl file instead of having a .php file?
No.
Think of the xml-stylesheet processing instruction as saying this:
Dear whatever application is receiving the important content of this
document from the XML parser... I don't know if 'xml-stylesheet' means
anything to you or not, but if it does, here is something to go along
with it: 'href="mystyle.xsl" type="text/xsl"'
The semantics of xml-stylesheet, as defined by a W3C spec, are that the
stylesheet referenced in the href pseudo-attribute (it's not a real attribute,
it's just part of an opaque string that resembles attributes) is just
"associated" with the XML document containing the instruction. It is just
information; the application is not bound to any sort of contract to use the
stylesheet, nor is the application bound to use it in any particular way.
So, while it wouldn't be wrong for an application to invoke a PHP script that
initiates the transformation using the referenced stylesheet, a. this behavior
is not found in any processor, and b. it would be wrong to reference the PHP
script directly in the processing instruction, because the script itself is
not a stylesheet.
> My present setup uses the "trio" of a .php file,
> .xml file and .xls file. In order to render
> the page I must direct the browser to the .php file.
>
> It would be better if I could just direct the browser to
> the .xml file(s). That way I could have links to those
> .xml files within the web page to allow the user
> to change the content. Also I could have many .xml
> files and just one .xsl file. How do I get around
> the .php file issue?
You could direct all requests through a script (CGI or PHP) that masquerades
as a directory, if your server is configured to do fuzzy matching of path
components ("MultiViews" in Apache, IIRC). e.g. a request for
/path/to/somephp/foo.xml will result in /path/to/somephp.php being executed,
and that script can then look at the rest of the request path to figure out
that it needs to transform foo.xml.
Redirection could also work, if you don't mind the URL being rewritten. This
would be problematic for relative links in the transform result, though.
Similarly, but more work, you could configure the server to pass requests for
.xml files to a custom handler that invokes the transformation against a
particular stylesheet, possibly taking an alternate stylesheet reference from
the HTTP request's query args.
Application frameworks such as Cocoon and 4Suite have sprung up to provide
this kind of functionality without making you reinvent the wheel. But you're
probably going into unknown territory when you bring PHP into the mix. I'd go
with the MultiViews option, and hope that your PHP script can properly dissect
the request URI.
- 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