Parallel XSLT Processing of Large XML Documents - XML Prague 2015
Introduction to XML 2. XSLT
-
Upload
elaine-hart -
Category
Documents
-
view
48 -
download
4
description
Transcript of Introduction to XML 2. XSLT
University of Nottingham
School of Computer Science & Information Technology
Introduction to XML2. XSLT
Tim Brailsford
2
University of Nottingham
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
University of Nottingham
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
University of Nottingham
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
University of Nottingham
The Tree Model of XML
6
University of Nottingham
The Tree Model of XML
<definition>
<word> <meaning><etymology> <part-of-speech>
<language> <parts>
<prefix> <word> <meaning>
7
University of Nottingham
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
University of Nottingham
XML Node Relationships Self Parent Ancestor Child Descendant Following Following-Sibling Preceding Preceding-Sibling
9
University of Nottingham
Self
1
10
University of Nottingham
Parent
1
11
University of Nottingham
Ancestor
2
1
12
University of Nottingham
Child
1 2
13
University of Nottingham
Descendant
1 2
3 4 5
14
University of Nottingham
Following
1 4
2 3 5 6
15
University of Nottingham
Following-Sibling
1 2
16
University of Nottingham
Preceding
3
2 1
17
University of Nottingham
Preceding-Sibling
2 1
18
University of Nottingham
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
University of Nottingham
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
University of Nottingham
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
University of Nottingham
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