Viewing one XML using multiple XSL files

Toby Newman

Usenet Archive
Joined
Jul 8, 2003
Messages
16
Reaction score
0
I started learning XML on Monday.

I have an XML file and have written an XSL file to render it to HTML for formatted viewing in a browser. I'd like to create a second alternative view of the same data. I am confused how:

If the following line, which dictates which XSL file should be used to transform my XML document for me, is found *in the XML file itself* then how can you use more than one XSL to present multiple views of the same XML document?

<?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>

Am I approaching this the wrong way?
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Toby said:
If the following line, which dictates which XSL file should be used to transform my XML document for me, is found *in the XML file itself* then how can you use more than one XSL to present multiple views of the same XML document?

<?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>

The xml-stylesheet processing instruction is modelled after the HTML link element so it should allow you (in theory) to have several such processing instructions to suggest alternative stylesheets. However in reality for XSLT stylesheet I don't think any of the major desktop browsers like IE 6 and later, Mozilla/Firefox or Opera support that. On the other hand such a processing instruction does not prevent you to use script and an XSLT processor API on the server to apply different stylesheet as you like or want.
 

Toby Newman

Usenet Archive
Joined
Jul 8, 2003
Messages
16
Reaction score
0
The xml-stylesheet processing instruction is modelled after the HTML link element so it should allow you (in theory) to have several such processing instructions to suggest alternative stylesheets. However in reality for XSLT stylesheet I don't think any of the major desktop browsers like IE 6 and later, Mozilla/Firefox or Opera support that. On the other hand such a processing instruction does not prevent you to use script and an XSLT processor API on the server to apply different stylesheet as you like or want.

Would it be possible to encode the filename of the XSL that I want to use in the URL?
Like this:

http://www.domain.com/myxml.xml?XSLT=viewOne.xsl http://www.domain.com/myxml.xml?XSLT=viewTwo.xsl

I've done this before in PHP and know how to get the variables from the URL using PHP. I'm not using PHP files now, though, I'm using XML files. XML files aren't server-side scripted, though, so can I fetch the variable somehow in from the URL within XML?
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Toby said:
Would it be possible to encode the filename of the XSL that I want to use in the URL?
Like this:

http://www.domain.com/myxml.xml?XSLT=viewOne.xsl http://www.domain.com/myxml.xml?XSLT=viewTwo.xsl

I've done this before in PHP and know how to get the variables from the URL using PHP. I'm not using PHP files now, though, I'm using XML files. XML files aren't server-side scripted, though, so can I fetch the variable somehow in from the URL within XML?

You need server-side scripting reading out the query string and running the transformation e.g. http://example.com/transform.php?xml=myxml.xml&xslt=viewOne.xsl then transform.php reads out the file names, runs the transformation and sends the transformation result to the client.
 

Toby Newman

Usenet Archive
Joined
Jul 8, 2003
Messages
16
Reaction score
0
You need server-side scripting reading out the query string and running the transformation e.g. http://example.com/transform.php?xml=myxml.xml&xslt=viewOne.xsl then transform.php reads out the file names, runs the transformation and sends the transformation result to the client.

Ack - that's a shame. I don't have PHP or ASP on the server I'm using - it's a Sharepoint server and ASP is blocked. Is there any other way?
 

Grant Robertson

Usenet Archive
Joined
Oct 28, 2006
Messages
75
Reaction score
0
You need server-side scripting reading out the query string and running the transformation e.g. http://example.com/transform.php?xml=myxml.xml&xslt=viewOne.xsl then transform.php reads out the file names, runs the transformation and sends the transformation result to the client.

Curiosity Question:
So, does this mean that the script needs to read the XML file and make changes to it before sending it to the browser? Is this what is commonly meant when you say "transform"?

If that is so, then couldn't one write javascript code that reads the XML file from wherever it is on the internet and converts (transforms) that one line to whatever is needed then sends the rest on to the browser? I know diddly about javascript, but from what I have gathered it can read files from the internet and it can send HTML to the browser so that the browser acts as if it just read it directly off of the web site. So, if the javascript fed the browser an XML file with that one line modified would the browser then act as if it just read that XML file directly off of a web site and then do the XSL transformation itself?

Naturally, that would slow down the display because the XML file was being processed twice but it might work.

Perhaps one could even embed the XML file permanently into the javascript code. Then the XML would be transmitted at the same time as the javascript code and would already be on the client's computer. This would be like writing a program to display a page of text by simply writing a bunch of cout statements (C++) rather than simply saving and opening the text file. Naturally, the down side to this is that you no longer have a true XML file that can be parsed. Maybe you could also write a little utility that would automatically embed any XML file you wanted into a similar javascript program to make it easy to generate these javascript programs. But now I am making it way too complicated.
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Grant said:
Curiosity Question:
So, does this mean that the script needs to read the XML file and make changes to it before sending it to the browser? Is this what is commonly meant when you say "transform"?

