Download presentation
Presentation is loading. Please wait.
Published byCecil Tyler Modified over 9 years ago
1
CIS 375—Web App Dev II XPath
2
2 XPath IntroductionIntroduction What is XPath? XPath is a syntax for defining parts of an _____ document XPath uses paths to define XML elements XPath defines a library of standard __________ XPath is a major element in XSLT XPath is not written in XML XPath is a W3C ____________ Without XPath knowledge you will not be able to create XSLT documents. XPath was released as a W3C _______________, November 16, 1999, as a language for addressing parts of an XML document. XML functions Standard Recommendation
3
3 XPath Example Empire Burlesque Bob Dylan 10.90 … Given the XML code above, the XPath expression /catalog/cd[price>10.80] selects all CD’s with price greater than $10.80. /catalog/cd/title selects all title elements. These “elements” are also called ________. nodes
4
4 XPath SyntaxSyntax The following code makes the corresponding selection //cd …all CD elements /catalog/cd/* … all child elements of the CD element //* … all elements in the document /catalog/cd[1] … the first CD child element /catalog/cd[last()] … the last CD child element /catalog/cd[price] … all CD elements with a price /catalog/cd[price=10.90]/price … all price elements with a price of $10.90 /catalog/cd/title | /catalog/cd/artist … all title and artist elements //cd[@country='UK'] … all CD’s where country=‘UK’
5
5 XPath Location PathsLocation Paths An absolute location path starts with a slash ( / ) and a relative location path does not. The syntax for a location step is: axisname::nodetest[predicate] Examples of selection child::cd … all CD elements that are children of the current node ( child: can be omitted from a location step) cd[position()=1] … first CD child of the current node cd[@type="classic"] is short for child::cd[attribute::type="classic"]../@src … the src attribute of the parent of the current node
6
6 XPath Expressions / FunctionsExpressions Functions XPath supports expressions. Numerical: +, -, x, div, _____ Equality: =, != Relational:, >= Boolean: or, and XPath contains a function library for converting data. Node set functions: count(), last(), name(), position() String functions: concat(), string(), substring() Number functions: ceiling(), round(), sum() Boolean functions: boolean(), false(), true() mod
7
7 XPath ExamplesExamples Selecting nodes: http://www.w3schools.com/xpath/tryit.asp?filename =try_xpath_select_cdnodes http://www.w3schools.com/xpath/tryit.asp?filename =try_xpath_select_cdnodes Selecting nodes using criteria: http://www.w3schools.com/xpath/tryit.asp?filename =try_xpath_select_pricenodes_high http://www.w3schools.com/xpath/tryit.asp?filename =try_xpath_select_pricenodes_high
8
8 A Final XPath Example <xsl:stylesheet version="1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform"> My CD Collection <xsl:apply-templates select="title | artist | price“ /> Title: Artist: 10% discount price:
9
9 Output From Final Example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.