469,282 Members | 2,373 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Viewing one XML using multiple XSL files

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?

--
-Toby
Add the word afiduluminag to the subject to circumvent my email filters.
Jan 25 '07 #1
13 9387
Toby Newman wrote:
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.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 25 '07 #2
On 2007-01-25, Martin Honnen <ma*******@yahoo.dewrote:
Toby Newman wrote:
>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.
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?

--
-Toby
500 Nintendo Stars for trade: 2xWii Play
* * * * * * * * * * * * * * * * * * * * * * *
Add the word afiduluminag to the subject to circumvent my email filters.
Jan 25 '07 #3
Toby Newman wrote:
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...lt=viewOne.xsl
then transform.php reads out the file names, runs the transformation and
sends the transformation result to the client.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 25 '07 #4
On 2007-01-25, Martin Honnen <ma*******@yahoo.dewrote:
Toby Newman wrote:
>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...lt=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?

--
-Toby
500 Nintendo Stars for trade: 2xWii Play
* * * * * * * * * * * * * * * * * * * * * * *
Add the word afiduluminag to the subject to circumvent my email filters.
Jan 25 '07 #5
In article <45***********************@newsspool2.arcor-online.net>,
ma*******@yahoo.de says...
You need server-side scripting reading out the query string and running
the transformation e.g.
http://example.com/transform.php?xml...lt=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.
Jan 26 '07 #6
Grant Robertson wrote:
In article <45***********************@newsspool2.arcor-online.net>,
ma*******@yahoo.de says...
>You need server-side scripting reading out the query string and running
the transformation e.g.
http://example.com/transform.php?xml...lt=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"?
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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 26 '07 #7
In article <45**********************@newsspool3.arcor-online.net>,
ma*******@yahoo.de says...
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?
Jan 26 '07 #8
Grant Robertson wrote:
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.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jan 26 '07 #9
Martin Honnen <ma*******@yahoo.dewrites:
Toby Newman wrote:
>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.
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.
--
[pl>en: Andrew] Andrzej Adam Filip : an**@priv.onet.pl : an**@xl.wp.pl
Home site: http://anfi.homeunix.net/
Jan 27 '07 #10
Grant Robertson wrote:
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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 27 '07 #11
In article <45***********************@newsspool4.arcor-online.net>,
ma*******@yahoo.de says...
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.
Jan 27 '07 #12
On 2007-01-27, Andrzej Adam Filip <an**@onet.euwrote:
Martin Honnen <ma*******@yahoo.dewrites:
>Toby Newman wrote:
>>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.

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?
--
-Toby
500 Nintendo Stars for trade: 2xWii Play
* * * * * * * * * * * * * * * * * * * * * * *
Add the word afiduluminag to the subject to circumvent my email filters.
Jan 29 '07 #13
Toby Newman <go****@asktoby.comwrites:
On 2007-01-27, Andrzej Adam Filip <an**@onet.euwrote:
>Martin Honnen <ma*******@yahoo.dewrites:
>>Toby Newman wrote:

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.

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?
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".

--
[pl>en: Andrew] Andrzej Adam Filip : an**@priv.onet.pl : an**@xl.wp.pl
Home site: http://anfi.homeunix.net/
Jan 29 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by yogesh | last post: by
121 posts views Thread by typingcat | last post: by
5 posts views Thread by IkBenHet | last post: by
5 posts views Thread by aolson | last post: by
1 post views Thread by =?Utf-8?B?TWFuaQ==?= | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.