Slashdot Log In
Printing XML: Why CSS Is Better than XSL
Posted by
michael
on Thu Jan 20, 2005 10:45 AM
from the anything-you-can-do-i-can-do-better dept.
from the anything-you-can-do-i-can-do-better dept.
An anonymous contributor writes "XML.com just published an article titled Printing XML: Why CSS Is Better than XSL written by Michael Day and Håkon Wium Lie. The article was written in response to Norm Walsh's claim that CSS will never fix [printing]. Did you hear me? CSS will never fix it!. The article shows how a 100-line CSS style sheet gives you the same formatted version of W3C's Webarch as the 1000-line XSL style sheet by using Prince."
This discussion has been archived.
No new comments can be posted.
Printing XML: Why CSS Is Better than XSL
|
Log In/Create an Account
| Top
| 361 comments
| Search Discussion
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Tru Dat (Score:5, Insightful)
Frankly, I think the W3C should act like supreme overlord and take a bullwhip to all browser developers who can't stay up to standard.
I can just see Bill Gates bent over and bare assed in a W3C hazing ritual saying 'Thank you sir! May I have another?'
Re:Tru Dat (Score:4, Funny)
(http://www.christophermahan.com/)
Oh, did I just make a silly comment? Sorry... (again)
Re:Tru Dat (Score:4, Insightful)
(http://richardstanford.com/ | Last Journal: Monday April 05 2004, @06:03PM)
Even better, because there's no need to use the intermediate PDF step, instead the user would just print from their browser and they'd get the nicely formatted output pages. Ideally things like page size would be set from the print dialog, et cetera, for best transparency rather than being hardcoded into the CSS at all, something you need if you're dumping to PDF instead of going directly to a printer.
Re:Tru Dat (Score:4, Interesting)
Re:Tru Dat (Score:4, Informative)
(http://slashdot.org/)
Re:Tru Dat (Score:5, Insightful)
(Last Journal: Friday June 11 2004, @11:45AM)
For some things. XSL is much more widely scoped, (from the article), "Turing-complete language which, in principle, can be used for all programming tasks and is particularly suited for document transformations."
In the case of document presentation CSS is indeed a challenger, but mostly if the document is static. XSL has loops, branching, conditionals, and templates (akin to functions). If you have a report with some complex logic, ie. if this number is below a threshold, print this warning, otherwise show this table. Of course you could always do all transformations and logic before the final rendering step, but in a lot of cases it's easier to do it purely XSL. Yes, you could always bring Java-script or some other html-based functionality, but that's more than just CSS.
Furthermore, there was probably a number a transformations you've already done to get the data that you need. A more suiting comparision would be with XSL:FO and CSS, but again, they both have their place. Furthermore you can imbed graphics with SVG and tools like FOP will automatically render them. To say that CSS is definitely better is naive.
As in most other times when people compare languages, each has it strengths, and straight up conclusions (CSS is better!) is most often an apples to oranges comparison.
Re:Tru Dat (Score:4, Insightful)
(Last Journal: Friday June 11 2004, @11:45AM)
I have a large XML document. I want a PDF report of that information. With FOP I can write a couple stylesheets and get a PDF without having to use a browser.
My view is, why throw yet another programming language into the mix, just to do output?
If you're dealing in XML already the traditional route is XSL. If HTML than CSS+whatever. XHTML? Maybe XSL for transformations and CSS for formatting. But do you see that there are different problems that require different tools?
If people designed web apps like some advocate...
Web apps aren't the only apps. That's what I'm saying. Again, different problems require different tools.
you'd have to work in a million different langauges,
If you are a descent programmer, the languages don't matter. After you learn a few you pick up new ones quickly. You use the best ones for the job. Sometimes four languages is better than one. Sometimes not. Knowing which to pick separates you from the code monkeys.
So where did this come from? (Score:1)
Free? (Score:2, Funny)
Better question (Score:2, Insightful)
(http://plato.stanford.edu/ | Last Journal: Tuesday March 15 2005, @10:46AM)
Re:Better question (Score:4, Informative)
(http://libtom.org/)
1. It's old, mature and stable
2. LaTeX makes TeX really easy to work with
3. The output is related to the input, not the machine you are working on.
4. Gives you wicked control over positioning, size, orientation, etc.
5. Great support for equations, figures and other oddities that things like Word manages to screw up.
6. Most TeX distros [like tetex] are FREE and open source. No shelling out the MSFT tax to use Word
The only big downside to LaTeX is that occasionally it automagically places things in a less than desired fashion [figures I mean] and you have to manually tweak it. But I'd say for 99% of what math/crypto people do [for instance] LaTeX handles it perfectly.
Tom
Great example of hard-coding reducing size. (Score:5, Interesting)
If you look at the XSL, it selects different text sizes for different page sizes.
Thus I would have to say - have they tried printing both examples using different page sizes? Because I am pretty sure the CSS version will be a postage stamp in the middle of an A0 page.
Also from quick examination it looked like the XSL is more flexible in other ways, you can pass in all sorts of parameteres like margins.
Basically - sure the XSL is longer, but also more flexible in terms of use. Since you are only going to write it once (that is unless you want multiple page sizes in which case you are going to have many CSS files) what does it matter if there is a little code-size increase?
Furthermore the XSL could itself be transformed in various interesting ways for special modifications, a task harder to do with CSS. And you could include things like the paper-size->font-size mapping in seperate files to keep the size down and the file more readable (though I find the XSL perfectly readable - after having used XSL for a while, admittedly!).
Main Difference (Score:5, Insightful)
(http://richardstanford.com/ | Last Journal: Monday April 05 2004, @06:03PM)
More recently, a W3C Candidate Recommendation (called CSS3 Paged Media Module) added functionality to describe headers, footers, and more...
The big difference is that XSL provides the tools to perform this transformation - from XHTML to a printable layout - without needing to change the standard itself. The same goes for the argument made about page sizes, which are built into the latest CSS and which have to be handled manually with XSL.
Now, once you have wide support for the latest CSS (and who knows how long that will take), I would wholeheartedly agree that it would be a better choice for printing as shown here. The fact of the matter seems to be that they're comparing what you can do today, with a little work, using XSL transforms, to what you may be able to do tomorrow with a proposed dedicated language. I'd be pretty surprised if the latter couldn't do what its designed to do better than a general purpose language.
At least, that's the way I see it. So, there's some good stuff coming down the pipe with CSS. That's worth knowing about. But until it has wide support, there's XSLT. And that's worth knowing about as well, and a damn sight more useful - for now.
Browser support (Score:3, Insightful)
(http://www.philcrissman.com/)
Does XSL suffer the same cross-browser incompatibilities? This I don't know, and while I love CSS, if XSL was better at cross-browser homogenity(sic?) I could see that being a big feature.
As a previous poster noted, though, a better solution would be for Microsoft to fix IE so it supported the wc3 recommendations....
XML/XHTML as a layout language? (Score:5, Insightful)
(http://www.justgiving.com/garethowen | Last Journal: Thursday October 31 2002, @02:07PM)
Re:XML/XHTML as a layout language? (Score:5, Insightful)
(http://mithrastheprophet.blogspot.com/ | Last Journal: Thursday October 17 2002, @07:44PM)
Riiightt (Score:4, Insightful)
(http://masterdev.dyndns.dk/drslog | Last Journal: Thursday April 19 2007, @02:20PM)
The same argument could be applied to RDBMS: "Stored Procs are harder to use, so move the logic into the PHP code!!!" or Languages: "Pointers are hard to use, so VB.NET r0xx0rs over C!!!!"
My experience with the whole mess is that, yes, XSL-FO->PDF is harder to set up, but I get the same output every time. We tried to use CSS, and all it took to screw up the works was have somone set their browser margins or font size differently. Or use a non-CSS-compliant browser [microsoft.com]. We don't have control over the user's browser, but if we output to PDF, we have total control. Oh, but it is harder to use the latter, so forget it.
Q: How can you tell if a website was designed by a know-nothing monkey? A: "This site best viewed in 800x600, 1024x768, etc."
XSL isn't trying to replace CSS (Score:2, Insightful)
aren't XUL and firefox good examples? (Score:2)
(http://xyfer.blogspot.com/ | Last Journal: Tuesday July 24, @09:00AM)
XML + CSS?
There is no way I am even attempting to RTFA... (Score:1, Funny)
The authors aren't talking about using browser-CSS (Score:5, Informative)
The authors of their CSS Rocks article are imagining that you're going to use software like Prince [yeslogic.com], (software that one of them created) to apply CSS3 rules to XML and get PDFs out of them.
Another way to say this is that they're not talking about how to fix the browser -> print workflow in this article (although one of the authors works for Opera, so I imagine he's thinking about it). They're talking about easy ways to transform XML to PDFs, and discussing why you might use CSS to do such a thing.
This courteous and friendly rationalizing of the slashdot editor's inflammatory post has been brought to you by my company, which is paying me for the time I use to write this. The opinions, of course, are mine only.
Nerd fight!!! (Score:3, Funny)
(http://thepreacher.cac2.net/)
Let the hair pulling and the name calling begin.
Program vs. XSLT (Score:2)
(Last Journal: Thursday December 08 2005, @04:33PM)
Its much easier to write a Perl script to read in the XML, "transform" it and write out new XML.
css is better, but is still full problems (Score:2)
Why use either? (Score:2)
(Last Journal: Thursday April 18 2002, @07:50PM)
If a program uses XML to store something that is meant to be printed, use that program. For example, I use AbiWord to print AbiWord documents, which are XML. Whatever AbiWord uses to convert the XML so the printer can understand it is not something I care about unless I am an AbiWord developer.
Whatever works best to print XML that represents foo is irrelevant if foo wasn't designed to be printed.
Note to IT community... (Score:4, Insightful)
(http://www.hwacha.net/)
Please stop trying to build up this markup language, which annotates documents with suggestions as to how they might be displayed, into a typesetting system. Please get a typesetting system instead, and use formats such as eps and latex that are relevant to the task.
Thank you.
Also please stop using XML to represent arbitrary data. It's a markup language. It annotates and divides text. It does not extend easily to representing all data in all contexts, and when you try and make it do that, you wind up with syntax like '[CDATA['.
Thank you for your co-operation and enjoy your day. This has been a Public Service Rant brought to you by Diet Coke.
It's apparently already slashdotted. (Score:4, Funny)
(http://supybot.sf.net/)
In nice, big text. Way to hold the the XSL fort, guys!
Jeremy
DOH!!!! (Score:3, Informative)
(http://slashdot.org/~Spy+der+Mann/journal/ | Last Journal: Thursday November 15, @12:57AM)
Comparing XSL vs. CSS is like comparing Table-based design with Table AND CSS-based design.
(X)HTML's Document Object Model has default styles ("default" CSS if you prefer) assigned to each element. Of course using CSS is necessary.
And the reason many XSLT stylesheets are so long is because of the stupid design imposed on them (non-changeable variables, result-tree-fragments, inability to eval an xpath expression... ok who was the genius who came out with these ideas, anyway?)
Unfortunately, current browsers cannot do ALL the formatting. Try turning off IE's header and footer using CSS. Or customizing your own header and footer, or print landscape instead of portrait.
Let's hope that CSS3 solves these problems - but until then, server-side PDF generation is the solution.
Anyway if browsers had supported XSL, it would be a mainstream component of the web today. We would have marvelous things like client-side inclusion (I've done it with XSLT alone, _NO_ javascript!), bandwidth savings... (imagine that with Google!)
In the end it became a pipedream due to the lack of browser support.
WFT??? (Score:2)
In my world I use both. XSL when I need something really robust; CSS when I need to reuse css styles.
Both have their place. Arguing whether one or the other is better is really moot. You can use CSS with XSL to render XML anyway.
As a matter of practicality... (Score:4, Insightful)
(http://www.danm.net/)
Though I do have to agree with the article, in principle, that CSS is fully capable of doing the job when it comes to producing printable page layout, if we're going to be banging on a drum, let's bang on the "let's get these damn browsers to support printing better!" drum first. Because even if I create a CSS stylesheet that should produce beautiful printed pages, it doesn't do me a lot of good if I can't actually print them that way.
XSLT is for transformation (Score:5, Informative)
The bottom line (at least for me): if you can do it with CSS, do it with CSS. But there are some cases where you will need XSLT.
Please... (Score:1)
xsl:fo-nonsense (Score:4, Informative)
Size. (Score:2)
(http://althiphop.blogspot.com/)
XSL is not XSL-FO (Score:1)
Proof that CSS is better than XSL (Score:3, Funny)
(http://www.sowbug.org/)
COBOL better than XML (Score:1)
(http://www.geocities.com/josephbcotton | Last Journal: Tuesday January 10 2006, @09:27PM)
Don't people use both in ther same application? (Score:1)
Beware of the things you say (Score:2, Interesting)
(http://norman.walsh.name/)
I got a better one (Score:2)
(Last Journal: Thursday October 10 2002, @03:54PM)
I mean, sheesh... line counts make things better? pleeeze...
we also find out why... (Score:2)
thru Catchcom
is better than
Apache/1.3.33 (Debian GNU/Linux) mod_python/2.7.10 Python/2.3.4 PHP/4.3.10-2 mod_ssl/2.8.22 OpenSSL/0.9.7d
thru Charter Communications
never say never (Score:1)
(http://willcode4beer.com/ | Last Journal: Thursday May 12 2005, @07:33AM)
We see this time and again.
What Slashdot needs (Score:3, Funny)
Two competing technical ideas so that everyone can line up behind one or the other and argue which is better.
I'm really tired of seeing everyone here just politely agreeing with one another in such a single-minded way.
Ever since the debates over vi/emacs, linux/windows, tastes great/less filling, etc. were all settled, there just haven't been any good arguments here.
how about XSL **AND** CSS (Score:2)
(http://greggman.com/)
I didn't read the article yet but I just got through my first experience with XSL. I used XSL to turn XML into HTML and used CSS to format that HTML.
http://greggman.com/headlines/2005/2005-01-16-xslt -rss.htm [greggman.com]
Why is there an argument?
Herd mentality (Score:1, Insightful)
(http://www.putfwd.com/ | Last Journal: Tuesday November 23 2004, @01:50AM)
Show me the browser support for XSL? The article is displaying an example of why CSS3 will solve most of the same problems 1000x more elegantly. XSL is Perl's (I like Perl, I don't like XSL) ugly kid brother -- got beat twice as hard with the ugly stick.
When XSL came out, where was the tool support for it? Nonexistant. Because it was just a standard first. The tool support even now, years later, is only partial.
So yes, CSS3 will take time to implement in the real world, but it's a clearly superior solution. Shortcomings? Probably more than a few. But if we WORK on them, we can overcome them, probably also 1000x more elegantly than the atrocity that is XSL.
So instead of bitching about someone getting it right for a change (now that we've wasted how many years trying to work with XSL), why not start up an open source project to build support for the new spec? This sounds like a good side-project for Mozilla.org or the KHTML folks (since they already have a rendering engine).
Proffesionals are funny people. (Score:1)
Incorrect comparison (Score:5, Interesting)
(http://carewolf.com/)
Last name is Lie... (Score:1)
(http://candyaddict.com/ | Last Journal: Friday July 29 2005, @09:26AM)
But what I really Need . . . (Score:2)
(http://www.example.net/)
. . . XSL?! Sir, my first job was programming XML, very similar to your XSL in most respects.
Do you program Perl?
Of course I do, sir, I must type some for you.
Alright, shut up. --He'll do. Luke! Take these two programmers and get them cleaned up.
use XQuery for transformations (Score:2)
(http://per.bothner.com/)
Article is about printing XHTML, not XML (Score:1)
(http://sridev.gotdns.com:5000/)
You need XSL to convert XML to HTML/PDF or any other format for printing.
News just in Chalk is better than Cheese... (Score:2)
Now *slaps the person who wrote the post*, if youre not going to write a fair comparison don't bother writing one at all, the XSL-FO shows a page-size selector which will work for any size page, and he compares this to a one-size A4 CSS definition, I stoped reading at that point, if your going to argue Hello World is better than A cellular automota because it's got less lines of code in it, I don't want to hear any more of your arguments.
Line count comparison (Score:2)
(http://www.internetgenealogy.com/)
I'm not sure it's fair to compare a 100 line straight text file to a 1000 line XML file and say that one is inherently superior. Having worked with XML, crafting it by hand, running in to all sorts of parsing errors, I've come to one conclusion:
XML was never built to be written by hand, or to be read with the human eye.
After all, these are text files, and it's not like we're using systems with only a few hundred kilobytes of storage anymore. I can see a distinct advantage to enforcing a schema on data, even if it is a total pain in the ass to enforce it.
I can craft 100-200 line XML files in the manner that we all craft HTML by hand, and my patience *just* holds out through all the parsing errors.
What we do need is a good (ideally open source) XML editor that's as natural and intuitive to use as Notepad (or more ideally Textpad) is to edit text files.
I haven't seen one yet. I keep going back to really good text editors and using my brain and lots of iterations checking that the XML matches the schema to keep me from going insane.
Some of them are out there, but they're all so *fiddly*. Fiddly enough to scare off a data content author, who isn't a programmer. Given a schema, editing XML should be Microsoft Word easy (sans Clippy). I've not seen it there yet.
Then again I'm an old bastard (30) who wants to edit everything by hand no matter what. It's hard to break that habit.
CSS still lacks a great deal (Score:2)
Strange comparison (Score:2)
(http://www.medinheaven.co.uk/)
I'd rather see it compared to other templating solutions. It seems to me that XSL is like a functional language compared to other templating engines acting more like an imperative language (I said like, it's not a great analogy). It would appear to me to be a bitch to render XSL pages real-time if, as I see in many tutorials, the transforms are an extensive list of recursive <xsl:apply-templates>. How fast are the XSLT parsers these days?
Phillip.
Why CSS is better than XSL (Score:1)
Re:ATTENTION! (Score:1)
(http://www.grub.net/blog/index.html | Last Journal: Wednesday June 27, @08:48AM)
Is that all they make? References? Really, it's not worth getting out of bed for that.
Re:There is Nothing Worse Than XSL (Score:2)
(http://breakplay.com/)
Re:what do we have here... (Score:1)
(http://swedegeek.com/ | Last Journal: Monday October 10 2005, @09:55AM)
Hey, step off Prince! He's a fellow Minnesotan... Yea, sure ya betcha!!!
Besides, I just saw him at the Golden Globes this past Sunday. Okay, so he looked like a re-animated corpse from the 80s, but he was there nonetheless!
Re:PDF is the only way to print *properly* (Score:2)
(Last Journal: Saturday August 18 2001, @11:04AM)
Re:CSS itself is overused (Score:3, Insightful)
What about disabled access to your webpages through some speech browser and the like. What about mobile devices. Provide your content in a well structured format and you can be sure any (half modern) current device can see your pages as well as anything in the future.
The web is not a print medium. Design your sites so slight differences in spacing etc. are irrelevant. A well designed CSS-driven site will degrade nicely in Netscape 4 (basically @import to exclude it and other archaic browsers) and at the same time be accessible to everyone on any device.
A couple of years ago I would have agreed with you. Now the average browser is more than capable of displaying CSS based designs. Alright CSS may require a few hacks here and there for IE and such but a few nasty bits of CSS is far more preferable than some hacked together HTML using tables for layouts.
Re:CSS itself is overused (Score:2)
(don't forget to read the text, you might want to choose a different design
and try to reevaluate your opinion of CSS in general, and expand it to all the things that work in all browsers and not just text formatting. (CSS1?)
Re:Call me stupid....wait.... (Score:1)
no no no. (Score:1)
" I've lowered my tollerance for bad HTML and shoehorning designs into CSS."
This comment alone shows how out of touch you are with modern CSS based development...
Check out the zengarden, the CSS vault and CSS beauty for a lesson.
Re:CSS != XSL (Score:1)
(http://people.opera.com/howcome/2003/2/slashdot)
Re:what do we have here... (Score:2)
(http://www.codebig.com/ | Last Journal: Thursday August 26 2004, @06:29PM)
Re:There is Nothing Worse Than XSL (Score:2)
(http://soupisgoodfood.net/)
Re:CSS itself is overused (Score:2)
(http://picknit.com/ | Last Journal: Saturday July 29 2006, @03:58PM)
I agree that there's a convergence problem with browser support of CSS. But the intersection of CSS support you see on all the current browsers is enough for most purposes. That still leaves your legacy users in the lurch. But if legacy support is that important to your web site, it makes more sense to scale back the fancy formatting, instead of using obsolete kludges.