SDPL 2007XSLT: Additional Features and Computing1 5.1 Additional Features n XPath for arithmetics, cross-references, and string manipulation n Generating.

Slides:



Advertisements
Similar presentations
XML III. Learning Objectives Formatting XML Documents: Overview Using Cascading Style Sheets to format XML documents Using XSL to format XML documents.
Advertisements

Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined.
Advanced XSLT. Branching in XSLT XSLT is functional programming –The program evaluates a function –The function transforms one structure into another.
Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 12 Extensible Stylesheet Language Transformations : XSLT.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XML: Managing Data Exchange Stylesheets. Lesson Contents CSS The basic XSL file XSL transforms Templates Sort Numbering Parameters and Variables Datatypes.
SDPL 2003Notes 5.1: Additional XPath & XSLT1 5.1 Additional features of XPath & XSLT n XPath support for –arithmetical operations –processing ID/IDREF.
SDPL 2011XSLT: Additional features & Computing1 4.1 Additional XSLT Features n XPath for arithmetics, cross-references, and string manipulation n Generating.
SDPL 2005Notes 5.1: Additional XPath & XSLT1 5.1 Additional features of XPath & XSLT n XPath support for –arithmetics –processing ID/IDREF cross-references.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)
XSL Transformations (XSLT) Meghasyam Bokam April’1 st, 2002.
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
A note on generating text with the xsl:value-of instruction.
XML Workshop XSLT. XML Tagged data Hello A really interesting course, well taught Interchange of data RSS, BPEL4WS, RossettaNet … Structure document representation.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
CS 4408 Lecture 9. XSLT instruction elements We have seen that a template can contain non-XSLT text, canned text that it inserts into the result tree.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.
SDPL 2001Notes 5.1: Additional XPath & XSLT1 5.1 XPath & XSLT: Additional features n XPath support for –arithmetical operations –processing ID/IDREF cross-references.
More on XSLT. More on XSLT variables Earlier we saw two ways to associate a value with a variable  A variable whose value is the empty string, for example.
XSLT XSLT: eXtensible Stylesheet Language for Transformations - a language for transforming XML documents into any text- based format (e.g. HTML, plain.
ECA 228 Internet/Intranet Design I Intro to XSL. ECA 228 Internet/Intranet Design I XSL basics W3C standards for stylesheets – CSS – XSL: Extensible Markup.
10/06/041 XSLT: crash course or Programming Language Design Principle XSLT-intro.ppt 10, Jun, 2004.
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
CSE3201/CSE4500 Information Retrieval Systems
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.
SDPL 2006XSLT: Additional Features and Computing1 5.1 Additional Features n XPath support for –arithmetics –processing ID/IDREF cross-references –manipulation.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
XSLT. XSL comprises of –XSLT: Is a language for transforming XML documents into other XML documents –FO: XML vocabulary for specifying formatting XSL.
Transforming XML Part II XML Document Transformation with XSLT John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
Processing of structured documents Spring 2003, Part 7 Helena Ahonen-Myka.
XPath. Why XPath? Common syntax, semantics for [XSLT] [XPointer][XSLT] [XPointer] Used to address parts of an XML document Provides basic facilities for.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XSLT part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
Lecture 11 XSL Transformations (part 1: Introduction)
Computing & Information Sciences Kansas State University Thursday, 15 Mar 2007CIS 560: Database System Concepts Lecture 24 of 42 Thursday, 15 March 2007.
SDPL 2002Notes 5.1: Additional XPath & XSLT1 5.1 Additional features of XPath & XSLT n XPath support for –arithmetical operations –processing ID/IDREF.
 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 – XSL: Extensible Stylesheet Language Transformations (XSLT) Outline 12.1Introduction 12.2Setup.
SDPL 2001Notes 5: XSLT1 5. Document Transformations n XSLT (W3C Rec. Nov-99) –A language for transforming XML documents »representative of features common.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
SDPL 2002Notes 5.2: Computing with XSLT1 5.2 Computing with XSLT n XSLT is principally a declarative rule-based language –Can we express procedural computations.
SDPL 20064: Introduction to Style Sheets1 4. Introduction to Style Sheets n Discussed recently: –(APIs for) procedural manipulation of documents n Now.
XPath. XPath, the XML Path Language, is a query language for selecting nodes from an XML document. The XPath language is based on a tree representation.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
XP 1 XSLT II Robin Burke ECT 360. XP 2 Outline Conditionals Numbering Functions and operators Variables and parameters Named and recursive templates.
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.
1 XMLXSL(T) and CSS NOEA/PQC (rev. fen) 2007 Stylesheets CSS:Cascading Style Sheets XSL(T):eXtended Stylesheet Language (Transformations)
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
SDPL 2004Notes 4: Intro to Style Sheets1 4. Introduction to Style Sheets n Discussed recently: –Programmatic manipulation of documents n Now a more human.
XSLT I Robin Burke ECT 360. Outline History / Terminology XSLT processing XSLT syntax XPath XSLT basics Lab.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations Presenting XML and XBRL.
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.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
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.
Notes 5.2: Computing with XSLT
XML Path Language Andy Clark 17 Apr 2002.
CS 431 – February 28, 2005 Carl Lagoze – Cornell University
Presentation transcript:

SDPL 2007XSLT: Additional Features and Computing1 5.1 Additional Features n XPath for arithmetics, cross-references, and string manipulation n Generating text –for content –for attribute values n Repetition, sorting and conditional processing n Numbering document contents 5.2 Computing with XSLT

SDPL 2007XSLT: Additional Features and Computing2 XPath: Arithmetics Double-precision floating-point operators +, -, *, div, mod (same as % in Java) Double-precision floating-point operators +, -, *, div, mod (same as % in Java) »e.g. 2.3 mod 1.1 ≈ 0.1 Rounding numbers up, down, and to the closest integer: floor(x), ceiling(x),round(x) Rounding numbers up, down, and to the closest integer: floor(x), ceiling(x),round(x) Formatting numbers as strings (e.g.): Formatting numbers as strings (e.g.): »format-number( , " 0.0 " ) = " -1.3 " –XSLT 1.0 function; uses Java decimal format patterns

SDPL 2007XSLT: Additional Features and Computing3 Aggregate Functions n Counting nodes »count( node-set ) –and summing them as numbers »sum( node-set ) n Example: –Average of observed temps below current node: div count(.//obs)

SDPL 2007XSLT: Additional Features and Computing4 Cross-referencing Function id selects elements by their unique ID Function id selects elements by their unique ID –NB: ID attributes must be declared in DTD (See an example later) n Examples: –id('sect:intro') selects the element with unique ID "sect:intro" –id('sect:intro')/auth[3] selects the third auth of the above element –id('sect1 sect2 sect3') selects 3 sections (with corresponding ID values)

SDPL 2007XSLT: Additional Features and Computing5 String manipulation Equality and inequality of strings with operators = and != Equality and inequality of strings with operators = and != –"foo" = 'foo' ; (NB alternative quotes) –"foo" != "Foo" Testing for substrings: Testing for substrings: –starts-with("dogbert", "dog") = true() –contains("dogbert", "gbe") = true() n Concatenation (of two or more strings), –concat("dog", "bert") = "dogbert"

SDPL 2007XSLT: Additional Features and Computing6 XPath: more string functions –substring-before("ftp://a", "//") = substring-before("ftp://a", "/") = "ftp:" –substring-after("ftp://a", "/")= "/a" –string-length("dogbert")=7 –substring( string, start, length? ): »substring("dogbert", 1, 3) = "dog" »substring("dogbert", 3) = "gbert" –translate( Str, Replaced, Replacing ): »translate("doggy","dgo","Ssi") = "Sissy"

SDPL 2007XSLT: Additional Features and Computing7 Generating Text Insert text nodes with a computed value in the result: Insert text nodes with a computed value in the result: –if Expr gives a node-set, the value of the first node in document order is used (in XSLT 2.0 all, space-separated) n Example: Transform elements like Charlie Parker Charlie Parker to the form Charlie ("Bird") Parker

SDPL 2007XSLT: Additional Features and Computing8 Computing generated text (2) This can be specified by template rule This can be specified by template rule (" ") (" ") Verbatim text (like the white-space above) can be inserted using xsl:text Verbatim text (like the white-space above) can be inserted using xsl:text

SDPL 2007XSLT: Additional Features and Computing9 Attribute value templates The string-value of an expression can be inserted in an attribute value by surrounding the expression by braces { and } The string-value of an expression can be inserted in an attribute value by surrounding the expression by braces { and } Example: Transform source element Example: Transform source element<photo> Mary.jpg Mary.jpg into form into form

SDPL 2007XSLT: Additional Features and Computing10 Attribute value templates (2) Attribute value templates (2) This can be specified by template rule This can be specified by template rule Expressions {file} and are evaluated in the context of the current node (the photo element) Expressions {file} and are evaluated in the context of the current node (the photo element)

SDPL 2007XSLT: Additional Features and Computing11 XSLT: Repetition Nodes can be "pulled" from source for processing using Template Nodes can be "pulled" from source for processing using Template –Template is applied to the selected nodelist, each node in turn as the current() node »in document order, unless sorted using xsl:sort instructions (see later)

SDPL 2007XSLT: Additional Features and Computing12 Example (of for-each ) n Format the below document as HTML: ]> The Joy of XML Getting Started Helen Brown says that processing XML documents is fun. Dave Dobrik agrees. Family affairs Bob Brown is the husband of Helen Brown. Finishing Up As we discussed in, processing XML documents is fun. ]> The Joy of XML Getting Started Helen Brown says that processing XML documents is fun. Dave Dobrik agrees. Family affairs Bob Brown is the husband of Helen Brown. Finishing Up As we discussed in, processing XML documents is fun.

