1 / 21

Introduction to XML 2. XSLT

Introduction to XML 2. XSLT. Tim Brailsford. XSL / XSLT / FO. eXtensible Stylesheet Language A language (an XML application) to define the appearance and behaviour of an XML document. Transformation The logical restructuring of a “source document” to produce a “result document”.

elaine-hart
Download Presentation

Introduction to XML 2. 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. Introduction to XML2. XSLT Tim Brailsford

  2. XSL / XSLT / FO • eXtensible Stylesheet Language • A language (an XML application) to define the appearance and behaviour of an XML document. • Transformation • The logical restructuring of a “source document” to produce a “result document”. • For example XML  HTML • Formatting • The precise description of screen/page layout. • XSLT vs FO

  3. The XSLT Language • XML syntax (using the xsl: namespace) • XSL language consists of directives (ie elements in this namespace) • Rule-based • stylesheets consist of a series of templates that contain rules for the processing of a particular element. • XSL stylesheets are not a sequential programming language - rules are applied depending upon the logical structure of the document. • Rules may be conditional • XSL may contain variables (numeric or string), it may perform arithmetic calculations. • There is a library of parameterised functions

  4. The Tree Model of XML <definition> <word>export</word> <part-of-speech>vt</part-of-speech> <meaning> Send out (goods) to another country</meaning> <etymology> <language>Latin</language> <parts> <part> <prefix>ex</prefix> <meaning>out</meaning> </part> <part> <word>portare</word> <meaning>to carry</meaning> </part> </parts> </etymology> </definition>

  5. The Tree Model of XML

  6. The Tree Model of XML <definition> <word> <meaning> <part-of-speech> <etymology> <language> <parts> <prefix> <word> <meaning>

  7. XML Node Types • Root Node • The top level node (1 per document) • Element Node • An element bound by a start and finish tag (or a single empty-element tag) • Text Node • A sequence of consecutive characters (PCDATA) • Attribute Node • The name and value of an attribute inside an element • Comment Node • Processing Instruction Node • Namespace Node

  8. XML Node Relationships • Self • Parent • Ancestor • Child • Descendant • Following • Following-Sibling • Preceding • Preceding-Sibling

  9. Self 1

  10. Parent 1

  11. Ancestor 2 1

  12. Child 1 2

  13. Descendant 1 2 3 4 5

  14. Following 1 4 2 3 5 6

  15. Following-Sibling 1 2

  16. Preceding 3 2 1

  17. Preceding-Sibling 2 1

  18. XSL Templates • <xsl:template match=“GREETING”> . . .</xsl:template> • Templates contain transformation rules • either XSL directives or valid XML output. • Templates are matched to an XML node. see greeting-1.xsl

  19. XPATH • XPATH is a sub-language within XSLT - used to identify components of the document. • XPATH expressions can be used to match a template, or the contents of an element. • Example: <xsl:template match=“GREETING”>

  20. Example XPATH Expressions • <xsl:template match=“GREETING”> • <xsl:template match=“GREETING/MESSAGE/TITLE”> • <xsl:value-of select=“MESSAGE”> • <xsl:value-of select=“@title”> ./MESSAGE ../MESSAGE */MESSAGE MESSAGE/TITLE|MESSAGE/BODY ancestor(CHAPTER)/HEAD BOOK[@title] BOOK[not(@title)] //BOOK[@category=‘fiction’]

  21. XSL apply-templates directive • <xsl:apply-templates /> • Specifies that immediate children of a node should be processed further. • It is possible to specify which children with an optional “select=xpath”<xsl:apply-templates select=“book” /> see greeting-2.xsl

More Related