Download presentation
Presentation is loading. Please wait.
Published byClifton Richard Modified over 8 years ago
1
XP 1 XSLT II Robin Burke ECT 360
2
XP 2 Homework #4 Forgot we hadn't covered "choose" becomes extra credit My books.xml didn't include descriptions
3
XP 3 Outline Conditionals Numbering Functions and operators Variables and parameters Named and recursive templates
4
XP 4 Conditional nodes XSLT supports two kinds of conditional elements: If is only if-then (no else) Choose is more general
5
XP 5 Example if choose
6
XP 6 Comparison operators
7
XP 7 Predicates XPath expressions test for a condition result = set of nodes that fulfill that condition Format elementName[condition]
8
XP 8 Example from last week
9
XP 9 Numbering Issues what is counted? what is the format of the numbering? how are numbers at different places in the tree related?
10
XP 10 Numbering Number nodes using: position() Using position(): Nodes are numbered by position in result document Can be used in conditional statements
11
XP 11 Using Attributes: from=pattern: pattern indicates where numbering should restart format=pattern: pattern indicates number format grouping-size, grouping-separator: indicate how digits are grouped and separator character
12
XP 12 Number element Nodes are numbered according to position in source document More flexibility
13
XP 13 Example numbering with position numbering with number element
14
XP 14 Number element Attributes: value=expression: any XPath expression that evaluates to a number (i.e. position()) count=pattern: specifies which nodes to count level=type: tree level for nodes to count; can be any, single, or multiple
15
XP 15 Numbering, cont’d count attribute indicates what is being counted default = count elements of the same name otherwise = specify an XPath pattern all matching elements included
16
XP 16 Numbering relationships how does the number of one element depend on other elements? Possibilities only depends on immediate siblings single depends on “parent” multiple depends on “cousins” any
17
XP 17 Formatting format type 1, a, A, i, I other punctuation
18
XP 18 Example table of contents
19
XP 19 Internal computations Often performed using XPath sort of like SQL Can perform calculations of nodes selected by an XPath expression XPath functions
20
XP 20 XPath numerical functions
21
XP 21 XPath string functions
22
XP 22 XPath operators
23
XP 23 Example Calculating the average Problem redundant calculation
24
XP 24 Variables Not variable! User-defined name that stores a particular value or object Types: number text string node set boolean result tree fragment
25
XP 25 Using variables Syntax: Example: Names are case-sensitive Value only set once upon declaration Enclose text strings in single-quotes
26
XP 26 Using variables, cont'd Value can be XPath expression Value can be XML fragment Syntax:
27
XP 27 Variable reference Syntax: $variable-name Example: $Months Except Referencing tree fragments: Do not use $variable-name Use to reference value
28
XP 28 Global variables Can be referenced from anywhere within the style sheet Must be declared at the top level of the style sheet, as a direct child of the element Must have a unique variable name Evaluated only once when stylesheet is invoked
29
XP 29 Local variables Referenced only within template Can share name with other local or global variable Reevaluated when template is used
30
XP 30 Examples average with variables
31
XP 31 Number format XPath function format-number Syntax: format-number(value, format) Example: format-number(56823.847, '#,##0.00') displays 56,823.85
32
XP 32 Number format syntax
33
XP 33 Decimal format XSL element for defining number formats Named decimal format passed as argument to format-number
34
XP 34 Example average with format
35
XP 35 Parameters Similar to variables, but: Value can be changed after it is declared Can be set outside of scope Syntax: Example: To reference: $param-name
36
XP 36 External parameters Depends on XSLT processor Some work by appending parameter value to url Command line processors allow external parameter setting: MSXML Saxon
37
XP 37 Template parameters Local in scope Created inside element Used to pass parameters to template
38
XP 38 Idea Called template contains param definitions Calling template place element in element or element Syntax: No error if calling param name does not match template param name
39
XP 39 Named template Template not associated with node set Collection of commands that are accessed from other templates in the style sheet Syntax: XSLT elements
40
XP 40 Calling named templates Syntax:...
41
XP 41 Example average with named template
42
XP 42 Functional programming Functional programming language: Relies on the evaluation of functions and expressions, not sequential execution of commands Different from C family of languages LISP, Scheme, ML
43
XP 43 Templates as functions A template supplies a result fragment incorporated into the final document think of this as substitution function call replaced by result
44
XP 44 Iteration How to handle iteration with templates? stars for ratings Possibilities convert numbers into node sets weird since node sets are supposed to come from the document recursive templates
45
XP 45 Recursion base case when do I stop? recursive case how do I bite off one piece call template again with the rest
46
XP 46 Example Template: star(rating) desired output: # stars = # in rating Base case: rating = 0 output: nothing Recursive case rating > 0 output: * plus result of star (rating-1)
47
XP 47 Example, cont'd star(3) replaced by * star(2) replaced by ** star(1) replaced by *** star(0) ***
48
XP 48 Pseudocode stars (n) if n = 0 return '' else return '*' + stars(n-1)
49
XP 49 Recursive pattern Syntax with :.........
50
XP 50 Example ratings with stars
51
XP 51 Another example "best rated" jeep supplier Finding maximum built into XSLT 2.0
52
XP 52 Recursive statement?
53
XP 53 What about the name?
54
XP 54 Homework #5 Case 1 from Chapter 7 Plus doing it "correctly" with CSS Also 10/27 Schema milestone for final project
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.