SDPL 2007XSLT: Additional Features and Computing13 Example: Table of contents n A table of contents can be formed of section titles: Table of Contents Table of Contents

SDPL 2007XSLT: Additional Features and Computing14 Example (cont; Cross references) Cross-refs can also be processed using for-each: Cross-refs can also be processed using for-each: Section (...) Section (...) With this rule the source fragment With this rule the source fragment As we discussed in As we discussed in becomes As we discussed in Section (Getting …)

SDPL 2007XSLT: Additional Features and Computing15 XSLT Sorting A sorted order for the processing of nodes with xsl:for- each and xls:apply-templates can be specified by A sorted order for the processing of nodes with xsl:for- each and xls:apply-templates can be specified by controlled by attributes of xsl:sort, like controlled by attributes of xsl:sort, like –select : expression for the sort key (default: "." ) –data-type : "text" (default) or "number" –order : "ascending" (default) or "descending" The first xsl:sort specifies the primary sort key, the second one the secondary sort key, and so on. The first xsl:sort specifies the primary sort key, the second one the secondary sort key, and so on.

SDPL 2007XSLT: Additional Features and Computing16 Example (cont; Sorted index of names) All names can be collected in a last-name-first-name order using the below template All names can be collected in a last-name-first-name order using the below template Index, Index, n This creates an UL list with items Brown, Bob Brown, Helen Brown, Helen Dobrik, Dave Brown, Bob Brown, Helen Brown, Helen Dobrik, Dave Possible to eliminate duplicates? Yes, but a bit tricky. See next

