I have an XML catalog data and an XSL file to visualize this catalog data. I use this line to validate XML.
<?xml-stylesheet type="text/xsl" href="presentation-list-catalog.xsl"?>
This part works great.
I’d like to have a secret link for designers, or somehow I need to validate XML using another XSL file. Basically I need to only change the link to the XSL file:
<?xml-stylesheet type="text/xsl" href="download-links-catalog.xsl"?>
This XSL file is another visualisation of the XML catalog data so that designers will be able to download hi-res catalog pictures. For this purpose, I would like to use the same XML, but converted using another custom XSL file.
Is it possible to specify a custom XSL file using an HTTP request like:
http://example.com/catalog.xml?download-links-catalog.xsl
What are the possible solutions?
If you’re using PHP, one solution is the following:
You can port this idea to other server-side scripts, such as Ruby, ASP, JSP, etc.
catalog.xml
In
catalog.xml, instead of pointing to an XSL file, point to a PHP file. In this example, the PHP file iscatalog.php.catalog.php
catalog.phpserves up the correct XSL file based upon the referral URL.For brevity, this example doesn’t include some security checks. For example, you should validate that
$queryis in actuality an XSL file. If this check isn’t made, then hackers could access arbitrary files on your server.presentation-list-catalog.xsl
There’s nothing strange about this XSL file. Note that the text within the
h2tags isPresentation List Catalog.download-links-catalog.xsl
This XSL file is the same as
presentation-list-catalog.xslexcept that the text within theh2tags isDownload Links Catalog.What to Expect
Using the above setup, navigating to
http://example.com/catalog.xmlwill serve up
catalog.xmlusingpresentation-list-catalog.xsl.Navigating to
http://example.com/catalog.xml?download-links-catalog.xslwill serve up
catalog.xmlusingdownload-links-catalog.xsl.The example XML and XSL files above were taken from W3Schools’s article on “XSLT – Transformation.”