Internet Technologies1 XSLT Processing XML using XSLT Using XPath
Internet Technologies2 Processing XML using XSLT XSLT is available in Java and C#/.NET
Internet Technologies3 The Catcher in the Rye J. D. Salinger Little, Brown and Company Input
Internet Technologies4 <xsl:stylesheet xmlns:xsl=" version="1.0"> Processing
Internet Technologies5 The Catcher in the Rye J. D. Salinger Little, Brown and Company Output
Internet Technologies6 The Catcher in the Rye J. D. Salinger Little, Brown and Company Input
Internet Technologies7 <xsl:stylesheet xmlns:xsl=" version="1.0"> The default rules matches the root, library and block elements.
Internet Technologies8 The Catcher in the Rye J. D. Salinger Little, Brown and Company The output is the same.
Internet Technologies9 The Catcher in the Rye J. D. Salinger Little, Brown and Company Cliff Notes on The Catcher in the Rye Two books in the input
Internet Technologies10 <xsl:stylesheet xmlns:xsl=" version="1.0"> What’s the output?
Internet Technologies11 The Catcher in the Rye J. D. Salinger Little, Brown and Company Cliff Notes on The Catcher in the Rye Illegal HTML
Internet Technologies12 The Catcher in the Rye J. D. Salinger Little, Brown and Company Input
Internet Technologies13 <xsl:stylesheet xmlns:xsl=" version="1.0"> <!-- --> We are not matching on publisher.
Internet Technologies14 The Catcher in the Rye J. D. Salinger Little, Brown and Company We get the default rule matching the publisher and then printing its child.
Internet Technologies15 The Catcher in the Rye J. D. Salinger Little, Brown and Company Input
Internet Technologies16 <xsl:stylesheet xmlns:xsl=" version="1.0"> We can skip the publisher by matching and stopping the recursion.
Internet Technologies17 The Catcher in the Rye J. D. Salinger
Internet Technologies18 The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company A shelf has many books.
Internet Technologies19 <xsl:stylesheet xmlns:xsl=" version="1.0"> Will this do the job?
Internet Technologies20 The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company This is not what we want.
Internet Technologies21 The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company Same input.
Internet Technologies22 <xsl:stylesheet xmlns:xsl=" version="1.0"> Found a shelf Checks for a shelf and quits.
Internet Technologies23 Found a shelf Output
Internet Technologies24 The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company Same input.
Internet Technologies25 <xsl:stylesheet xmlns:xsl=" version="1.0"> These are a few of my favorite books Produce a table of books.
Internet Technologies26 These are a few of my favorite books 1 The Catcher in the Rye J. D. Salinger Little, Brown and Company 2 The XSLT Programmer's Reference Michael Kay Wrox Press 3 Computer Organization and Design Patterson and Henessey Morgan Kaufmann
Internet Technologies27
Internet Technologies28 One More Time -- Input The Catcher in the Rye J. D. Salinger Little, Brown and Company Mindfulness In Plain English J. D. Salinger Wisdom Publications Boston To Kill A Mokingbird Harper Lee Addison-Wesley
Internet Technologies29 One More Time -- XSLT <xsl:stylesheet xmlns:xsl=" version="1.0"> These are a few of my favorite books Let’s do some calculations on the fly.
Internet Technologies30 One More Time - Output
Internet Technologies31 XPATH Non-xml language used to identify particular parts of an xml document Used by XSLT for matching and selecting particular elements to be copied into the result tree. Used by Xpointer to identify a particular point in or part of an xml document that an Xlink links to. Slides adapted from “XML in a Nutshell” by Harold
Internet Technologies32 XPATH First, we’ll look at three commonly used XSLT instructions: xsl:value-of xsl:template xsl:apply-templates
Internet Technologies33 XPATH The xsl:value-of element computes the string value of an Xpath expression and inserts it into the result tree. XPath allows us to select nodes in the tree and different node types produce different values.
Internet Technologies34 XPATH element => the text content of the element after all tags are stripped text => the text of the node attribute => the value of the attribute root => the value of the root processing-instruction => the processing instruction data (, and the target are not included comment => the text of the comment (no comment symbols) namespace => the namespace URI node set => the value of the first node in the set
Internet Technologies35 XPATH The xsl:template top-level element is the key to all of xslt. The match attribute contains a pattern (location path) against which nodes are compared as they’re processed. If the pattern matches a node, then the contents are instantiated
Internet Technologies36 XPATH Find and apply the highest priority template that matches the node set expression. If the select attribute is not present then all children of the context node are processed.
Internet Technologies37 The Tree Structure of an XML Document Alan Turing computer scientist mathematician cryptographer See Harold Pg. 147
Internet Technologies38 Richard M Feynman physicist Playing the bongoes Unicode ‘M’
Internet Technologies39 / person born = “1914” died = “1952” id=“p342” person name first_name Alan <!– Did the word “computer scientist” exist in Turing’s day?”-- > profession
Internet Technologies40 The root Element Nodes Text Nodes Attribute Nodes Comment Nodes Processing Instructions Namespace Nodes Nodes seen by XPath Constructs not seen by XPath CDATA sections Entity references Document Type Declarations
Internet Technologies41 Note The following appears in each example below so it has been removed from the slides. <xsl:stylesheet xmlns:xsl=" version="1.0" > :
Internet Technologies42 Location Paths The root matched the root matched the root
Internet Technologies43 Location Paths Child element location paths (relative to context node) computer scientist
Internet Technologies44 Location Paths Attribute location paths (relative to context node) 1912
Internet Technologies45 Location Paths Attribute location paths (relative to context node)
Internet Technologies46 Location Paths Comment Location Step (comments don’t have names) Did the word "computer scientist" exist in Turing's day?
Internet Technologies47 Location Paths Comment Location Step comment deleted Document content with comments replaced as shown. Default – no comments output
Internet Technologies48 Location Paths Text Location Step (Text nodes don’t have names) computer scientist
Internet Technologies49 Location Paths Processing Instruction Location Step type="text/xsl" href = "pi.xsl"
Internet Technologies50 Location Paths Wild cards There are three wild cards: *, The * matches any element node. It will not match attributes, text nodes, comments or processing instructions nodes.
Internet Technologies51 Location Paths Matching with * Matches all elements and requests calls on sub-elements only. Nothing is displayed. The text nodes are never reached.
Internet Technologies52 Location Paths Matching with node() The node() wild card matches all nodes: element nodes, text nodes, attribute nodes, processing instruction nodes, namespace nodes and comment nodes.
Internet Technologies53 Matching with Node What is the output?
Internet Technologies54 Matching with Node -Output
Internet Technologies55 Location Paths Matching wild card matches all attribute nodes.
Internet Technologies56 Matching Found an attribute What is the output?
Internet Technologies57 Matching - Output Found an attribute 1912 Found an attribute 1954 Found an attribute p342 Found an attribute 1918 Found an attribute 1988 Found an attribute p4567
Internet Technologies58 Matching p p4567
Internet Technologies59 Location Paths Multiple matches with | Matches all the elements. Skips the text nodes unless they describe a profession or hobby.
Internet Technologies60 Location Paths Selecting from all descendants with // // selects from all descendants of the context node as well as the context node itself. At the beginning of an Xpath expression, it selects from all descendants of the root node.
Internet Technologies61 Location Paths Selecting from all descendants with // TuringFeynman
Internet Technologies62 Location Paths Selecting from all descendants with // Alan
Internet Technologies63 Location Paths Selecting from all descendants with // AlanRichard
Internet Technologies64 Location Paths Selecting from all descendants with // Richard
Internet Technologies65 Specifying the Child Axis Consider the following path: /Envelope/Header/Signature The above is an abbreviation for /child::Envelope/child::Header/child::Signature
Internet Technologies66 Using an Axis
Internet Technologies67 What is the output?
Internet Technologies68 Richard M Feynman Alan Turing Axis Example - Output
Internet Technologies69 Writing Output to an Attribute
Internet Technologies70 Writing Output to an Attribute
Internet Technologies71 Predicates In general, an Xpath expression may refer to more than one node. Predicates allow us to reduce the number of nodes we are interested in. Each step in a location path may have a predicate that selects from the node list that is current at that step in the expression. The boolean expression in the predicate is tested against each node in the context node list. If the expression is false then that node is deleted from the list.
Internet Technologies72 Predicates Richard M Feynman
Internet Technologies73 Predicates Richard M Feynman physicist Playing the bongoes
Internet Technologies74 Predicates Alan Turing computer scientist mathematician cryptographer
Internet Technologies75 Predicates Richard M Feynman physicist Playing the bongoes
Internet Technologies76 Predicates <xsl:apply-templates select = < 1950]/ name[first_name='Alan']" /> Alan Turing
Internet Technologies77 General XPath Expressions Xpath expressions that are not node sets can’t be used in the match attribute of an xsl:template element. They can be used for the values for the select attribute of xsl:value-of elements and in location path predicates.
Internet Technologies78 General XPath Expressions
Internet Technologies79 General XPath Expressions Xpath Functions Person Person 1 Person 2
Internet Technologies80 General XPath Expressions Xpath Functions Mr. T. Mr. T. Alan Turing Node set converted to string