SDPL 2007XSLT: Additional Features and Computing17 Conditional processing n A template can be instantiated or ignored with Template Template Example: a comma-separated list of names: Example: a comma-separated list of names:,,

SDPL 2007XSLT: Additional Features and Computing18 An aside: Meaning of position() Evaluation wrt the current node list. The above applied to a b c d by invocation yields" a,b,c,d " (← single node list); Evaluation wrt the current node list. The above applied to a b c d by invocation yields" a,b,c,d " (← single node list); With invocation from we'd get " a,b " and " c,d " (Clever, and tricky!) With invocation from we'd get " a,b " and " c,d " (Clever, and tricky!)

SDPL 2007XSLT: Additional Features and Computing19 Conditional processing (2) A case construct (  switch in Java): A case construct (  switch in Java): … … … … … </xsl:choose>

SDPL 2007XSLT: Additional Features and Computing20 Example (cont; Eliminating duplicate names) Only the current() node accessible in current node list Only the current() node accessible in current node list –but can refer to nodes in the source tree –Process just the first one of duplicate name s:,, </xsl:for-each>

SDPL 2007XSLT: Additional Features and Computing21 Numbering Document Contents Formatted numbers can be inserted in the result tree by element Formatted numbers can be inserted in the result tree by element –by the position of the current node in the source tree –nodes to be counted specified by a count pattern –supports common numbering schemes : single-level, hierarchical, and sequential through levels n Typical cases in following examples »(Complete specification rather complex) n Example 1: Numbering list items

SDPL 2007XSLT: Additional Features and Computing22 Generating numbers: Example 1 n n item itemitemolapricotbananacoconut apricotbananacoconut

SDPL 2007XSLT: Additional Features and Computing23 Generating numbers: Example 2 n Hierarchical numbering (1, 1.1, 1.1.1, 1.1.2, …) for titles of chapters, titles of their sections, and titles of subsections:

SDPL 2007XSLT: Additional Features and Computing24 Generating numbers: Example chapSweets title title Berries sect subsect Cherry titlechaptitle Vegetables... Sweets Sweets Berries Berries Cherry Cherry Vegetables Vegetables

SDPL 2007XSLT: Additional Features and Computing25 Example 2: Variation n As above, but number titles within appendices with A, A.1, A.1.1, B.1 etc:

