124.11.lec14

124.11.lec14 - CS 124/LINGUIST 180: From Languages to...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 124/LINGUIST 180: From Languages to Information Dan Jurafsky Lecture 14: XPath, XSLT Slides from Daniela Florescu, Donald Kossmann, Miles Efron, Dan Suciu, Matt Hottell, Minos Garofalakis, and Joe Hellerstein. Copyright all of them. XML   Last 9me:   Introduc9on to XML   Schemas   DTD   This 9me:   Doing stuff with XML documents Letter to Twitter “Twitter mailing address” “Twitter address” Web Search Today   Web document: bag of words   HTML: presenta9on language <I>! Twitter<BR>! 795 Folsom St<BR>! San Francisco, CA <BR> </I> ! <I>! Terriyaki sauce<BR>! One egg<BR>! New York steak<BR> ! </I>   Difficult to iden9fy structure/seman9cs A first step - XML   Focus on structure/seman9cs instead of layout <I>! Twitter<BR>! 795 Folsom St<BR>! San Francisco, CA<BR> “Twitter mailing address”! ! </I> address[.*name=“Twitter”]! <address>! <company name=“Twitter”>! <street>795 Folsom St</street>! <city>San Francisco</city>! <state>CA</state>! </address> Step 2: Manipulating XML files   XSLT   eXtensible Stylesheet Language Transforma9ons   A way to derive dynamic views of informa9on   A language used to transform a given XML document into another document   Xpath address[.*name=“Twitter”]   A way of specifying elements of an XML document. Why might we want to transform XML documents?   Rendering XML into other formats for viewing:   HTML   LaTeX   PDF   Portable devices   Deriving alternate views of informa9on for differing contexts.   Informa9on Extrac9on from XML ­structured documents XSL Processing XML ??? XSL Processor XSL XSLT Stylesheets   An XML doc itself   Root element is “stylesheet”.   Simplest possible stylesheet just has that root (and a namespace defini9on): <?xml version="1.0"?> <xsl:stylesheet version="1.0” xmlns:xsl="h^p://www.w3.org/1999/XSL/Transform"> </xsl:stylesheet> What does that empty stylesheet do?   h^p://cs124.stanford.edu/xml/names.xml   h^p://cs124.stanford.edu/xml/empty.xsl   h^p://www.ibiblio.org/mefron/xml/xsl/form.html An XSLT program <xsl:stylesheet version="1.0" xmlns:xsl= http://www.w3.org/1999/XSL/Transform>! !<xsl:template …..>! !………! !</xsl:template>! !<xsl:template …..>! Each template rule specifies how certain nodes from the input XML doc have !………! to be reformatted in the output !</xsl:template>! </xsl:stylesheet>! XSLT template rules   An element named xsl:template   Which has an a^ribute named match   That contains a pa^ern   And a template   that is instan9ated and output when the pa^ern is matched pattern template <xsl:template match="person">A Person</xsl:template> template rule What does that one-line stylesheet do?   h^p://cs124.stanford.edu/xml/names.xml   h^p://cs124.stanford.edu/xml/printnames.xsl   h^p://www.ibiblio.org/mefron/xml/xsl/form.html Slightly more complex   The xsl:value ­of element   Gets the string value (text content) of an element   The element iden9fied by a select a^ribute containing an XPath expression.   And inserts this text content into the output   <xsl:value ­of select="name"/>   Means:   “take the string value of the name element” Printing the value-of each name   h^p://cs124.stanford.edu/xml/names.xml   h^p://cs124.stanford.edu/xml/findnames.xsl   h^p://www.ibiblio.org/mefron/xml/xsl/form.html Why would we want to do that? <xsl:stylesheet version="1.0” xmlns:xsl="http://www.w3.org/1999/ XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict">! <xsl:template match="/">! <html> ! <head> ! ! !<title>Expense Report Summary</title> ! </head> ! <body> ! !<p>Total Amount: <xsl:value-of select="expense-report/total"/>! ! !</p> ! !</body>! </html>! </xsl:template>! </xsl:stylesheet>! Traversing the XML document   An XSLT processor reads the input XML   From top to bo^om, star9ng at the root of the document   Using preorder traversal   Applying templates at each step of the traversal   A template matches a given node   Performs a specific transforma9on upon the node   So you can think of an XSL stylesheet as a series of template ­based transforma9ons. XML Documents as Trees letter greeting salutation recipient body close signoff sender Sneak peak: Xpath: XML Documents as Trees letter greeting salutation body recipient close signoff /letter/body! sender Another template example with value-of   Input   <foo>beam</foo>   Two example templates <xsl:template match=“foo”> <bar>baz</bar> <bar>baz</bar> </xsl:template> <xsl:template match=“foo”> <bar><xsl:value ­of select=“.”</xsl:value ­of></bar> <bar>beam</bar> </xsl:template>   Applying a template to a single node   Return the body of the template   All the xsl elements in the body are “interpreted” and replaced by their result   The other elements remain unchanged   The current node (“.”) is set to the input node while evalua9ng Xpath expressions Summary: The anatomy of a stylesheet   An XSLT program is an XML document   The root element of the document is called xsl:stylesheet and is composed of a set of “templates” (i.e., elements called xsl:template)!   The xsl namespace is bound to the “official” XSLT URI (e.g. http://www.w3.org/1999/XSL/Transform)   The XML elements composing the XSLT program: a blend of “user” names and “XSLT” names   The “simple” xsl elements are “interpreted” and replaced by the result of their evalua9on   xsl:for-each, xsl:if, xsl:choose, xsl:value-of! Changing the order of traversal   The xsl:apply ­templates element   Its select a^ribute   Has an XPath expression telling the XSLT processor which nodes to process at that point in the output tree.   Example:   Suppose we want to list names of people   But always last name first   And not print their professions Changing the order of traversal   Example:   Suppose we want to list names of people   But always last name first   And not print their professions or hobbies <xsl:template match="name"> <xsl:value ­of select="last_name"/>, <xsl:value ­of select="first_name"/> </xsl:template>   Why is this not enough?   It prints the professions and hobbies Changing the order of traversal   Example:   Suppose we want to list names of people   But always last name first   And not print their professions or hobbies.   Here’s a person template that means:   When processing a node named person   apply templates to name children only,   but not to any other child elements like profession or hobby <xsl:template match="person"> <xsl:apply ­templates select="name"/> </xsl:template> Applying templates <xsl:apply ­templates select=“name” />   This statement tells the XSLT to look at all child nodes of the current nodes. If any are “name” nodes, then apply the template to them. Apply-templates   h^p://cs124.stanford.edu/xml/names.xml   h^p://cs124.stanford.edu/xml/applyexample.xsl   h^p://www.ibiblio.org/mefron/xml/xsl/form.html Recursive application of templates   The templates are not (normally) invoked by hand   XSLT seman9cs is based on a built ­in, recursive applica9on of templates   Apply ­templates( list of XML nodes)  ­> list of XML nodes   For each input node   Find the template that applies   Apply the template, returns back a sequence of nodes   Concatenate all par9al results, return   The evalua9on of the XSLT main program starts:   by invoking this recursive procedure on the input document node xsl:apply-templates   Re ­enter the built ­in recursive applica9on of templates   Has a select a^ribute that specifies on what set of nodes to apply the procedure (using Xpath)   <xsl:apply ­templates select=“author”/>   <xsl:apply ­templates select=“author/name”/>   <xsl:apply ­templates select=“.//heading”/>   <xsl:apply ­templates select=“ancestors::department/group”/>   <xsl:apply ­templates select=“.”/>   The order of those nodes can be changed using a xsl:sort; default is document order   If no select a^ribute, then implicitly trigger the recursive applica9on of templates on the list of children of the current node More fun with apply-templates   Suppose our goal is to wrap some HTML (9tle, etc) around the whole doc   And put each person in the middle somewhere:   <xsl:template match="people"> <html> <head><9tle>Famous Scien9sts</9tle></head> <body> <xsl:apply ­templates select="person"/> </body> </html> </xsl:template> Final example   h^p://cs124.stanford.edu/xml/names.xml   h^p://cs124.stanford.edu/xml/finalnames.xsl   h^p://www.ibiblio.org/mefron/xml/xsl/form.html Default templates   What happens if there is no template that matches a node?   Default templates.   A^ributes and text nodes: <xsl:template match="text()|@*"> ! <xsl:value-of select="."/>! </xsl:template>!   text() means “any text node”   @* means “any a^ribute node” <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="h^p://www.w3.org/1999/XSL/Transform"> <xsl:template match="people"> <html> <head><9tle>Famous Scien9sts</9tle></head> <body> <dl> <xsl:apply ­templates/> </dl> </body> </html> </xsl:template> <xsl:template match="person"> <dt><xsl:apply ­templates select="name"/></dt> <dd><ul> <li>Born: <xsl:apply ­templates select="@born"/></li> <li>Died: <xsl:apply ­templates select="@died"/></li> </ul></dd> </xsl:template> More Default templates   What happens if there is no template that matches a node?   More default templates..   Elements and document nodes <xsl:template match="*|/"> !<xsl:apply-templates/>! </xsl:template>! !   A^ributes and text nodes <xsl:template match="text()|@*"> !<xsl:value-of select="."/>! </xsl:template>! !   The other nodes <xsl:template match="processing-instruction()| comment()"/>! xsl:value-of   <xsl:value ­of select=“path expression”/>   Evaluates the path expression => nodes   Apply the fn:string(..) func9on to each node   Concatenate the strings   Create (and return) a new text node with this value Another example title: The Elements of Statistical Learning! author: Trevor Hastie, Robert Tibshirani, Jerome Friedman! publisher: Springer! year: 2001! keywords: machine learning, data mining, statistical models! Scenario: we have a simple database of bibliographic information. We have several things we’d like to do with this data: title: Latex: User's Guide andDReference Manual! isplay it in a web browser. Alter our displays: author: Leslie Lamport! -- Order by title publisher: Addison-Wesley! -- Limit output to “new” books year: 1994! keywords: text processing, markup languages, typesetting! title: The Latex Companion! author: Michael Goossens, Frank Mittlebach, Alexander Samarin! publisher: Addison-Wesley! year: 1994! keywords: text processing, markup languages, typesetting! …! Another example <?xml version="1.0"?>! <bibliography>! <book>! <title>The Elements of Statistical Learning</title>! <authList>! <author>Trevor Hastie</author>! <author>Robert Tibshirani</author>! <author>Jerome Friedman</author>! </authList>! <publisher>Springer</publisher>! <year>2001</year>! <kwList>! <keyWord>machine learning</keyWord>! <keyWord>data mining</keyWord>! <keyWord>statistical models</keyWord>! </kwList>! </book>! …! </bibliography>! Another example <?xml version="1.0"?>! Now let’s look at some examples of how <book>! <title>The Elements of we can use XSLT to help organize and Statistical Learning</title>! <authList>! p <author>Trevor Hastie</author>!rovide access to this data. <bibliography>! <author>Robert Tibshirani</author>! <author>Jerome Friedman</author>! </authList>! <publisher>Springer</publisher>! <year>2001</year>! <kwList>! <keyWord>machine learning</keyWord>! <keyWord>data mining</keyWord>! <keyWord>statistical models</keyWord>! </kwList>! </book>! …! </bibliography>! XSL (for-each statement) <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <title>Title List</title> </head> <body bgcolor="white"> <h2>Title List</h2> <hr/> <ol> <xsl:for-each select="bibliography/book"> <li><xsl:value-of select="title"/></li> </xsl:for-each> </ol> </body> </html> </xsl:template> </xsl:stylesheet> XSL (for-each statement) <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <title>Title List</title> </head> <body bgcolor="white"> <h2>Title List</h2> <hr/> <ol> <xsl:for-each select="bibliography/book"> <li><xsl:value-of select="title"/></li> </xsl:for-each> </ol> </body> </html> </xsl:template> </xsl:stylesheet> XSL (sort statement) <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <title>Title List: Ordered Alphabetically</title> </head> <body bgcolor="white"> <h2>Title List</h2> <hr/> <ol> <xsl:for-each select="bibliography/book"> <xsl:sort select="title" /> <li><xsl:value-of select="title"/></li> </xsl:for-each> </ol> </body> </html> </xsl:template> </xsl:stylesheet> XSL (sort statement) <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <title>Title List: Ordered Alphabetically</title> </head> <body bgcolor="white"> <h2>Title List</h2> <hr/> <ol> <xsl:for-each select="bibliography/book"> <xsl:sort select="title" /> <li><xsl:value-of select="title"/></li> </xsl:for-each> </ol> </body> </html> </xsl:template> </xsl:stylesheet> XSL (Xpath selections) <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <title>Title List</title> </head> <body bgcolor="white"> <h2>Title List: Recent Acquisitions</h2> <hr/> <ol> <xsl:for-each select="bibliography/book"> <xsl:if test="year &gt; 2000"> <li><xsl:value-of select="title"/></li> </xsl:if> </xsl:for-each> </ol> </body> </html> </xsl:template> </xsl:stylesheet> xsl:for-each <xsl:for-each select = node-set-expression> <!-- Content: (xsl:sort*, template-body) --> </xsl:for-each>   The node-set expression evaluates to a list of nodes   For each one of them return the template body, evaluated normally   Each application returns a list of nodes, concatenate them all   The input list is processed in document order in case of no sort, otherwise in the sorting specified by the xsl:for-each xsl:for-each example   Data <customers> <customer> <name>...</name> <order>...</order> <order>...</order> </customer> <customer> <name>...</name> <order>...</order> <order>...</order> </customer> </customers> xsl:if   General form <xsl:if test = boolean-expression> <!-- Content: template-body --> </xsl:if>   Example 1: <xsl:template match="namelist/name"> <xsl:apply-templates/> <xsl:if test="not(position()=last())">, </xsl:if> </xsl:template>   Example 2: <xsl:template match="item"> <tr> <xsl:if test="position() mod 2 = 0"> <xsl:attribute name="bgcolor">yellow</xsl:attribute> </xsl:if> <xsl:apply-templates/> </tr> </xsl:template> xsl:choose   General form: <xsl:choose> <!-- Content: (xsl:when+, xsl:otherwise?) --> </xsl:choose> <xsl:when test = boolean-expression> <!-- Content: template-body --> </xsl:when> <xsl:otherwise> <!-- Content: template-body --> </xsl:otherwise> xsl:choose: example <xsl:template match="orderedlist/listitem"> <fo:list-item indent-start='2pi'> <fo:list-item-label> <xsl:variable name="level" select="count(ancestor::orderedlist) mod 3"/> <xsl:choose> <xsl:when test='$level=1'> <xsl:number format="i"/> </xsl:when> <xsl:when test='$level=2'> <xsl:number format="a"/> </xsl:when> <xsl:otherwise> <xsl:number format="1"/> </xsl:otherwise> </xsl:choose> <xsl:text>. </xsl:text> </fo:list-item-label> <fo:list-item-body> <xsl:apply-templates/> </fo:list-item-body> </fo:list-item> </xsl:template> Review: Using XSLT to manage Info XML ??? XSL Processor XSL Review: Using XSLT to manage Info Specific to a particular document XML ??? XSL Processor XSL Review: Using XSLT to manage Info Specific to a particular document XML ??? XSL Processor XSL Specific to a class of documents Review: Using XSLT to manage Info Specific to a particular document XML General across all XML/XSL docs ??? XSL Processor XSL Specific to a class of documents Review: Using XSLT to manage Info XML XSL This model buys us an important system architecture: The logical structure of documents is separated from ??? their visual structure. XSL Processor Moreover, since this abstraction takes place within the agreedupon strictures of XML/XSLT, we only need one processor to process unlimited XML/XSL document pairs. XPath   Regular expression language for specifying nodes in the tree. What is XPath?   A way to select specific nodes in an XML document tree   A tree ­based regular expression language   Used by XSLT to help templates refer to specific nodes or their proper9es in processing XML documents. XML Example <?xml version=“1.0” encoding=“UTF ­8”?> <memo> <header> <to>Mom</to> <from>John Boy</from> <date>2003 ­11 ­12</date> </header> <body gree2ng=“Dear Mom”> <excited>I am having a great 9me!</excited> Hollywood is great, and working on The Waltons is giving me the chance to meet really cool people. I hope everything is great at home. <signature>All my love</signature> </body> </memo> XML as a tree memo header to body date from excited signature XML as a tree memo header to body date from excited signature XML as a tree memo header to body date from excited signature XML as a tree memo header to body date excited from Absolute path: /memo/header/date signature Selecting nodes   Absolute paths to a node begin with a / and contain the full path to the desired node.   /memo/header/date   To select any node of a certain type anywhere in the document use //.   //date   Wildcards can be used:   /memo/*/date XPath Expressions Examples:   /memo   /memo/header   /memo/header/date Given an XML document, the value of a path expression p is a set of elements (= XML subtrees) More specific nodes   You can use a Boolean test to pick certain nodes of a specific type by inser9ng a test into brackets   /memo[./header/date/text()=“2003 ­11 ­12”]   /memo/header/to[./text()=“Mom”]   If an a^ribute or child node is the test, then the node is returned if that a^ribute or child node exists.   /memo/body[excited] Selecting attributes   A^ributes are specified using the @ symbol.   /memo/body/@gree9ng   //@gree9ng   //body[@gree9ng] Path Expressions   XPath expressions /   Simple: /A/P/T A2 A1 N4 V4 B5 P6 T10 T11 V10 V11 P7 T12 V12 PB3 N8 V8   Branching: /A[B]/P/T   Values: /A/P/T[=v11] B9 T13 V13 E14 V14   Result is a set Path Expressions   XPath expressions /   Simple: /A/P/T A2 A1 N4 V4 B5 P6 T10 T11 V10 V11 P7 T12 V12 PB3 N8 V8   Branching: /A[B]/P/T   Values: /A/P/T[=v11] B9 T13 V13 E14 V14   Result is a set Path Expressions   XPath expressions /   Simple: /A/P/T A2 A1 N4 V4 B5 P6 T10 T11 V10 V11 P7 T12 V12 PB3 N8 V8   Branching: /A[B]/P/T   Values: /A/P/T[=v11] B9 T13 V13 E14 V14   Result is a set Path Expressions   XPath expressions /   Simple: /A/P/T A2 A1 N4 V4 B5 P6 T10 T11 V10 V11 P7 T12 V12 PB3 N8 V8   Branching: /A[B]/P/T   Values: /A/P/T[=v11] B9 T13 V13 E14 V14   Result is a set Path Expressions   XPath expressions /   Simple: /A/P/T A2 A1 N4 V4 B5 P6 T10 T11 V10 V11 P7 T12 V12 PB3 N8 V8   Branching: /A[B]/P/T   Values: /A/P/T[=v11] B9 T13 V13 E14 V14   Result is a set XPath Syntax   Path wildcards   // = descendant at any level (or self)   * = any (single) tag   Example: /booklist//lastname   Query a^ributes and a^ribute content   Use “@”   Examples: /booklist//book[@format=“Paperback”], /booklist//book/ @genre   Branching predicates: A[pred]   Predicate on A’s subtree using logical connec>ves (and, or, etc.), path expressions, built ­in func>ons (e.g., contains()), etc.   Example: //author[contains(./lastname, “Fey”)] Xpath: XML Documents as Trees letter greeting salutation recipient body close signoff sender Xpath: XML Documents as Trees letter greeting salutation body recipient close signoff /letter/body! sender Xpath: XML Documents as Trees letter greeting salutation body recipient close signoff /letter/greeting/*! sender Xpath: Context Node 1. print name of root element 2. proceed to first child 3. print name of this element 4. proceed to first child 5. print name of this element letter greeting salutation Context node recipient body 1. letter 2. 3. greeting 4 5. salutation close signoff sender Xpath: Context Node 1. print name of root element 2. proceed to first child 3. print name of this element 4. proceed to first child 5. print name of this element letter greeting salutation Context node recipient body close signoff sender Xpath: Context Node 1. print name of root element 2. proceed to first child 3. print name of this element 4. proceed to first child 5. print name of this element letter greeting salutation Context node recipient body close signoff sender Xpath: Paths from Context Node letter greeting salutation Context node body recipient close signoff xpath location: ./ sender Xpath: Paths from Context Node letter greeting salutation Context node body recipient close signoff xpath location: ../ sender Xpath: Paths from Context Node letter greeting salutation Context node body recipient close signoff sender xpath location: ../recipient! Example for XPath Queries <bib> <book> <publisher> Addison ­Wesley </publisher> <author> Serge Abiteboul </author> <author> <first ­name> Rick </first ­name> <last ­name> Hull </last ­name> </author> <author> Victor Vianu </author> <9tle> Founda9ons of Databases </9tle> <year> 1995 </year> </book> <book price=“55”> <publisher> Freeman </publisher> <author> Jeffrey D. Ullman </author> <9tle> Principles of Database and Knowledge Base Systems </9tle> <year> 1998 </year> </book> </bib> Data Model for XPath The root Processing instruction Comment bib book publisher Addison-Wesley The root element book author .... Serge Abiteboul XPath: Simple Expressions /bib/book/year Result: <year> 1995 </year> <year> 1998 </year> /bib/paper/year Result: empty (there were no papers) XPath: // //author Result:<author> Serge Abiteboul </author> <author> <first ­name> Rick </first ­name> <last ­name> Hull </last ­name> </author> <author> Victor Vianu </author> <author> Jeffrey D. Ullman </author> /bib//first ­name Result: <first ­name> Rick </first ­name> Xpath: Functions /bib/book/author/text() Result: Serge Abiteboul Jeffrey D. Ullman Victor Vianu Rick Hull doesn’t appear because he has firstname, lastname Func9ons in XPath:   text() = matches the text value   node() = matches any node (= * or @* or text())   name() = returns the name of the current tag Xpath: Wildcard //author/* Result: <first ­name> Rick </first ­name> <last ­name> Hull </last ­name> * Matches any element Xpath: Attribute Nodes /bib/book/@price Result: “55” @price means that price is has to be an a^ribute Xpath: Qualifiers /bib/book/author[firstname] Result: <author> <first ­name> Rick </first ­name> <last ­name> Hull </last ­name> </author> Xpath: More Qualifiers /bib/book/author[firstname][address[//zip][city]]/lastname Result: <lastname> … </lastname> <lastname> … </lastname> Xpath: More Qualifiers /bib/book[@price < “60”] /bib/book[author/@age < “25”] /bib/book[author/text()] Xpath: Summary bib matches a bib element * matches any element / matches the root element /bib matches a bib element under root bib/paper matches a paper in bib bib//paper matches a paper in bib, at any depth //paper matches a paper at any depth paper|book matches a paper or a book @price matches a price a^ribute bib/book/@price matches price a^ribute in book, in bib bib/book/[@price<“55”]/author/lastname matches… The Root and the Root   <bib> <paper> 1 </paper> <paper> 2 </paper> </bib>   bib is the “document element”   The “root” is above bib   /bib = returns the document element   / = returns the root   Why ? Because we may have comments before and ayer <bib>; they become siblings of <bib> Xpath: More Details   We can navigate along 13 axes: ancestor ancestor ­or ­self a^ribute We’ve only seen these, so far. child descendant descendant ­or ­self following following ­sibling namespace parent preceding preceding ­sibling self Xpath: More Details   Examples:   child::author/child::lastname = author/lastname   child::author/descendant::zip = author//zip   child::author/parent::* = author/..   child::author/a^ribute::age = author/@age   What does this mean ?   paper/publisher/parent::*/author   /bib//address[ancestor::book]   /bib//author/ancestor::*//zip Xpath: Paths from Context Node letter formal greeting salutation Context node body recipient close signoff sender xpath location: ../attribute::formal! Xpath: Paths from Context Node letter These share (follow) the same parent. greeting salutation Context node body recipient close signoff sender xpath location: ../Following-sibling! Xpath: Paths from Context Node letter These share (follow) the same parent. greeting salutation Context node body recipient close signoff sender xpath location: ../Following-sibling! Xpath: Paths from Context Node letter greeting salutation Context node body recipient close signoff sender xpath location: ../Following-sibling[3]! [same] ../Following-sibling[last()]]! Xpath: Even More Details   name() = the name of the current node   /bib//*[name()=book] same as /bib//book   What does this mean ? /bib//*[ancestor::*[name()!=book]]   h^p://www.zvon.org/xxl/XPathTutorial/General/ examples.html Namespaces   Integra9on of Data from diverse data sources   Integra9on of different XML Vocabularies (aka Namespaces)   Each „vocabulary“ has a unique key, iden9fied by a URI/IRI   Same local name, from different vocabularies can have   Different meaning   Different structure associated with it   Qualified Names (Qname) to a^ach a „name“ to its „vocabulary“   for all nodes in an XML document that has names (A^ributes, Elements, Pis   QName ::= triple ( URI [ prefix: ] localname )   Binding (prefix, URI) is introduced in elements start tag   Later only the prefix is used, not the long URIs   Prefix is op9onal, default namespaces   Prefix and localname a separated by „:“   „h^p://w3.org/TR/1999/REC ­xml ­names“ Example: Namespaces   DQ1 defines dish for china   Diameter, Volume, Decor, ...   DQ2 defines dish for satellites   Diameter, Frequency   How many „dishes“ are there?   Be^er ask for:   „How many dishes are there?“ or   „How many dishes are there?“ Example: Namespaces <gs:dish xmlns:gs = „h^p://china.com“ > <gs:dm gs:unit = „cm“>20</gs:dm> <gs:vol gs:unit = „l“>5</gs:vol> <gs:decor>Meissner</gs:decor> </gs:dish> <sat:dish xmlns:sat = „h^p://satelite.com“ > <sat:dm>200</sat:dm> <sat:freq>20 ­2000MHz</sat:freq> </sat:dish> ...
View Full Document

This document was uploaded on 06/01/2011.

Ask a homework question - tutors are online