78177

Transform XML with publicly available XSLT

Question:

I don't have much practical experience with XSLT so I would need your "best practice" help on the problem. XML is automaticaly generated and sent to the user (emails, etc.). This XML contains the following header element (starting and ending element tags are deleted due to editor problems):

xml-stylesheet type="text/xsl" href="http://example.com/myvisualisation.xslt"

XSLT is uploaded and available at given URL. What is the "standard/normal" way for user to open received XML with this transformation applied? (when I try with browser I get cross-domain error). Is it possible (and how) to arrange things so that user can simply double click attached XML and he/she will see transformed document?

Also when I try to open XML with MS Excel (which gives me an option to apply transformation) is quite "messy" (missing borders, etc.) compared to if I use browser (looks ok) although I am using very standard and simple HTML.. no fancy stuff.

Answer1:

I don't think sending XML files to "users" is a good idea. Why don't you do the transformation for them and send them the resulting HTML file - or (preferably, IMHO) use some other generally accepted format such as PDF?

<blockquote>

Also when I try to open XML with MS Excel (which gives me an option to apply transformation) is quite "messy" (missing borders, etc.) compared to if I use browser (looks ok) although I am using very standard and simple HTML.. no fancy stuff.

</blockquote>

Hard to tell based on so little info (none, really) but it could have something to do with Excel not being a browser.

Answer2:

Although browsers support XSLT, in practice, most XSLT that generates HTML is run on the server or in offline batch processes -- not within the browser. <strong>If at all possible, run XSLT in the server or in an offline batch process rather than in the browser.</strong>

If you have to transform XML in the browser, be aware of some serious limitations and issues:

<ol><li>XSLT 2.0 is not supported by any of the major browsers.</li> <li>Browser security models differ in ways that affect XSLT processing. This can be a major source of frustration in developing or distributing documents that rely on browser-based XSLT. <ul><li>As you've already encountered, cross-domain restrictions can be an issue.</li> <li>While Firefox will allow locally loaded XSLT files to run, Chrome will not; <a href="https://code.google.com/p/chromium/issues/detail?id=70088" rel="nofollow">Chrome requires that XSLT be loaded from a server</a>.</li> </ul></li> </ol>

<strong>Note:</strong> It is not a "header element" but a processing instruction. You should be able to paste it into your question verbatim, and it should look like this:

<?xml-stylesheet type="text/xsl" href="http://example.com/myvisualisation.xslt"?>

If your document instead actually does represent this as an element [<strong><em>wrong</em></strong>],

<xml-stylesheet type="text/xsl" href="http://example.com/myvisualisation.xslt"/>

then the link to the XSLT will certainly fail.

<strong>Final note:</strong> Your XML-in-MS Excel question should be asked separately with substantially more detail added.

Recommend

  • can't get the image to rotate in center in Qt
  • Getting “node stack overflow” when cbind multiple sparse matrices
  • XslTransform with xml-stylesheet
  • Why async.map function works with the native fs.stat function?
  • Cross compiling Qt 5
  • Making a URL W3C valid AND work in Ajax Request
  • How to add System.Windows dll to Visual Studio 2010 express?
  • How to work with Master Page that is attached to the page via the page's basepage?
  • Fire callback when selection was made with select2 4.0, and retrieve the value of last selection
  • Aligning image on right side of title on UIButton with imageEdgeInsets and titleEdgeInsets
  • Creating UDF with VSTO in Excel
  • VBA Dir function not working on Excel 2010
  • Outlook to Excel hyperlink issue
  • Flex items with same property values are rendering in different sizes
  • C# Excel interop - how to test if interop object is still working and performing a task?
  • jQuery: add elements until a particular height is reached
  • what makes a request a new request in asp.net C#
  • RxJava debounce by arbitrary value
  • System.InvalidCastException: Specified cast is not valid
  • How do I access an unhandled exception in an MVC Error view?
  • How do I get HTML corresponding to current DOM tree?
  • HTTP/2 streams vs HTTP/1.1 connections
  • JQuery Internet Explorer and ajaxstop
  • JSON response opens as a file, but I can't access it with JavaScript
  • Use of this Javascript
  • Google Custom Search with transparent background
  • Read a local file using javascript
  • Avoid links criss cross / overlap in d3.js using force layout
  • Linq Objects Group By & Sum
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Menu Color Fade on Hover with Jquery
  • vba code to select only visible cells in specific column except heading
  • Change an a tag attribute in JavaScript based on screen width
  • jquery mobile loadPage not working
  • How to format a variable of double type
  • Data Validation Drop Down Box Arrow Disappearing
  • Buffer size for converting unsigned long to string
  • How do you join a server to an Active Directory (domain)?
  • To Get the radio button value in ruby on rails