Connecting Tech Pros Worldwide Help | Site Map

Before I Dive In To XML/XSLT

Member
 
Join Date: Jul 2007
Location: San Ramon, California
Posts: 65
#1: Dec 20 '08
I've got a quick question. I've been using HTML/XHTML for years upon years upon years, and finally used XML for the first time in one of my applications that I developed using Ajax. I fully understand how to write XML, but not so much of XSLT. I took a quick look at XSLT, and I'm a little puzzled on how to do more of the flat out fancy effects that I can do in CSS. Can I do absolutely everything I can do in CSS (opacity, floating, z-index, shadows, etcetera) with XSLT (alone), or not?

If not, is there a way to apply CSS to the XHTML you "generate" using XSLT?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Dec 20 '08

re: Before I Dive In To XML/XSLT


you're misunderstanding XSLT. CSS is used to style/layout an existing (XML/HTML) markup. XSLT is used to change the markup itself (thus changing the structure rather than the style, which leads to a different presentation*).

Quote:

Originally Posted by moltendorf View Post

is there a way to apply CSS to the XHTML you "generate" using XSLT?

sure, output an element that's loading the stylesheet. (either <link> or <style>)

* example
Expand|Select|Wrap|Line Numbers
  1. // your xml
  2. <?xml version="1.0" encoding="iso-8859-1" ?>
  3. <root>
  4.   <echo>Hello World!</echo>
  5. </root>
while CSS tells the browser how to display the <root> and <echo> elements, XSLT changes the XML to a (e.g.) HTML
Expand|Select|Wrap|Line Numbers
  1. // XSLT result
  2. <!DOCTYPE ...>
  3. <html>
  4.   <head>
  5.     <title>Example</title>
  6.     <link rel="stylesheet" href="sample.css">
  7.   <head>
  8.   <body>
  9.     <p>Hello World!</p>
  10.   </body>
  11. </html>
note: you can apply XSLT inline so that the sent markup is the same, but the document tree (DOM) the browser loads and uses is the result of the transformation. nevertheless many people prefer to do the transformation server side and only deliver the result (e.g. me).
Member
 
Join Date: Jul 2007
Location: San Ramon, California
Posts: 65
#3: Dec 20 '08

re: Before I Dive In To XML/XSLT


Ah, alright. I was not confused on how XSLT worked. But more so on the fact that all these tutorials said never to use CSS as XSLT is the W3C recommended way for styling XML (as if XSLT was a drop-in complete replacement of CSS), so I thought XSLT provided something similar to CSS, as well as the structure changes.

Edit: I don't like to do the transformation server-side. I already can do it without XML/XSLT using the Templating Engine I have built with PHP. I figured if my software became popular enough the XML output it generates would be considered cutting-edge, and I'd wonder how the results would look in Google (with a new mass of all XML websites being indexed). :)
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#4: Dec 20 '08

re: Before I Dive In To XML/XSLT


Quote:

Originally Posted by moltendorf View Post

I don't like to do the transformation server-side. I already can do it without XML/XSLT using the Templating Engine I have built with PHP.

although you don't use XSLT for transformation, you do it server side too.

just out of interest, what template engine do you use on your XML?
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#5: Dec 22 '08

re: Before I Dive In To XML/XSLT


I've always used xslt to transform my xml data into divs and headers, etc... while pointing to a css sheet to style it. I used XSLT to choose the class of div depending on the elements, but still relied on the CSS to change the look.

Probably a misunderstanding by the people who wrote those tutorials.
Taken from: What is XSL?
Quote:
Will XSL replace CSS?
No. They are likely to co-exist since they meet different needs. XSL is intended for complex formatting where the content of the document might be displayed in multiple places; for example the text of a heading might also appear in a dynamically generated table of contents. CSS is intended for dynamic formatting of online documents for multiple media; its strictly declarative nature limits its capabilities but also makes it efficient and easy to generate and modify in the content-generation workflow. So they are two different tools; for some tasks, CSS is the appropriate choice and for some tasks, XSL. They can also be used together - use XSL on the server to condense or customize some XML data into a simpler XML document, then use CSS to style it on the client.
Reply


Similar XML bytes