Extensible Stylesheet Language

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Extensible Stylesheet Language - Presentation Transcript

    1. Extensible Stylesheet Language Jussi Pohjolainen TAMK University of Applied Sciences
    2. XSL
      • E xtensible S tylesheet L anguage (XSL)
        • family of transformation languages
      • To format and / or transform XML – documents
      • XSL Family consists of three languages
        • XSL Transformations (XSLT)
        • XSL Formatting Objects (XSL-FO)
        • XML Path Language (XPath)
      • All languages are W3C recommendations
    3. Relationships with the Languages Extensible Stylesheet Language XSL Transformations XSL Formatting Objects XML Path Language uses
    4. Languages
      • XSL Transformations (XSLT)
        • XML language for transforming XML documents
      • XSL Formatting Objects
        • XML language for specifying visual formatting
      • XML Path Language
        • A non-XML language used by XSLT, addressing the parts of an XML document . Also available for use in non-XSLT contexts
    5. Main Idea of XSLT XSLT Processor The XSLT Processor can be client-side (browser) or server-side (php, java..)
    6. Without XSLT - link
    7. With XSLT - link Now the XML document is linked to an external xslt document Browser is used as an XSLT processor. (client-side)
    8. XSLT
      • XSLT is an transformation language.
      • With XSLT you can make transformations:
        • XML -> XML in General:
          • XML -> XHTML
          • XML -> SVG
          • ...
        • XML -> HTML
        • XML -> TEXT
      • With XSLT you can transform a XML document to other text format (can be any).
    9. XSL-FO
      • XSL-FO is a W3C Specified XML language for defining visual presentation.
      • Unified presentation language
      • No semantic markup
    10. Example of an XSL-FO Document
      • <?xml version=&quot;1.0&quot;?>
      • <fo:root xmlns:fo=&quot;http://www.w3.org/1999/XSL/Format&quot;>
      • <fo:layout-master-set>
      • <fo:simple-page-master master-name=&quot;only&quot;>
      • <fo:region-body/>
      • </fo:simple-page-master>
      • </fo:layout-master-set>
      • <fo:page-sequence master-reference=&quot;only&quot;>
      • <fo:flow flow-name=&quot;xsl-region-body&quot;>
      • <fo:block font-size=&quot;20pt&quot; font-family=&quot;serif&quot; line-height=&quot;30pt&quot;>
      • Jussi Pohjolainen
      • </fo:block>
      • <fo:block color=&quot;red&quot; font-size=&quot;30pt&quot; font-family=&quot;serif&quot;>
      • jussi.pohjolainen(at)tamk.fi
      • </fo:block>
      • </fo:flow>
      • </fo:page-sequence>
      • </fo:root>
    11. Transforming XSL-FO - document
      • Once XSL-FO document is generated, it is passed to a FO processor.
      • FO Processor converts the document into something that is readible, printable or both.
        • Most common output is PDF, PS, RTF.
      • FO Processors?
        • XEP, XSLFormatter, XINC and FOP
    12. Example: XSL-FO and Processor XS Processor The possible output formats depends of the features of the XS processor. For example, Apache FOP supports only PDF
    13. Generating FO documents
      • XSL-FO Documents are not meant to be implemented by the programmer.
      • XSL-FO Documents are generated
      • Well Who / What generates XSL FO Documents?
        • It's result of an XSLT – transformation
    14. Main Idea of XSLT: XML -> XHTML XSLT Processor The XSLT Processor can be client-side (browser) or server-side (php, java..)
    15. Main Idea of XSLT: XML -> FO XSLT Processor Now the books.xml is transformed into XSL FO language...
    16. Example: XSL-FO and Processor XS Processor And if you have an fo-document, you can transform it to pdf (for example)
    17. XSL-FO Process in Whole XS Processor XSLT Processor
    18. Example
      • Converting XML to PDF using PHP and Apache FOP
      • Apache FOP
        • http://xmlgraphics.apache.org/fop/
      • Must be installed in your server
        • It is NOT installed in TAMK Environment
    19. XSL-FO Process in Whole FOP PHP
    20. PHP Code
      • <?php
      • // load xslt-file
      • $xslDoc = new DOMDocument();
      • $xslDoc->load(&quot;books_to_fo.xslt&quot;);
      • // load source xml-file
      • $xmlDoc = new DOMDocument();
      • $xmlDoc->load(&quot;books.xml&quot;);
      • // Make transformation
      • $proc = new XSLTProcessor();
      • $proc->importStylesheet($xslDoc);
      • $booksFo = $proc->transformToXML($xmlDoc);
      • // Save the fo document to a file
      • file_put_contents(&quot;books.fo&quot;, $booksFo);
      • // Use fop to create the pdf
      • shell_exec(&quot;fop books.fo books.pdf&quot;);
      • ?>
    21. XSLT AND XPATH
    22. Relationships with the Languages Extensible Stylesheet Language XSL Transformations XSL Formatting Objects XML Path Language uses
    23. XPath
      • Before learning the basics of XSLT, let's look at XPath
        • XPath is a non-XML language that is used with XSLT.
        • XPath is used also in other languages, like XPointer
      • XPath is a language for selecting elements, or nodes, from an XML – document
    24. Selecting Nodes?
      • <?xml version=&quot;1.0&quot;?>
      • <A>
      • <B>
      • <C></C>
      • </B>
      • </A>
      • <!-- Let's select C -->
      • /A/B/C
      XPath
    25. Selecting Nodes (W3schools) Expression Description nodename Selects all child nodes of the named node / Selects from the root node // Selects nodes in the document from the current node that match the selection no matter where they are . Selects the current node .. Selects the parent of the current node @ Selects attributes
    26. Examples (W3schools) Expression Description /bookstore Selects the root element bookstore bookstore/book Selects all book elements that are children of bookstore //book Selects all book elements no matter where they are in the document bookstore//book Selects all book elements that are descendant of the bookstore element, no matter where they are under the bookstore element //@lang Selects all attributes that are named lang
    27. More Examples
      • /bookstore/book[1]
      • /bookstore/book[last()]
      • /bookstore/book[last()-1]
      • /bookstore/book[position()<3]
      • //title[@lang]
      • //title[@lang='eng']
      • /bookstore/book[price>35.00]
      • /bookstore/book[price>35.00]/title
    28. Example of an XSLT-transformation: XML-file
      • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
      • <?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;transform.xslt&quot;?>
      • <book>
      • <title>Programming with Java</title>
      • </book>
    29. Example of an XSLT-transformation: XSLT-file
      • <?xml version=&quot;1.0&quot;?>
      • <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;>
      • <xsl:output method=&quot; text &quot; indent=&quot;yes&quot; encoding=&quot;utf-8&quot;/>
      • <xsl:template match=&quot;/&quot;>
      • Title: <xsl:value-of select=&quot; /book/title &quot;/>
      • </xsl:template>
      • </xsl:stylesheet>
    30. Result: Simple text – file..
      • Title: Programming with Java
    31. Making the Transformation
      • Implement a xml-document
      • Implement a xslt-document
      • Link these two together
      • Output the result with some processor
        • Browser, XML-editor, PHP, Java..
    32. XSLT-transformation with PHP 5
      • <?php
      • // Load the transformation file
      • $xslt = new domDocument();
      • $xslt->load(&quot;transformation.xslt&quot;);
      • // Load the source xml file
      • $myXML = new DomDocument();
      • $myXML->load(&quot;original.xml&quot;);
      • // Add the transformation file to XSLTProcessor
      • $proc = new XSLTProcessor();
      • $proc->importStylesheet($xslt);
      • // Transform the xml and output the result
      • print $proc->transformToXml($myXML);
      • ?>
    33. Examples of XSLT
      • <?xml version=&quot;1.0&quot;?>
      • <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;>
      • <xsl:output method=&quot; text &quot; indent=&quot;yes&quot; encoding=&quot;utf-8&quot;/>
      • <xsl:template match=&quot;/&quot;>
      • Title: <xsl:value-of select=&quot; /book/title &quot;/>
      • </xsl:template>
      • </xsl:stylesheet>
    34. Examples of XSLT
      • <?xml version=&quot;1.0&quot;?>
      • <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;>
      • <xsl:output method=&quot; html &quot; indent=&quot;yes&quot; encoding=&quot;utf-8&quot;/>
      • <xsl:template match=&quot;/&quot;>
      • <html><head><title></title></head>
      • <body>
      • <h1>Title: <xsl:value-of select=&quot;/book/title&quot;/></h1>
      • </body>
      • </html>
      • </xsl:template>
      • </xsl:stylesheet>
    35. Result of Previous XSLT
      • <html><head><title></title></head>
      • <body>
      • <h1>Title: Programming with Java</h1>
      • </body>
      • </html>
      Is this valid xhtml?
    36. Better Version
      • <?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?>
      • <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;>
      • <xsl:output method=&quot;xml&quot; indent=&quot;yes&quot; encoding=&quot;utf-8&quot;
      • doctype-system=&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;
      • doctype-public=&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; />
      • <xsl:template match=&quot;/&quot;>
      • <html><head><title>Example</title></head>
      • <body>
      • <h1>Title: <xsl:value-of select=&quot;/book/title&quot;/></h1>
      • </body>
      • </html>
      • </xsl:template>
      • </xsl:stylesheet>
    37. <xsl:value-of select=&quot;XPath&quot;/>
      • With <xsl:value-of> you can select an element from the source file
      • The value of the select attribute is XPath expression
        • <xsl:value-of select=&quot;books/book/name&quot;/>
    38. for-each
      • <?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?>
      • <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;>
      • <xsl:output method=&quot;xml&quot; indent=&quot;yes&quot; encoding=&quot;utf-8&quot;
      • doctype-system=&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;
      • doctype-public=&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; />
      • <xsl:template match=&quot;/&quot;>
      • <html><head><title>Example</title></head>
      • <body>
      • <xsl:for-each select=&quot;/books/book&quot;>
      • <p><xsl:value-of select=&quot;title&quot;/></p>
      • </xsl:for-each>
      • </body>
      • </html>
      • </xsl:template>
      • </xsl:stylesheet>
      Repeat for every book..
    39. sort
      • <?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?>
      • <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;>
      • <xsl:output method=&quot;xml&quot; indent=&quot;yes&quot; encoding=&quot;utf-8&quot;
      • doctype-system=&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;
      • doctype-public=&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; />
      • <xsl:template match=&quot;/&quot;>
      • <html><head><title>Example</title></head>
      • <body>
      • <xsl:for-each select=&quot;/books/book&quot;>
      • <xsl:sort select=&quot;price&quot; order=&quot;ascending&quot;/>
      • <p><xsl:value-of select=&quot;title&quot;/></p>
      • </xsl:for-each>
      • </body>
      • </html>
      • </xsl:template>
      • </xsl:stylesheet>
      Repeat for every book.. ..and sort them by price
    40. Why this doesn't work?
      • <?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?>
      • <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;>
      • <xsl:output method=&quot;xml&quot; indent=&quot;yes&quot; encoding=&quot;utf-8&quot;
      • doctype-system=&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;
      • doctype-public=&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; />
      • <xsl:template match=&quot;/&quot;>
      • <html><head><title>Example</title></head>
      • <body>
      • <img src=&quot; <xsl:value-of select=&quot;books/book/url&quot;/> &quot; />
      • </body>
      • </html>
      • </xsl:template>
      • </xsl:stylesheet>
      What's wrong with this line?
    41. Using attribute
      • <?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?>
      • <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;>
      • <xsl:output method=&quot;xml&quot; indent=&quot;yes&quot; encoding=&quot;utf-8&quot;
      • doctype-system=&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;
      • doctype-public=&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; />
      • <xsl:template match=&quot;/&quot;>
      • <html><head><title>Example</title></head>
      • <body>
      • <img>
      • <xsl:attribute name=&quot;src&quot;>
      • <xsl:value-of select=&quot;books/book/url&quot;/>
      • </xsl:attribute>
      • </img>
      • </body>
      • </html>
      • </xsl:template>
      • </xsl:stylesheet>

    + Tampere University of Applied SciencesTampere University of Applied Sciences, 2 years ago

    custom

    623 views, 1 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 623
      • 623 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 43
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags