Serendipity Strikes

I had been thinking that, even to use the browser solution, I d have to take the user s typed XML, run the XSLT script on it to generate the HTML, and then let the user browse the result. Not difficult, but you can see how it could lead to a fair number of new features in the program as we provide ways for the user to tell us what XSLT file to use and so on. Then something I had read in my search slapped me in the face.

Internet Explorer can display XML!! Given a legal raw XML file, it will display it in a simple indented format. That s not very useful to me (or, I would imagine, to anyone ), but where I was reading that, it went on to say that the XML file can specify an XSLT transformation to be applied to it and that in that case Internet Explorer will display the result of applying the transformation. To me that meant : If I put a pointer to my XSLT into my XML, maybe Internet Explorer will display a page that looks like my article!

That s easy enough to try. I dug around and found the information again and added the necessary line, which goes second from the top in your XML file. The top of the file looks like this:

 <?xml version="1.0"?> 
<?xml-stylesheet type="text/xsl" href="magazine.xsl"?>

The magazine.xsl is the name of the file containing the XSLT to convert my articles. So I did this experiment:

  1. I opened Internet Exlorer and pointed it at the XML files for one of my articles. Internet Explorer dutifully displayed the XML, all nicely indented, but not looking much like an article.

  2. I edited the XML file and entered the xml-stylesheet line, saved the file, and refreshed Internet Explorer. Wow! Something came up that looked like an article! The graphics weren t there, and the fonts were wrong, but it had the header and the underlines and the menus and all the stuff. Nearly worked!

  3. The images on my Web site are taken from a directory named images that is parallel to the magazine directory. I copied the images directory to the corresponding place beside the XML directory. I refreshed the browser, and the graphics were there!

  4. The fonts and layouts on the site are controlled by a Cascading Style Sheets file named style.css, which needs to be in a standard place relative to the article. I put the style sheet in the right place, and voila! the article looked almost right!

There was a little hassle with the menu items that appear in the upper right of my pages, next to the logo. These were running off to the right, instead of folding to the size of the page as they are supposed to. It took me a good half hour or more to figure out what was happening there. I m still not entirely sure of the fix, but basically Internet Explorer wasn t seeing the spaces between the items, concluded they were all one big long string, and displayed it accordingly . I seem to remember an XSLT option saying how to treat white space, and I think that s probably implicated in this. In any case, I changed the lines in question to have identifiable space, and the problem went away.

This Is Really Cool!

So, what have I discovered ? If the user has legal XML in his Notepad, and if it includes a pointer to the right XSL stylesheet, and if a few files are in the right directories, he can just open the XML file and look at it in Internet Explorer to see how it s shaping up. He can press refresh at any time for a fresh view.

This means that we won t have to do the XSL transformation inside XML Notepad and we won t have to provide any new features. The user can view the file easily after every save by just refreshing the browser. He ll probably want some handy features, but this is definitely better than what he has now. We might be done!

Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291 © 2008-2017.
If you may any questions please contact us: