Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chungnam National University DataBase System Lab. 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014.

Similar presentations


Presentation on theme: "Chungnam National University DataBase System Lab. 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014."— Presentation transcript:

1 Chungnam National University DataBase System Lab. (hyungjun25@cnu.ac.kr)hyungjun25@cnu.ac.kr 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 Whats New in XSLT 2.0

2 Chungnam National University DataBase System Lab. Contents XSLT Status XSLT Overview New Feature of XSLT 2.0 Schema Support Grouping Functions Types Regular Expressions Temporary Trees Sequences Character Maps Conclusion References 2

3 Chungnam National University DataBase System Lab. XSLT Status XSLT 1.0 XSL Transformations (XSLT) Version 1.0 W3C, http://www.w3.org/TR/1999/REC-xslt-19991116http://www.w3.org/TR/1999/REC-xslt-19991116 Published W3C Recommendation : 1999-11-16 XSLT 2.0 XSL Transformations (XSLT) Version 2.0 W3C, http://www.w3.org/TR/2007/REC-xslt20-20070123/http://www.w3.org/TR/2007/REC-xslt20-20070123/ Published W3C Recommendation : 2007-01-23 3

4 Chungnam National University DataBase System Lab. XSLT Overview A language for transforming XML documents The results can be: Same XML document type with filtered data Another XML document type Other text formats HTML WML Delimited text, etc. XSL contains the languages: XPath: expressions for selecting elements in a document XSLT (XSL Transformations) Other languages e.g. XLink, Xpointer 4

5 Chungnam National University DataBase System Lab. Features of XPath Identifies particular parts in XML documents Expressions along the tree structure of XML documents Examples: child::chapter Selects all subordinated elements of chapter child::*[self::chapter] Selects all chapter elements of the context element id(´a23´)/child::chapter[position()=5] Selects the fifth child-element with the name chapter of the element with the unified ID a23 5

6 Chungnam National University DataBase System Lab. Features of XSLT Tree-oriented transformation language based on XML Uses XPath expressions for: Conditional parsing: if / while / test /... Selecting parts of the document: match / select / value-of / template /... Manipulation of strings and numbers Vocabulary for specifying formating: e.g. sorting Variable output formats: e.g. xml, html, plain text,... 6

7 Chungnam National University DataBase System Lab. XSL Transformation 7 XSLT (eXtensible Stylesheet Language Transformations) Input XML Document Converting Rules: Stylesheet(XSL) XPath XML Document HTML WML Plain Text Output …

8 Chungnam National University DataBase System Lab. Example of a XSLT 8 Hello XSLT! Hello XSLT!

9 Chungnam National University DataBase System Lab. Schema Support Grouping Functions Types Regular Expressions Temporary Trees Sequences Character Maps New Feature of XSTL 2.0

10 Chungnam National University DataBase System Lab. Schema Support Need to import schemas to use: user-defined types substitution groups Import with namespace identifies target namespace schema-location locates schema In order to refer to additional types, you must import the schema that defines them: Must specify at least the namespace or the schema location, if not both 10

11 Chungnam National University DataBase System Lab. Implications for XSLT 2.0 Use Well-designed schemas become a useful tool Substitution groups and appropriate types help reduce number of templates Check whether the result conforms to the schema while generating it 11

12 Chungnam National University DataBase System Lab. Grouping XSLT 1.0 allowed sorting, but not SQL-style grouping XSLT 2.0 provides a new, flexible grouping instruction for grouping iterates through a set of groups. Attributes: select: XPath expression for which elements to select group-by: Node by which to group the results group-adjacent: Leaves elements in their original order and groups elements with the same key value together group-starting-with: Specifies a node that will be treated as the beginning of a new group group-ending-with: Specifies a node that will be treated as the end of the group 12

13 Chungnam National University DataBase System Lab. Grouping Functions to know: current-grouping-key() returns the current value of the grouping key shared by members of the group current-group() returns a reference to the current group Grouping by key(Example) 13 1 Italia Milano, Venezia 2 France Paris, Lyon

14 Chungnam National University DataBase System Lab. Implications for XSLT 2.0 Use Much easier to convert from flat to hierarchical structures Processing XHTML to DocBook (or XHTML 2.0) Easier to create indexes Easier to create summaries/roll-ups Easier to create paginated documents 14

15 Chungnam National University DataBase System Lab. Functions XSLT is really a programming language, but in version 1.0 lacked the ability to define new functions XSLT 2.0 rectifies this: You can define new functions These functions can take 0 or more parameters These functions can return a value 15

16 Chungnam National University DataBase System Lab. Functions … wraps the function. Attributes: name: The name of the function as: Data type returned by the function (as an XML Schema data type) override: Whether this function should override previous definitions with the same name and arity (number of xsl:param elements in the function definition) Content of the function: 0 or more elements that define incoming parameters Code to execute – final value can be returned via,, or another expression 16

17 Chungnam National University DataBase System Lab. Function Example 17

18 Chungnam National University DataBase System Lab. Implications for XSLT 2.0 Use General replacement for named templates Particular use where XSLT code can't be used: creating a value to sort by using creating a value to index by using creating a value to group by using carrying out complex tests on nodes, for use in match patterns in templates or keys 18...

19 Chungnam National University DataBase System Lab. Types Strong Typing in XSLT 2.0 The type of a sort key determines how values are sorted If the wrong type of value is passed as a parameter to a template, you will get an error XSLT 2.0 allows you to declare: The type of variables The return type of templates The type of sequences (constructed with xsl:sequence) The return type of (user-declared) functions Both the type and required type of parameters 19

