1 / 18

XSLT

XSLT. Doo Soon Kim. Short tragic story. Once upon a time …. There was a handsome prince. He was traveling in Egypt, …. There, he met a beautiful woman, Cleopatra!!!. He fell in love with her. He wanted to express his love to her.

Télécharger la présentation

XSLT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XSLT Doo Soon Kim

  2. Short tragic story Once upon a time…. There was a handsome prince... He was traveling in Egypt, … There, he met a beautiful woman, Cleopatra!!!

  3. He fell in love with her He wanted to express his love to her. Eoifun;vun fds;ih sj;fai j;fsodij “ fisa;oinv fie fis;j ;oasidj f;asj fdasj; fiosj Hi..I love you....Sweetheart….blah..blah….

  4. What is XSLT? • Extensible Stylesheet Language Transformation • Convert XML documents into other XML documents, into HTML documents or into almost anything you like • defined by XML

  5. History XSL XSLT XPath July, 1999 April, 1999 became Candidate Recommendation November, 2000 became Candidate Recommendation November, 2000 became Recommendation November, 1999

  6. Use case #1 <name> <first_name /> <last_name /><name><job /><age /> translator(interpreter) <name /><occupation /> schema B schema A

  7. Use case #2 Catalog.html Catalog2HTML.xsl Catalog.wml Catalog.xml Catalog2WML.xsl Catalog2RTF.xsl Catalog.rtf

  8. Schema, XML, XSLT, XPATH • Schema : Defines the structure of XML. (grammar) • XML document: follows the schema. (sentence) • XSLT : converts a xml document of one schmeta into the other. (translation) • XPATH : address specific parts of an XML document. (a specific word)

  9. Schema, XSLT, XPATH <card type="simple"> <name>Doo Soon Kim</name> <title>PhD, CS Dept.</title> <email>dskim@cs.utexas.edu</email> <phone>(512) 123-4567</phone> </card> Schema : Top level is card. Card element has 4 children nodes – name, title, email, phone XSLT : Converts it into HTML format (or other formats) XPATH : card/name => name element card[@type] => the type attribute of card ...

  10. Examples • example

  11. <card type="simple"> <name>Doo Soon Kim</name> <title>PhD, CS Dept.</title> <email>dskim@cs.utexas.edu</email> <phone>(512) 123-4567</phone> </card> <html xmlns="http://www.w3.org/1999/xhtml"><title>business card</title> <body><h1>Doo Soon Kim</h1><h3><i>PhD, CS Dept.</i></h3> <p>email: <a href="mailto:dskim@cs.utexas.edu"><tt>dskim@cs.utexas.edu</tt></a></p> <p>phone: (512)123-4567</p> </body></html>

  12. Simple examples <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/1999/xhtml"> <xsl:template match="card[@type='simple']"> <html xmlns="http://www.w3.org/1999/xhtml"> <title>business card</title><body> <xsl:apply-templates select="name"/> <xsl:apply-templates select="title"/> <xsl:apply-templates select="email"/> <xsl:apply-templates select="phone"/> </body></html> </xsl:template> <xsl:template match="card/name"> <h1><xsl:value-of select="text()"/></h1> </xsl:template> <xsl:template match="email"> <p>email: <a href="mailto:{text()}"><tt> <xsl:value-of select="text()"/> </tt></a></p> </xsl:template> ... </xsl:stylesheet> (ref: http://www.brics.dk/~amoeller/XML/xslt-4.1.html)

  13. Understanding a Template • XSLT is a list of XSL templates • XSL Template : If elements are satisfied by match part in a template, replace them with the body of the template • The match patterndetermines where this template applies • Match pattern is defined by XPATH

  14. Examples XPATH <xsl:template match=“title"> <H1><xsl:value-of select="text()"/></H1> </xsl:template> If match holds, do this part! <title> Lord of Ring </title> <H1> Lord of Ring </H1> <title> <H1> Lord of Ring Lord of Ring

  15. More of XSLT • Templates can have programming features inside its bodyIf-then-else, variable, loop, function ... • Provides lots of built-in primitive functions.string manipulator, mathematical functions, ...

  16. Lesson from past project • XFDL(eXtensible Form Description Language) • Built XFDL Editor/Viewer • Intellectual Property Office wanted to provide a patent-form service (over 150) over the internet • Manages patent-related documents as SGML • Key problem : Converting XFDL into SGML patent DTD • Sounds good.....But......

  17. Project failed!! • XFDL : form description language. display-oriented like HTMLPatent DTD : content-oriented. Content-oriented -> Display-oriented : EasyDisplay-oriented -> Content-oriented : Hard • We ended up making different 150 XSLT. • Lesson : You should have a well-defined schema first!

  18. References • XSLT Processors : Saxon, XT, iXSLT, Xalan-Java, Xalan-C++, Sablotron, MSXML(ex. msxml <xsl file> <xml file>) • W3C Recommendation(http://www.w3.org/TR/xslt) • XSLT Editors(http://www.xslt.com/resources.html)

More Related