Can you embed xsl style sheets in xml documents

Here should go questions about transforming XML with XSLT and FOP.
christian
Posts: 5
Joined: Thu Jun 29, 2006 5:53 pm

Can you embed xsl style sheets in xml documents

Post by christian »

Hello

I have some xml that is generated on our server (dumpped from an SQL database) and I'd like to format it using an external XSL style sheet so that it appears in a friendly table for users in their browser.

My problem/question is this. Presumably the browser needs to download both the xml and the xsl files so I'm confused as to what to put in the href in the following declaration

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

If I just put the xsl file name doesn't it have to be in the same local directory? If so does this mean that I have to save it to the servers file system locally in the same folder as the style sheet? (Which I would rather avoid)

Should I publish the xsl somewhere globally available?, eg

http://www.acme.com/StyleSheets/FormPro ... erview.xsl

Or is there a way of embedding the xsl into the top of the xml as you can in html? so that it can all be sent back to the browser in one go.

Thanks for any advice.

Christian
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

It looks like the best solution for you is to post the xsl stylesheet to a globally available location.

If this same xml file is viewed many times, you might consider transforming the xml on the server itself before showing it to the user. Then the user only needs one access.
christian
Posts: 5
Joined: Thu Jun 29, 2006 5:53 pm

Post by christian »

Thanks for the reply. I think your suggestion about transforming it on the server is probably best. I'll go with this for now.

Christian
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Can you embed xsl style sheets in xml documents

Post by sorin_ristache »

Hello,

You cannot embed the stylesheet in the XML file as Web browsers will handle it as a single XML file. There is no such extraction of the stylesheet from the XML file implemented in browsers. The path to the stylesheet specified in the href attribute can be a URL to a global XSL or can be a relative path to a local file but the XSL stylesheet does not have to be located in the same folder as the XML file. It can be stored in a subfolder, for example href="subfolder1/subfolder2/FormPropertiesOverview.xsl" or can be stored in a different folder, like href="../../otherFolder/FormPropertiesOverview.xsl".

Regards,
Sorin
Post Reply