With transform I am talking about XSLT transformations, usually in the context of the web XML is being transformed with an XSLT stylesheet to HTML as that is what browsers can render.
If that is so, then couldn't one write javascript code that reads the XML file from wherever it is on the internet and converts (transforms) that one line to whatever is needed then sends the rest on to the browser? I know diddly about javascript, but from what I have gathered it can read files from the internet and it can send HTML to the browser so that the browser acts as if it just read it directly off of the web site. So, if the javascript fed the browser an XML file with that one line modified would the browser then act as if it just read that XML file directly off of a web site and then do the XSL transformation itself?

If you have ASP/J(ava)Script on the server then you can run the XSLT transformation on the server (PHP was only mentioned as an example). It would also be possible to simply change the xml-stylesheet processing instruction and send the XML to the client but relying on client-side XSLT support if the transformation can be done on the server does not necessarily sound like a good idea. However the original already pointed out that he does not have ASP on his server.
 

Grant Robertson

Usenet Archive
Joined
Oct 28, 2006
Messages
75
Reaction score
0
With transform I am talking about XSLT transformations, usually in the context of the web XML is being transformed with an XSLT stylesheet to HTML as that is what browsers can render.

Can't a browser open a raw XML file and apply the XSL itself? Or is XSL different enough from XSLT that I am totally off base? When I open some XML files with my browser I get a little bit of formatting over and above just what a text file gets. But when I open some XML files I get a message that says that there was no XSL file specified so the browser just applied a default style.

Does XSLT perform transformations that can only be done on a server and then send out the HTML to the browser or is it possible for a browser to perform the transformations itself? I'm guessing older browsers couldn't do it but could newer ones?
 

Joseph Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
733
Reaction score
0
Grant said:
Can't a browser open a raw XML file and apply the XSL itself?

Yes, a good browser really should be able to do so; that was sorta the original design point for stylesheets generally. I'm not sure which browsers can do it these days; I've mostly been running stand-alone XSLT engines.
 

Andrzej Adam Filip

Usenet Archive
Joined
Mar 3, 2004
Messages
44
Reaction score
0
Martin Honnen said:
The xml-stylesheet processing instruction is modelled after the HTML link element so it should allow you (in theory) to have several such processing instructions to suggest alternative stylesheets. However in reality for XSLT stylesheet I don't think any of the major desktop browsers like IE 6 and later, Mozilla/Firefox or Opera support that. On the other hand such a processing instruction does not prevent you to use script and an XSLT processor API on the server to apply different stylesheet as you like or want.

In some cases using trivial xml file for tying xsl and xml may help.

<?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>
<xml-file href="myXML.xml" />

It will require your myXSL.xsl style-sheet to process myXML.xml file when processing xml-file.
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Grant said:
Can't a browser open a raw XML file and apply the XSL itself?

Yes, but the original question is that someone wants to offer several different stylesheet for an XML document. To that question I did reply that the xml-stylesheet processsing instruction in theory allows that but that browsers in pratice do not support that. You seem to have missed that original problem.
 

Grant Robertson

Usenet Archive
Joined
Oct 28, 2006
Messages
75
Reaction score
0
You seem to have
missed that original problem.
Nah. I hyjacked the thread again. Sometimes the answers to the original question peaks my interest about something related. I did preface my question with "Curiosity Question:". I guess I should have changed the subject line as well. Would people here prefer that I start an entirely new thread also? In most of usenet people have gotten so lax that I often don't go to the full effort of full netiquette any more.
 

Toby Newman

Usenet Archive
Joined
Jul 8, 2003
Messages
16
Reaction score
0
In some cases using trivial xml file for tying xsl and xml may help.

<?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>
<xml-file href="myXML.xml" />

It will require your myXSL.xsl style-sheet to process myXML.xml file when processing xml-file.

I'm a little unsure what you mean. Is this something I could do without server-side scripting?
 

Andrzej Adam Filip

Usenet Archive
Joined
Mar 3, 2004
Messages
44
Reaction score
0
Toby Newman said:
I'm a little unsure what you mean. Is this something I could do without server-side scripting?

xsl script/file can "parse" additional xml files except xml file with xml-stylesheet so you can "reference" in your xml file additional xml files for processing by your xsl using document function.

http://www.w3.org/TR/xslt#document
<quote>
12.1 Multiple Source Documents
Function: node-set document(object, node-set?)
The document function allows access to XML documents other than the main source document.
</quote>

WARNING: I have not test how it is supported by "main browsers".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top