Download presentation
Presentation is loading. Please wait.
1
Introduction to XSLT Transparency No. 1 Introduction to XSLT Cheng-Chia Chen
2
Introduction to XSLT Transparency No. 2 What is XSLT ? XSLT is a language for transforming XML documents into other [XML] documents. XML syntax Possible output formats: XML HTML TEXT XSL Processor XSL XML HTML (or XML or text)
3
Introduction to XSLT Transparency No. 3 Outlines Transform XML Documents into HTML Documents Transform XML Documents into other XML Documents Transform XML Documents into Texts. Note: Most slide materials adapted from Roger L. CostelloRoger L. Costello
4
Introduction to XSLT Transparency No. 1 Transform XML Documents into HTML Documents
5
Introduction to XSLT Transparency No. 5 HTML Generation Use XSL to generate HTML documents. XSLT viewed as a tool to fill in the content of an HTML document with data extracted from an XML Document. XSLT provides elements (tags) for extracting the XML data
6
Introduction to XSLT Transparency No. 6 Enhancing HTML Documents with XML Data XML Document HTML Document (with embedded XSL elements) XSL element XML data
7
Introduction to XSLT Transparency No. 7 Enhancing HTML Documents with the Following XML Data Jeff 555-1234 555-4321 lightgrey FitnessCenter.xml
8
Introduction to XSLT Transparency No. 8 HTML Document in an XSL Template <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> Welcome Welcome!
9
Introduction to XSLT Transparency No. 9 Note The HTML is embedded within an XSL template, which is an XML document Consequently, the HTML must be well formed, i.e., every start tag must have an end tag Because the HTML is embedded within an XSL template, we are able to add XSL elements to the HTML, allowing us to extract data out of XML documents Let's customize the HTML welcome page by putting in the member's name. This is achieved by extracting the name from the XML document. We use an XSL element to do this
10
Introduction to XSLT Transparency No. 10 Extracting the Member Name <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> Welcome Welcome !
11
Introduction to XSLT Transparency No. 11 Extracting a Value from an XML Document, Navigating the XML Document Extracting values: use the XSL element Navigating: … is an XPath expression with matched node as context node. Recall what the location path : /FitnessCenter/Member/Name means: "Start from the top of the XML document, go to the FitnessCenter element, from there go to the Member element, and from there go to the Name element."
12
Introduction to XSLT Transparency No. 12 The tree view of fitnessCenter.xml Document / PI Element FitnessCenter Element Member Element Member Element Member Element Name Element Phone Element Phone Element FavoriteColor... Text Jeff Text 555-1234 Text 555-4321 Text lightgrey...
13
Introduction to XSLT Transparency No. 13 Extract the FavoriteColor and use it as the bgcolor <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> Welcome Welcome !
14
Introduction to XSLT Transparency No. 14 Notes Attribute values cannot contain " “ The following is NOT valid: <Body bgcolor="<xsl:value-of select='/FitnessCenter/Member/FavoriteColor'/>"> To extract the value of an XML element and use it as an attribute value you must use curly braces: 1.Evaluate the expression within the curly braces. 2.Assign the value to the attribute.
15
Introduction to XSLT Transparency No. 15 Extract the Home Phone Number <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> Welcome Welcome ! Your home phone number is:
16
Introduction to XSLT Transparency No. 16 Note In this example we want "the Phone element where the value of its type attribute equals 'home' ": The expression within […] is called a "predicate". Its purpose is to filter. Note the use of the single quotes within the double quotes. select=" … ' …' …"
17
Introduction to XSLT Transparency No. 17 Review - HTML Table This will create a table with 3 rows - the first row contains a header for each column. The next two rows contains the table data.
18
Introduction to XSLT Transparency No. 18 Fruit Color Apple Red Banana Yellow Fruit Color Apple Red Banana Yellow
19
Introduction to XSLT Transparency No. 19 Create a Table of Phone Numbers Suppose that a Member has an arbitrary number of phone numbers (home, work, cell, etc). Create an HTML table comprised of the phone numbers. On each row of the table put the type (home, work, cell, etc) in one column and the actual phone number in the next column.
20
Introduction to XSLT Transparency No. 20 Welcome Welcome ! Your phone numbers are: Type Number
21
Introduction to XSLT Transparency No. 21 Iterating through XML Elements <!- - Within here we are at one of the Phone elements. Thus, in <xsl:value-of select="path", the value for path is relative to where we are in the XML document. The "." refers to the Phone element that we are currently positioned at. - ->
22
Introduction to XSLT Transparency No. 22 Special Offer to Platinum Members Enhance the example to provide a special offer to "platinum" members. We need to check if the "level" attribute on the Member element equals "platinum".
23
Introduction to XSLT Transparency No. 23 Welcome Welcome ! Our special offer to platinum members today is... Your phone numbers are: Type Number
24
Introduction to XSLT Transparency No. 24 Conditional Processing Use the IfTruePart element to perform conditional processing. Note: It is needless to add in the value of test attribute extra { and }, which must appear in
25
Introduction to XSLT Transparency No. 25 Accessing Multiple Parts of the XML Document Enhance the table to contain three columns: the name of the Member, the type of the phone (home, work, cell, etc), and the actual phone number.
26
Introduction to XSLT Transparency No. 26 Welcome Welcome ! Our special offer to platinum members today is... Your phone numbers are: Name Type Number
27
Introduction to XSLT Transparency No. 27 Getting the Name when accessing the Phone Member Phone 555-1234 Phone 555-4321 Name Jeff Notice how we access the Name with respect to the Phone element Via the location path../Name We can access elements in other parts of the XML tree via the “../” operator... Name
28
Introduction to XSLT Transparency No. 28 Other ways to Access the XML Data "Select the Name of the first Member" "Select the Name of the first Member" "Select the Name of the last Member" Note: Assume that there are multiple Members
29
Introduction to XSLT Transparency No. 29 Other ways to Access the XML Data (cont.) <!- - Process all Name elements which have FitnessCenter as an ancestor - ->
30
Introduction to XSLT Transparency No. 30 Enhanced XML Document Jeff 555-1234 555-4321 lightgrey David 383-1234 383-4321 lightblue Roger 888-1234 888-4321 lightyellow Note that each Member now has a unique id (the id attribute)
31
Introduction to XSLT Transparency No. 31 Review - HTML Hyperlinking … Click Here... This creates an internal hyperlink (the source anchor links to the target anchor).
32
Introduction to XSLT Transparency No. 32 Hyperlink Name to Home Phone Problem: 1. create an HTML document that has two tables: - a Member Name table, and - a Member home Phone number table. 2. Hyperlink the Member's Name to his/her Phone.
33
Introduction to XSLT Transparency No. 33 Name Home Phone Number
34
Introduction to XSLT Transparency No. 34 Numbering There is an XSL element that returns a number corresponding to the element's position in the set of selected nodes. Output: 1. Jeff 2. David 3. Roger
35
Introduction to XSLT Transparency No. 35 Start Numbering from 0 How would you start the numbering from zero, rather than one?
36
Introduction to XSLT Transparency No. 36 format attribute of xsl:number With the format attribute we can specify the format of the generated number, i.e., 1, 2, 3 or I, II, III, or A, B, C, or A.1, A.2, A.3, or … format= “ 1 ” generates the sequence: 1, 2, 3, … format= “ 01 ” generates: 01, 02, 03, … format= “ A ” generates: A, B, C, … format= “ a ” generates: a, b, c, … format= “ I ” generates: I, II, III, … format= “ i ” generates: i, ii, iii,...
37
Introduction to XSLT Transparency No. 37 format attribute of xsl:number. Output: A. Jeff B. David C. Roger
38
Introduction to XSLT Transparency No. 38 Sorting There is an XSL element that sorts the elements that you extract from the XML document "For each Member, sort the Name elements" Output: David Jeff Roger
39
Introduction to XSLT Transparency No. 39 Sorting Note: 1. Sort occurs before iteration. 2. I.e. The set of Member elements selected by xsl:for-each is sorted using the Name child element. This occurs prior to the first iteration of the loop.. After the set of Member elements are sorted then the looping begins
40
Introduction to XSLT Transparency No. 40 concat() function concat(destination string, strings to add) Note: if you want to concatenate more than one string to the destination string then simply add more arguments
41
Introduction to XSLT Transparency No. 41 Output: Welcome Jeff! Welcome David! Welcome Roger!
42
Introduction to XSLT Transparency No. 42 xsl:variable This XSL element allows you to create a variable to hold a value (which could be a string or a subtree of the XML document). The variable is referenced by $variable-name This creates a variable called hello, that has a value which is the literal string, ‘Hello World’. We could use this variable as follows: Value = This will output: Value = Hello World
43
Introduction to XSLT Transparency No. 43 Member's Phone Numbers: Name Type Number
44
Introduction to XSLT Transparency No. 44 xsl:variable This creates a variable called member, that has a value which is a subtree. We could use this variable as follows: Name = Home Phone = This will result in generating: Name = Jeff Home Phone = 555-1234 Member... Name Phone Jeff 555-1234 555-4321
45
Introduction to XSLT Transparency No. 45 xsl:variable A variable is “ write once, read many ”. That is, you can assign a variable a value only once, but then you can retrieve the value of the variable many times. A variable declaration is visible to the following siblings and its descendants. This region is the scope of the variable binding.
46
Introduction to XSLT Transparency No. 46 The name variable's scope Do Lab2, Part 1 Member's Phone Numbers: Name Type Number …
47
Introduction to XSLT Transparency No. 47 Global Variables Are variables declared outside of template elements. <xsl:stylesheet mlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> Value of Pi The value of pi = …
48
Introduction to XSLT Transparency No. 48 Problem Create a variable, names, to contain a list of the Member Names, with each name separated by a slash. How would you create such a variable? First attempt: Member's Names: Output: A parameter or variable with the same name already exists in the current scope.
49
Introduction to XSLT Transparency No. 49 Problem - Solution In all previous examples of creating a variable we declared the name of the variable and then had a select attribute which gave the variable its value. We can omit the select attribute: - Do stuff in here. All output will go into the names “box”.
50
Introduction to XSLT Transparency No. 50 Problem - Solution Member's Names: / Output: Member's Names: Jeff/David/Roger
51
Introduction to XSLT Transparency No. 51 contains() function contains(string to be tested, test string) returns true if string to be tested contains test string $greeting contains ‘welcome’
52
Introduction to XSLT Transparency No. 52 xsl:choose xsl:choose allows you to elegantly express multiple conditional tests. Here ’ s the structure: [action] [action] [action] The first xsl:when statement that evaluates to true is executed. If none evaluates to true then the xsl:otherwise statement is executed.
53
Introduction to XSLT Transparency No. 53 substring-before() String Function Here’s the form of this string function: substring-before(string, pattern) Example: “Get the contents of Phone and put it into the variable called ‘phone’. Then extract from the content of ‘phone’ the string before the '-' (i.e., the telephone exchange)”. 555-1234 substring-before($phone, ‘-’) 555 phone
54
Introduction to XSLT Transparency No. 54 substring-after() String Function Here’s the form of this string function: substring-after(string, pattern) Example: “Get the contents of Phone and put it into the variable called ‘phone’. Then extract from the content of ‘phone’ the string after the '-'”. 555-1234 substring-after($phone, ‘-’) 1234 phone
55
Introduction to XSLT Transparency No. 55 starts-with() String Function Here’s the form of this string function: starts-with(string, pattern) Example: [action] “If the Phone starts with the string, ‘555’ then do [action]”.
56
Introduction to XSLT Transparency No. 56 substring() function substring(string, i, len?) returns the substring of string that starts at the ith position and has length, len. The length argument (len) is optional. If not present then this function returns the substring starting at the ith position all the way to the end of the string. Note: the first character is at position 1 (not 0 as with some languages) substring(‘1234567890’, 2, 5) returns ‘23456’
57
Introduction to XSLT Transparency No. 57 string-length() function string-length(string) returns the length of the string string-length(‘ 1234567890 ’) returns 10
58
Introduction to XSLT Transparency No. 58 translate() function translate(string, from-pattern, to-pattern) Example. translate(“Hello”, “ABCDEFGHIJKLMNOPQRSTUVWXYZ”, “abcdefghijklmnopqrstuvwxyz”); this will convert Hello to hello (i.e., convert to lower case) A better approach to the above problem is: translate(“Hello”, $upperCaseChars, $lowerCaseChars) Note: need to put the string within (single) quotes, otherwise the XSL Processor will try to interpret it as an XML element.
59
Introduction to XSLT Transparency No. 59 Boolean and Relational Operators Boolean operators: not, and, or Relational operators:, =, =, != The less than signs are reserved symbols, so they need to be escaped when you use them. Thus, the relational operators will appear in your XSL code like this: = = != < > = <= >= != Want this: Use this:
60
Introduction to XSLT Transparency No. 60 Arithmetic The arithmetic operators available: +, -, *, div, mod (remainder from doing a division) Note: recall that an XML element can have a dash in the name. So, if you want to indicate subtraction, be sure to surround “ - ” with blank spaces.
61
Introduction to XSLT Transparency No. 61 Arithmetic functions sum(node-set) this function sums up all the values in the set of nodes floor(number) returns the largest integer that is not greater than number Example. floor(2.5) returns 2 ceiling(number) returns the smallest integer that is not less than number Example. Ceiling(2.5) returns 3 round(number) returns the integer closest to number Example. round(2.3) returns 2
62
Introduction to XSLT Transparency No. 62 Enhanced XML Document Jeff 555-1234 555-4321 lightgrey 340 David 383-1234 383-4321 lightblue 500 Roger 888-1234 888-4321 lightyellow 340 Note that each Member now has MembershipFee element
63
Introduction to XSLT Transparency No. 63 Compute Membership Revenue Membership Fee Revenue:
64
Introduction to XSLT Transparency No. 64 xsl:attribute This XSL element is used by nesting it within an output element. It enables you to create an attribute for the output element.
65
Introduction to XSLT Transparency No. 65 Coloring alternate rows Member Names: yellow For each even row of the table, the TR value will be:
66
Introduction to XSLT Transparency No. 66 count() function count(set of node) returns an integer representing the number of nodes (i.e., XML elements) in the set. Example. Number of members = Output: Number of members = 5
67
Introduction to XSLT Transparency No. 67 Selecting all Elements/Attributes...... For each attribute do... For each child element do...
68
Introduction to XSLT Transparency No. 68 Getting the Name of the Element/Attribute using the name() Function Attribute = Element = name(node) returns the name of "node"
69
Introduction to XSLT Transparency No. 69 When to use Curly Braces? “ When I assign an attribute a value, when do I use curly braces and when do I not use them? ” Use curly braces for these attributes: - the attribute of a literal result element (where you literally type what should be output) Example: - the name attribute of xsl:attribute Example: - the name attribute of xsl:pi Example: - the name attribute of xsl:element Example: - the optional attributes of xsl:sort: Example: <xsl:sort order ={@value} lang =“{@value}” data-type ={@value} case-order =“{@value}”>
70
Introduction to XSLT Transparency No. 70 document( ) Function This function enables you to access other XML documents (besides the XML document that you specify when you invoke the XSL Processor). The format for using the document() function is: document(url), where url is a URL to another XML document
71
Introduction to XSLT Transparency No. 71 Fitness Centers Merger Another fitness center has just merged with us. They have an xml document (FitnessCenter2.xml) containing their Members. You are to create an XSL-enhanced HTML document that creates a single table comprised of all the Members from both fitness clubs.
72
Introduction to XSLT Transparency No. 72 Name Phone(home)... <xsl:variable name="FitnessCenter2" select="document('file://localhost/xml-course/.../FitnessCenter2.xml')"/>
73
Introduction to XSLT Transparency No. 73 Parameterized Processing You can create a subroutine (called a named template), and you can pass to it parameters.
74
Introduction to XSLT Transparency No. 74 Fitness Center <xsl:with-param name="name" select="/FitnessCenter/Member[1]/Name"/>...
75
Introduction to XSLT Transparency No. 75 Call by Reference How do we create a named template that returns a value? Example: create a named template which, when passed a number, returns the number div 2.
76
Introduction to XSLT Transparency No. 76 Fitness Center 16 / 2 =
77
Introduction to XSLT Transparency No. 77 generate-id() Use this function to generate a unique string for a node in the source document tree. Example. generate-id(/FitnessCenter/Member[1]) will return a unique id for the first Member Note: for the same node e, generate-id(e) will always produce the same id.
78
Introduction to XSLT Transparency No. 78 Using generate-id() to Uniquely Identify Elements In previous example we created two tables –previous example a table containing the Members Names, and a separate table containing home Phone numbers. Each Name was hyperlinked to his/her home Phone. We used the id attribute on each Member element to link the two tables together. Suppose there is no id attribute. We can use generate-id() to create a unique identifier.
79
Introduction to XSLT Transparency No. 79 Name Home Phone Number
80
Introduction to XSLT Transparency No. 1 Use XSLT to transform XML Documents
81
Introduction to XSLT Transparency No. 81 Note All the xsl functionality that we have learned at previous slides are applicable in transforming XML documents
82
Introduction to XSLT Transparency No. 82 Transformation Language XSL may be used as a transformation language it may be used to transform an XML document into another XML document (perhaps the new one is the same, minus company sensitive data) Transformation Engine (XSLT Processor) XSL XML
83
Introduction to XSLT Transparency No. 83 Example: Filter Gold Members Jeff 555-1234 555-4321 lightgrey David 383-1234 383-4321 lightblue Roger 888-1234 888-4321 lightyellow Jeff 555-1234 555-4321 lightgrey Roger 888-1234 888-4321 lightyellow
84
Introduction to XSLT Transparency No. 84 A pseudo code for XSLT Process model: process(Node: node): tree-fragment rules = match(node); // find rules matching this node rule = rules.best(); // find the best among all rules result = rule.appliedTo(node) // this may recursively call process() return result. main() { return process( root-node ) }.
85
Introduction to XSLT Transparency No. 85 XML Transformations - all about (Template) “ Rules ” Each template rule has two parts: A pattern or matching part, that - identifies the XML node in the source document to which the action part is to be applied. Matching information is contained in an attribute. An action part that - details the transformation of the node
86
Introduction to XSLT Transparency No. 86 XSLT Document Structure [action] [action] [action]...
87
Introduction to XSLT Transparency No. 87 Template Rules Template rules take the following general form: [ action ]
88
Introduction to XSLT Transparency No. 88 Template Rules (Example) “Use this rule when the processor parse through the XML document and get to a element.” “Go to each of my children (the Member children) and apply the template rules to them.”
89
Introduction to XSLT Transparency No. 89 Terminology In FitnessCenter.xml we have (snippet): Jeff 555-1234 555-4321 lightgrey... “Member is a child element of the FitnessCenter element. Name, Phone, Phone, and FavoriteColor are children elements of the Member element. Member is a parent of Name. FitnessCenter and Member are ancestors of Name.”
90
Introduction to XSLT Transparency No. 90 xsl:element Used to compute/create output elements. xsl:element is used to create elements [contents of the new element] [contents of the new element] creates
91
Introduction to XSLT Transparency No. 91 Identity Transformation Create a stylesheet which simply creates an XML document that is a copy of the input XML document
92
Introduction to XSLT Transparency No. 92 Document / PI Element FitnessCenter Element Member Element Member Element Member Element Name Element Phone Element Phone Element FavoriteColor... Text Jeff Text 555-1234 Text 555-4321 Text lightgrey...
93
Introduction to XSLT Transparency No. 93 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> default selection
94
Introduction to XSLT Transparency No. 94
95
Introduction to XSLT Transparency No. 95 Jeff 555-1234 555-4321 lightgrey David 383-1234 383-4321 lightblue Roger 888-1234 888-4321 lightyellow Note that we've lost the attribute on the Member element The output
96
Introduction to XSLT Transparency No. 96 For each attribute Add an attribute to the element being output. The name of the attribute is the name of the current attribute being processed. The value of the attribute is the value of the current attribute being processed. Getting Member’s Attribute:
97
Introduction to XSLT Transparency No. 97 Jeff 555-1234 555-4321 lightgrey David 383-1234 383-4321 lightblue Roger 888-1234 888-4321 lightyellow
98
Introduction to XSLT Transparency No. 98 Generalize previous identity stylesheet only work for FitnessCenter XML documents. Make a stylesheet which does an identity transformation on any XML document.
99
Introduction to XSLT Transparency No. 99 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
100
Introduction to XSLT Transparency No. 100 Default Template Rules Every xsl document has two default template rules Applied when the XSL Processor cannot find a template rule to use in your stylesheet. Here are the two default template rules: “Match on the document or any element. The action is to go to the children and execute their template rules.” “Match on a text node. The action is to output the value of the text node.”
101
Introduction to XSLT Transparency No. 101 Multiple Applicable Rules Suppose we are finding rules to be applied to a node. But now there are two rules matched:...... // the default rule Which one will the processor choose to apply? Answer: given two rules that apply, the more specific rule wins. --> Clearly, “*” is much more general than “Member”. “*” matches on any element. “Member” just matches on the Member element.
102
Introduction to XSLT Transparency No. 102 Smallest Identity Transformation Stylesheet Now that we know about the default template rules, we can further reduce the size of the stylesheet.
103
Introduction to XSLT Transparency No. 103 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
104
Introduction to XSLT Transparency No. 104 The xsl:apply-templates element (without the select attribute) tells the XSL Processor to apply the template rules to all children (in document order) The xsl: apply-templates element can have a select attribute that tells the XSL Processor to process only the child element that matches “ pattern ”. Thus, the select attribute rule enables us to specify the order in which the children are processed
105
Introduction to XSLT Transparency No. 105 "Go to the template rule for my Name child element. Then go to the template rule for the work Phone child element." "Go to all the child element nodes (not to any child text nodes)."
106
Introduction to XSLT Transparency No. 106 mode Attribute Allows you to create multiple template rules for the same element. Each template rule can process the element differently. So, you can have multiple template rules for the same element. Just give each template rule a different mode
107
Introduction to XSLT Transparency No. 107 Problem Identity transform the FitnessCenter.xml document. However, after you have copied all the Members, follow up with a (new) GoldMembers section, containing the name of each gold member (within stars) The next slide shows what the output XML file should look like
108
Introduction to XSLT Transparency No. 108 Jeff 555-1234 555-4321 lightgrey David 383-1234 383-4321 lightblue Roger 888-1234 888-4321 lightyellow ***David*** Note that the names here are processed differently than the name in the GoldMembers section
109
Introduction to XSLT Transparency No. 109
110
Introduction to XSLT Transparency No. 110 *** ***
111
Introduction to XSLT Transparency No. 111 Stylesheet Reuse via xsl:include and xsl:import The elements xsl:include and xsl:import enable you to reuse other stylesheets. These elements are “ top-level elements ”. This means that they must be immediate children of the xsl:stylesheet element (i.e., they cannot be within a template rule) The xsl:include element is basically a macro substitution - the element is replaced by the contents of stylesheet it references
112
Introduction to XSLT Transparency No. 112 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">...... Replace the xsl:include element with the contents of the referenced stylesheet (i.e., all the children of xsl:stylesheet) toUpperCase.xsl
113
Introduction to XSLT Transparency No. 113 xsl:import xsl:import acts just like xsl:include - the stylesheet that it references is macro-substituted. However, there is a difference: With xsl:include the stuff that is macro-substituted into the stylesheet has the same precedence as the rest of the stylesheet. It is as though you had one stylesheet. With xsl:import the stuff that is macro-substituted into the stylesheet has lower precedence than the rest of the stylesheet. Also, all xsl:import elements must come first in the stylesheet.
114
Introduction to XSLT Transparency No. 1 Transform XML Documents into Text Files
115
Introduction to XSLT Transparency No. 115 Problem Create a stylesheet that creates a text file containing each member's data. One line per member Member data separated by a slash delimiter Jeff/555-1234/555-4321/lightgrey David/383-1234/383-4321/lightblue Roger/888-1234/888-4321/lightyellow
116
Introduction to XSLT Transparency No. 116 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
117
Introduction to XSLT Transparency No. 1 More Examples
118
Introduction to XSLT Transparency No. 118 Examples transform some data represented in XML using three different XSLT stylesheets to produce three different representations of the data, HTML, SVG and VRML. The input data: 10 9 7 4 3 4 6 -1.5 2
119
Introduction to XSLT Transparency No. 119 transforms the data into HTML using simplified syntax: <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" lang="en"> Sales Results By Division Division Revenue Growth Bonus
120
Introduction to XSLT Transparency No. 120 <xsl:sort select="revenue" data-type="number" order="descending"/> color:red
121
Introduction to XSLT Transparency No. 121 The HTML output <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> Sales Results By Division Division Revenue Growth Bonus North 10 9 7 West 6 -1.5 2 South 4 3 4
122
Introduction to XSLT Transparency No. 122 Transform the data into SVG: <xsl:stylesheet version="1.0“ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd"> Revenue Division
123
Introduction to XSLT Transparency No. 123 <rect x="{$pos}" y="{150-$height}" width="20" height="{$height}"/>
124
Introduction to XSLT Transparency No. 124 The SVG output <svg width="3in" height="3in" xmlns="http://www.w3.org/Graphics/SVG/svg-19990412.dtd"> Revenue Division North 10 South 4 West 6
125
Introduction to XSLT Transparency No. 125 Transforms the data into VRML <xsl:stylesheet version="1.0“ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" encoding="UTF-8" media-type="model/vrml"/> #VRML V2.0 utf8 # externproto definition of a single bar element EXTERNPROTO bar [ field SFInt32 x field SFInt32 y field SFInt32 z field SFString name ] "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl"
126
Introduction to XSLT Transparency No. 126 # inline containing the graph axes Inline { url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wr l" } bar { x y z name " " }
127
Introduction to XSLT Transparency No. 127 The VRML Output #VRML V2.0 utf8 # externproto definition of a single bar element EXTERNPROTO bar [ field SFInt32 x field SFInt32 y field SFInt32 z field SFString name ] "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl" # inline containing the graph axes Inline {url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl" } bar {x 10 y 9 z 7 name "North" } bar {x 4 y 3 z 4 name "South" } bar {x 6 y -1.5 z 2 name "West" }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.