Before I Dive In To XML/XSLT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moltendorf
    New Member
    • Jul 2007
    • 65

    Before I Dive In To XML/XSLT

    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?
    Last edited by moltendorf; Dec 20 '08, 12:44 PM. Reason: Removed many of my repetetive statements.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you're misunderstandin g 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*).

    Originally posted by moltendorf
    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
    Code:
    // your xml
    <?xml version="1.0" encoding="iso-8859-1" ?>
    <root>
      <echo>Hello World!</echo>
    </root>
    while CSS tells the browser how to display the <root> and <echo> elements, XSLT changes the XML to a (e.g.) HTML
    Code:
    // XSLT result
    <!DOCTYPE ...>
    <html>
      <head>
        <title>Example</title>
        <link rel="stylesheet" href="sample.css">
      <head>
      <body>
        <p>Hello World!</p>
      </body>
    </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).

    Comment

    • moltendorf
      New Member
      • Jul 2007
      • 65

      #3
      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). :)

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by moltendorf
        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?

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          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 misunderstandin g by the people who wrote those tutorials.
          Taken from: What is XSL?
          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.

          Comment

          Working...