XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET (Using XSLT style sheet to calculate values based.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
The Web Warrior Guide to Web Design Technologies
Introduction to C Programming
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Tutorial 10 Programming with JavaScript
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Tutorial 11 Working with Operators and Expressions
Tutorial 14 Working with Forms and Regular Expressions.
Tutorial 11 Creating XML Document
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
SD2520 Databases using XML and JQuery
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
JSP Standard Tag Library
Tutorial 14 Working with Forms and Regular Expressions.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
Extensible Stylesheet Language Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University XSL-FO XSLT.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Using Client-Side Scripts to Enhance Web Applications 1.
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
JavaScript, Fourth Edition
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
1 JavaScript in Context. Server-Side Programming.
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations Presenting XML and XBRL.
XP 1 XSLT II Robin Burke ECT 360. XP 2 Outline Conditionals Numbering Functions and operators Variables and parameters Named and recursive templates.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
XP 1 XSLT II Robin Burke ECT 360. XP 2 Homework #4 Forgot we hadn't covered "choose" becomes extra credit My books.xml didn't include descriptions.
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
1 Whitespace Handling Roger L. Costello XML Technologies.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations Presenting XML and XBRL.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
XML Schema – XSLT Week 8 Web site:
1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
CH 15 XSL Transformations 1. Objective What is XSL? Overview of XSL transformations Understanding XSL templates Computing the value of a node with xsl:value-of.
Programming Web Pages with JavaScript
Tutorial 10 Programming with JavaScript
Objectives Insert a script element Write JavaScript comments
Tutorial 10 Programming with JavaScript
Presentation transcript:

XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET (Using XSLT style sheet to calculate values based on data from the source document)

XP New Perspectives on XML, 2 nd Edition Tutorial 7 2 OBJECTIVES In this chapter you will: Learn how to number nodes Apply XPath functions such as count() and sum() Create formulas using mathematical operators Work with text nodes and white space Create variables and parameters

XP New Perspectives on XML, 2 nd Edition Tutorial 7 3 OBJECTIVES In this chapter you will: Create named and recursive templates Work with multiple style sheets Learn how to use extension functions and elements

XP New Perspectives on XML, 2 nd Edition Tutorial 7 4 NUMBERING NODES Goal: add numbers to the items in columns Number nodes using: –Xpath’s position() function Position of the element in the result document Can be used in conditional statements –XSLT element

XP Using the number Element Source document Goblin Fountain Tracer Fire Dragon Fountain Rock the Sky Pyro Blast Style New Perspectives on XML, 2 nd Edition Tutorial 7 5 Numbered list 1.Goblin Fountain 2.Tracer Fire 3.Dragon Fountain 4.Rock the Sky 5.Pyro Blast

XP Counting subset of items Source document Goblin Fountain Tracer Fire Dragon Fountain Rock the Sky Pyro Blast Style New Perspectives on XML, 2 nd Edition Tutorial 7 6 Numbered list 1. Goblin Fountain 2. Dragon Fountain

XP Levels Source document Goblin Fountain Dragon Fountain Tracer Fire Rock the Sky Pyro Blast Style New Perspectives on XML, 2 nd Edition Tutorial 7 7 Numbered list 1. Goblin Fountain 2. Dragon Fountain 1. Tracer Fire 2. Rock the Sky 3. Pyro Blast

XP New Perspectives on XML, 2 nd Edition Tutorial 7 8 USING Nodes are numbered according to position in source document Attributes: –select=expression: any XPath expression that evaluates to a number –count=pattern: specifies which nodes to count –level=type: tree level for nodes to count any = across different levels as if they were all siblings single = items at one level only (defaut) multiple = hierarchy count

XP Hierarchical numbered list Source document Goblin Fountain Dragon Fountain Tracer Fire Rock the Sky Pyro Blast Style /> New Perspectives on XML, 2 nd Edition Tutorial 7 9 Hierarchical list 1. Fountains 1.2. Goblin Fountain 1.2. Dragon Fountain 2. Rockets 2.1. Tracer Fire Rock the Sky Pyro Blast1

XP New Perspectives on XML, 2 nd Edition Tutorial 7 10 USING Attributes: –from=pattern: pattern indicates where numbering should restart –format=pattern: pattern indicates number format 1=integer (1, 2, 3,…) A= alphabetical uppercase (A, B, C, …) a= alphabetical lowercase (a, b, c, …) i= lowercase Roman numerial (i, ii, iii, iv, v, …) I= uppercase Roman numerial (I, II, III IV, V, …) –grouping-size, grouping-separator: indicate how digits are grouped and separator character. For example displays “548710” as “ ”

XP New Perspectives on XML, 2 nd Edition Tutorial 7 11 WORKING WITH XPATH FUNCTIONS Used to calculate numerical values or manipulate text strings Numerical functions: Examples:

XP New Perspectives on XML, 2 nd Edition Tutorial 7 12 XPATH TEXT FUNCTIONS

XP XPATH STRING FUNCTION Example Substring-before (“C101 C102 C103 C104”, “ ”) Locates the first blank space in the text string and extracts all the text before the first blank, e.g., “C101” New Perspectives on XML, 2 nd Edition Tutorial 7 13

XP New Perspectives on XML, 2 nd Edition Tutorial 7 14 WORKING WITH MATHEMATICAL OPERATORS Six operators: Example:

XP New Perspectives on XML, 2 nd Edition Tutorial 7 15 FORMATTING NUMBERS XPath function format-number Syntax: format-number (value, format) Example: format-number ( , “#,##0.00”) displays 56, Another example: format-number ( , “#.##0,00”) displays ,85

XP New Perspectives on XML, 2 nd Edition Tutorial 7 16 NUMBER FORMAT SYMBOLS

XP New Perspectives on XML, 2 nd Edition Tutorial 7 17 Format: Example:

XP New Perspectives on XML, 2 nd Edition Tutorial 7 18 ATTRIUTES

XP New Perspectives on XML, 2 nd Edition Tutorial 7 19 WORKING WITH TEXT NODES AND WHITE SPACE White space: –Space (press space bar), –Tab (pressing the tab key) –new line (pressing Enter key) –carriage return –nonbreaking space  Adjacent elements will have no white space between them can be used to create white space: –Syntax: &#160

XP New Perspectives on XML, 2 nd Edition Tutorial 7 20 CONTROLLING WHITESPACE Stripping space: –Remove text nodes that contain only white space from the result document –Syntax: –where list is a white-space separated list of elements in the source document that contain white space characters –Use * match all nodes

XP New Perspectives on XML, 2 nd Edition Tutorial 7 21 CONTROLLING WHITESPACE Preserving space: –Make sure that text nodes that contain only white space are not deleted –Syntax: –Use * as pattern to match all nodes Normalize space: –Remove leading and trailing spaces –X-pathSyntax: normalize-space(text) –Example: normalize-space (“ goodbye ”) returns the text string “goodbye”

XP New Perspectives on XML, 2 nd Edition Tutorial 7 22 USING VARIABLES User-defined name that stores a particular value or object, such as: Types: –number –text string –node set –boolean value (either true or false) –result tree fragment

XP New Perspectives on XML, 2 nd Edition Tutorial 7 23 VARIABLE SCOPE Global: –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 Local: –Referenced only within template –Can share name with other local or global variable

XP New Perspectives on XML, 2 nd Edition Tutorial 7 24 USING VARIABLES Declaring variables –Syntax: –Example: Names are case-sensitive Value only set once upon declaration Enclose text strings in single-quotes Example Referencing a variable: The name of the company is Note use of $ Not like variables of other languages

XP New Perspectives on XML, 2 nd Edition Tutorial 7 25 COPYING –Syntax: –Shallow copy: only node itself is copied –Syntax: –Deep copy: node and descendants are copied –Example:

XP New Perspectives on XML, 2 nd Edition Tutorial 7 26 USING 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

XP New Perspectives on XML, 2 nd Edition Tutorial 7 27 SETTING PARAMETER VALUES EXTERNALLY Depends on XSLT processor –Some work by appending parameter value to url Web browsers to not allow users to set parameters values directly –Use a JavaScript program from within the browser (see Tutorial 10)

XP New Perspectives on XML, 2 nd Edition Tutorial 7 28 TEMPLATE PARAMETERS Local in scope Created inside element To pass parameter to template –place element in element –Syntax: –No error if calling param name does not match template param name

XP TEMPLATE PARAMETERS Example … styles New Perspectives on XML, 2 nd Edition Tutorial 7 29

XP New Perspectives on XML, 2 nd Edition Tutorial 7 30 INTRODUCING FUNCTIONAL PROGRAMMING Functional programming language: –Relies on the evaluation of functions and expressions, not sequential execution of commands –Different from most other languages

XP New Perspectives on XML, 2 nd Edition Tutorial 7 31 FUNCTIONAL PROGRAMMING PRINCIPLES Main program consists entirely of functions with well-defined inputs Results of program are defined in terms of function outputs No assignment statements; when a variable is declared, its value cannot be changed Order of the execution is irrelevant

XP New Perspectives on XML, 2 nd Edition Tutorial 7 32 FUNCTIONAL PROGRAMMING Easier to maintain and less susceptible to error No order of execution Each time a function is called, it does the same thing, regardless of how many times it has already been called, or the condition of other variables in the program Important to think about the desired end result, rather than the sequential steps needed to achieve that effect

XP New Perspectives on XML, 2 nd Edition Tutorial 7 33 RECURSION In functional programming, recursion takes the place of looping structures Function calls itself

XP New Perspectives on XML, 2 nd Edition Tutorial 7 34 USING NAMED TEMPLATES Template not associated with node set Collection of functions and commands that are accessed from other templates in the style sheet Syntax: styles, variables and parameters

XP USING NAMED TEMPLATES Example New Perspectives on XML, 2 nd Edition Tutorial 7 35

XP New Perspectives on XML, 2 nd Edition Tutorial 7 36 CALLING NAMED TEMPLATES Syntax:...

XP New Perspectives on XML, 2 nd Edition Tutorial 7 37 WRITING A RECURSIVE TEMPLATE Templates that call themselves, usually passing along a new parameter value with each call Needs to have a stopping condition –Expressed in an if statement or a choose statement –If missing, will call itself without end

XP New Perspectives on XML, 2 nd Edition Tutorial 7 38 WRITING A RECURSIVE TEMPLATE Syntax with :

XP New Perspectives on XML, 2 nd Edition Tutorial 7 39 WRITING A RECURSIVE TEMPLATE Syntax with

XP New Perspectives on XML, 2 nd Edition Tutorial 7 40 WORKING WITH MULTIPLE STYLE SHEETS Use or –Not supported by all browsers Use to create a library of XSLT code –Syntax: –Same as inserting the components of included sheet directly into including file –Does not perform a direct text copy Does not copy opening and closing tags Copies the elements and templates within the style sheet

XP New Perspectives on XML, 2 nd Edition Tutorial 7 41 WORKING WITH MULTIPLE STYLE SHEETS –Syntax: –Must be at the top level of the style sheet; must be first child of –If name conflicts occur, importing sheet takes precedence –If you import several style sheets, the last one imported has the highest precedence among the imported sheets in the event of a name conflict.

XP New Perspectives on XML, 2 nd Edition Tutorial 7 42 WORKING WITH EXTENSION FUNCTIONS Provide extended functionality specific to XSLT processor –Caution: use extensions only when you are sure that a given document is always acessed using the same processor. Extension functions - extend the list of functions available to XPath and XSLT expressions Extension elements - extend the list of elements that can be used in an XSLT style sheet Extension attributes - extend the list of attributes associated with XSLT elements Extension attribute values - extend the data types associated with XSLT attributes

XP New Perspectives on XML, 2 nd Edition Tutorial 7 43 WORKING WITH EXTENSION FUNCTIONS Check processor documentation for support EXSLT: –Proposed common set of extensions –Not fully supported by all processors –Some functions supported by: 4XSLT saxon jd.xslt libxslt Xalan-J Because extension functions are not available on all XSLT processors, just be aware of them. They will not be on the final exam

XP New Perspectives on XML, 2 nd Edition Tutorial 7 44 USING EXTENSIONS Modify to include: <xsl:stylesheet version=”1.0” xmlns:xsl=” xmlns:math=” extension-element-prefixes=”math”> Syntax: prefix:function() Test function availability: function-available(“extension”)

XP New Perspectives on XML, 2 nd Edition Tutorial 7 45 EXSLT MATH FUNCTIONS

XP New Perspectives on XML, 2 nd Edition Tutorial 7 46 WRITING EXTENSION FUNCTIONS (MSXML) Add: script commands where language is the language of the script and prefix is the namespace prefix you want to assign to the extension functions script commands are the commands needed to create the extension function Processor used by IE

XP Example: random() <xsl:stylesheet version=“1.0” xmlns:xsl=“ xmlns:jsext:=“ xmlns:msxsl=“urn:schema-microsoft-com:xslt” extension-element-prefixes=“jsext masxsl”> function random() { returns Math.random(); } New Perspectives on XML, 2 nd Edition Tutorial 7 47 Works only with MSXML

XP New Perspectives on XML, 2 nd Edition Tutorial 7 48 SUMMARY and position() are used to number elements XPath provides mathematical and string operators Standard mathematical operators (+, -, etc.) can be used in XSLT Number formatting uses format-number() function

XP New Perspectives on XML, 2 nd Edition Tutorial 7 49 SUMMARY White space characters are controlled with various XSLT elements and XPath functions Variables and parameters are used to supply user- defined values XSLT is a functional programming language Recursive templates provide looping logic in XSLT EXSLT provides a set of extension functions, elements, attributes and attribute values