SDPL 2007XSLT: Additional Features and Computing26 Example 2: Variation AA.1A.1.1B appendix Sweetstitletitle Berries sect subsect Cherry title titleVegetables... Sweets Sweets Berries Berries Cherry Cherry Vegetables Vegetablesappendix

SDPL 2007XSLT: Additional Features and Computing27 Generating numbers: Example 3 Sequential numbering of notes within chapters : (more precisely: starting anew at the start of any chapter) Sequential numbering of notes within chapters : (more precisely: starting anew at the start of any chapter)

SDPL 2007XSLT: Additional Features and Computing28 Ex 3: Sequential numbering from chap chap Yes!note noteNo! sect Perhaps?note noteOK... (1)(2)(3)(1) Yes! Yes! No! No! Perhaps? Perhaps? OK OK chap

SDPL 2007XSLT: Additional Features and Computing Computing with XSLT n XSLT is a declarative rule-based language –for XML transformations –Could we use it for general computing? –What is the exact computational power of XSLT? n We've seen some programming-like features: –iteration over source nodes ( xsl:for-each ) »in XSLT 2.0 iteration over arbitrary sequences –conditional evaluation ( xsl:if and xsl:choose )

SDPL 2007XSLT: Additional Features and Computing30 Computing with XSLT n Further programming-like features: –variables (names bound to non-updatable values): –variables (names bound to non-updatable values): –callable named templates with parameters: –callable named templates with parameters:

SDPL 2007XSLT: Additional Features and Computing31 Result Tree Fragments Result tree fragments built by templates can be stored, too: BAR Result tree fragments built by templates can be stored, too: BAR They can only be used as string values substring($fooBar, 2, 2) = "AR" They can only be used as string values substring($fooBar, 2, 2) = "AR" or inserted in the result: or inserted in the result: (XSLT 2.0 allows unlimited processing of (computed) sequences) (XSLT 2.0 allows unlimited processing of (computed) sequences)

SDPL 2007XSLT: Additional Features and Computing32 Visibility of Variable Bindings The binding is visible in following siblings of xsl:variable, and in their descendants: The binding is visible in following siblings of xsl:variable, and in their descendants:

SDPL 2007XSLT: Additional Features and Computing33 A Real-Life Example We used LaTeX to format an XML article. For this, we needed to map source table structures... to corresponding LaTeX environments: \begin{tabular}{lll} %3 left-justified cols... \end{tabular} We used LaTeX to format an XML article. For this, we needed to map source table structures... to corresponding LaTeX environments: \begin{tabular}{lll} %3 left-justified cols... \end{tabular} n How to do this?

SDPL 2007XSLT: Additional Features and Computing34 Possible solution (for up to 4 columns) \begin{tabular}{l } \begin{tabular}{l } \end{tabular} \end{tabular}</xsl:template>  OK, but inelegant!  How to support arbitrarily many columns? 1">l 1">l</xsl:if > 2">l 2">l</xsl:if > 3">l > 3">l

SDPL 2007XSLT: Additional Features and Computing35 More General Solution (1/2) Pass the column-count to a named template which generates the requested number of ‘ l ’s: Pass the column-count to a named template which generates the requested number of ‘ l ’s: \begin{tabular}{ } \begin{tabular}{ } \end{tabular} \end{tabular}

SDPL 2007XSLT: Additional Features and Computing36 Solution 2/2: Recursive gen-cols 0"> 0"> </xsl:template> formal parameters

SDPL 2007XSLT: Additional Features and Computing37 Stylesheet Parameters Stylesheet can get params from command line, or through JAXP with Transformer.setParameter(name, value) : Stylesheet can get params from command line, or through JAXP with Transformer.setParameter(name, value) : </xsl:transform> $ java -jar saxon.jar dummy.xml double.xslt In= default value

SDPL 2007XSLT: Additional Features and Computing38 Computational power of XSLT n XSLT seems quite powerful, but how powerful is it? –Implementations provide extension mechanisms, e.g., to call arbitrary Java methods –Are there limits to XSLT processing that we can do without extensions? n Any algorithm can be shown computable with plain XSLT –by simulating Turing machines, by a recursive named template with string parameters (see 2005 lecture notes, or References)

SDPL 2007XSLT: Additional Features and Computing39 What does this mean? n XSLT has full algorithmic power –(It is "Turing-complete") –Is this intentional? »Awkward as a general-purpose programming language! –Impossible to recognise non-terminating transformations automatically (  the "halting problem" has no algorithmic solution) »could attempt "denial-of-service" attacks with non-terminating style sheets(!)