tags:

views:

140

answers:

2

I've applied a stylesheet to an xml document using <?xsl-stylesheet ...>, this works great when the XML is being viewed in my application. But if the xml is exported, I want the XML to still render as plain XML, is it possible to have the stylesheet as optional rather than it producing this error when style is not found:

Error loading stylesheet: A network error occured loading an XSLT stylesheet:

+1  A: 

The only solution is to remove the xml-stylesheet during the export sadly.

Julian Aubourg
Oh, I see your point now. The only solution is to remove the xml-stylesheet during the export sadly.
Julian Aubourg
My XML Doc starts life off looking like this:<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="message.xslt"?>
JL
Please update your answer, and I'll accept is as correct...
JL
Other possible solution: use media="<YOUR_APPLICATION_NAME>" and make it so your application renderer recognizes it as screen. Only your application would use the stylesheet (and from a semantic point of view, it makes sense).
Julian Aubourg
@JL: I don't get your first comment... so I don't know what to update ;)
Julian Aubourg
Just for the next guy , please update your answer to : The only solution is to remove the xml-stylesheet during the export sadly.
JL
@JL: Done. Any link to your app or is it private? What does it do?
Julian Aubourg
Its intranet unfortunately, but it uses XML files as its db, and I just know outside of web reporting, these XML files are going to find themselves getting used in other systems.
JL
A: 

(I know ti's an old question, but it begs for an update)

It's generally not a good idea to use the xsl-stylesheet processing instruction in XML, because of its limited applicability and because you're binding the view to the data. While you could make it dynamic by having your web server return a different stylesheet depending on where the request comes from, this is not ideal.

Instead, in your application, use any available XSLT processor and process the XML prior to showing it in the viewer. This is simple to build and maintain and has the added benefit that the view (the XSLT) is separate from the data (the XML). When viewing the XML normally, it will not have the PI anymore and will be shown as regular XML.

Abel