20 Chungnam National University DataBase System Lab. Declaring Types of Variables Declare the type of variables and parameters with as attribute 20 is the integer value 1 is the double value 1.0 is the string 2003-11-20 is the date November 20, 2003 is an error

21 Chungnam National University DataBase System Lab. Implications for XSLT 2.0 Use Easy to get errors from a stylesheet unless you're rigorous in keeping track of types Declare types of variables and parameters Cast elements/attributes to particular types 21

22 Chungnam National University DataBase System Lab. Regular Expressions Within XSLT 2.0, there are three key functions that use regular expressions: Tokenize(string, regex, flags?): Lets you split a string into pieces at each point where a delimiter or pattern occurs matches(string, regex, flags?): Returns a boolean with whether the string in the first argument contains the pattern in the second argument Replace(string, regex, replacement, flags?): Replaces the string or pattern in the first argument with the string in the second argument 22

23 Chungnam National University DataBase System Lab. Regular Expression Instructions XSLT 2.0 has instruction Uses regular expressions to apply markup to a string select attribute selects string regex The pattern to which the string is compared string split into a sequence of matching and non-matching substrings processed in turn by: for matching for non-matching 23

24 Chungnam National University DataBase System Lab. Example String Analysis 24 Mary had a little lamb, Its fleece was white as snow; And everywhere that Mary went The lamb was sure to go. Mary had a little lamb, Its fleece was white as snow; And everywhere that Mary went The lamb was sure to go.

25 Chungnam National University DataBase System Lab. Implications for XSLT 2.0 Use Potential to process any text format comma-delimited and fixed-format files CSS files C#, Java code? These are hard because of matching tags/braces Addition of regular expressions and XSD type support, it now becomes possible for an XSLT 2.0 transformer to read something like a Java or C# header Possible to parse non-comformant HTML files and convert them into valid XHTML. 25

26 Chungnam National University DataBase System Lab. Transclusion Transclusion is the act of dynamically including data from another resource into the current resource Sample code using the document() function: 26 doc1.xml First paragraph Last paragraph

27 Chungnam National University DataBase System Lab. Temporary Trees XSLT 1.0 had Result Tree Fragments Result trees are read-only. Created when use content of Tree that couldn't be accessed with location path Most processors have xxx:node-set() extension function Convert result tree fragment to node tree In XSLT 2.0, have temporary trees Can copy in same way as RTFs Can access without using extension function Provides a instruction to create multiple result documents Provides support for validation 27

28 Chungnam National University DataBase System Lab. Example Temporary Tress 28...... XSLT 1.0 XSLT 2.0

29 Chungnam National University DataBase System Lab. Implications for XSLT 2.0 Use Break up complex transformations into several steps Filter, sort, annotate nodes in early steps Later steps are easier to write Create lookup tables Translate from codes or numbers to labels Similar to arrays or matrices Iteratively process a document until it fulfils some test Add content until a document is valid 29

30 Chungnam National University DataBase System Lab. Sequences Every sequence of instructions creates a sequence of items When a sequence is added to a node: Atomic values are converted to text nodes Spaces added between atomic values Nodes are copied to create children 30 sequence of any items sequence of new n odes children of node

31 Chungnam National University DataBase System Lab. Sequences The instruction is used to construct sequences of nodes or atomic values (or both) Adds existing nodes or new atomic values to a sequence returns a sequence of integers. returns a sequence of doubles. 31

32 Chungnam National University DataBase System Lab. Using Sequences in XSLT 2.0 Iterate over a sequence Create a text node from a sequence 32 Thompson, Tobin

33 Chungnam National University DataBase System Lab. Implications for XSLT 2.0 Use Less need for recursive templates Use integer sequences to iterate a number of times Use to build node sequences by iteration rather than recursion Less need for temporary elements Atomic values don't need to be wrapped in an element in order to be passed around in a list 33

34 Chungnam National University DataBase System Lab. Character Maps Character maps give you greater control over serialization. They map a Unicode character to any string in the serialized document For XML and HTML output methods, the resulting character stream does not have to be well-formed The mapping occurs only at serialization: it is not present in result tree fragments This facility can be used instead of disabled output escaping in most cases 34

35 Chungnam National University DataBase System Lab. Conclusion XSLT 2.0 introduces a lot of new features Many stylesheets can be simpler: multi-step processing with temporary trees Grouping using user-defined functions for repetitive code Stylesheet applications can be simpler: Multiple result documents should reduce need for client-side scripting XSLT 2.0 expands into text parsing Using schemas/types well will make things easier; not using them will make things harder 35

36 Chungnam National University DataBase System Lab. References W3C, XSL Transformations (XSLT) Version 1.0 http://www.w3.org/TR/1999/REC-xslt- 19991116, 16, November. 1999http://www.w3.org/TR/1999/REC-xslt- 19991116 W3C, XSL Transformations (XSLT) Version 2.0 http://www.w3.org/TR/2007/REC-xslt20- 20070123/, 12, January. 2007http://www.w3.org/TR/2007/REC-xslt20- 20070123/ Steve Heckler, XSLT20.ppt, Accelebrate Kurt Cagle, Reevaluating XSLT 2.0, 9, March. 2007 36


Download ppt "Chungnam National University DataBase System Lab. 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014."

Similar presentations


Ads by Google