62
1 Before The Class What’re the roles of us in this subject? –A researcher –A developer –A problem solver IT related technologies What’s really confused you? XML: a markup language to model specific data from a specific domain The architecture of XML application The process of utilising related technologies (XML- based) as a problem solver

1 Before The Class What’re the roles of us in this subject? –A researcher –A developer –A problem solver –IT related technologies What’s really confused

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

1

Before The Class

• What’re the roles of us in this subject?

– A researcher

– A developer

– A problem solver

– IT related technologies

• What’s really confused you?

– XML: a markup language to model specific data from a specific domain

– The architecture of XML application

– The process of utilising related technologies (XML-based) as a problem solver

2

XML Path Language (XPath)

Address the nodes of XML doc. trees

3

• Introduction

• Nodes

• Location Paths

– Axes & Node Tests

– Using Axes and Node Tests

• Syntax and Expression

• Operations and Data Types

• Examples

• Functions

• Summary

4

Introduction – Why XPath?

• During the development of eXtensible StyleSheet Language Transformation (XSLT), another member of the XML family, known as XPointer was defined.

– XPointer takes the idea of anchor tags to a new level.

• Both XPointer and XSLT needed a way to point to various parts of a document.

• XSLT needs it to select the part of a document that would be transformed

• XPointer for linking two documents.

– The solution was to provide a common syntax and semantics that both XSLT and XPointer could use.

5

Introduction – Why XPath? (cont.)

• Besides, XML provides a rich, flexible and efficient way to mark up data,

– but XML does not provide a way to locate specific part of nodes within a given document.

• XML processing steps vs. XPath

– An XML doc. would need to be parsed and then searched through element by element to reach specific parts (DOM, SAX)

• Trouble: for large document, inefficient and error prone

– XPath: providing expression syntax for other XML technologies to locate specific parts

• Effectively and efficiently

• This new subset was called XPath

6

Introduction

• What is XPath?

– The XML Path Language (XPath) is a set of syntax and semantics for referring to portions of XML documents

– A language for finding information in an XML document

• XPath is a string-based (expression) instead of structure-based language (XML)

– A syntax for defining parts of an XML document

– Uses path expressions to navigate elements and attributes (nodes) in XML documents

– XPath contains a library of standard functions (for accessing the nodes)

– Intended to be used by other specifications such as XSL, XSL Transformations (XSLT) and the XML Pointer Language (XPointer) and others.

7

Introduction (cont.)

• The XPath specification is the foundation for a variety of specifications,

– Including XSLT and linking/addressing specifications like XPointer.

• An understanding of XPath is fundamental to a lot of advancing XML technology usages.

• XPath core: Path Expressions

– XPath uses path expressions to select nodes or node-sets in an XML document.

– These path expressions look very much like the expressions you see when you work with a traditional computer file system. (XPath uses a notation with forward slashes (/) similar the UNIX shell )

– The basic idea is to recall: a tree is much like the structures of files and folders on a hard drive

8

Introduction (cont.)• XPath Standard Functions

– XPath includes over 100 built-in functions (refer to W3C XPath document)

– There are functions for:

• string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values, and more

• XPath is Used in XSLT

– A major element in the XSLT standard.

– XSLT uses XPath extensively for matching -- testing whether a node matches a given pattern.

– XSLT specifies the context used by XPath.

– You should understand XPath if you want to work with XSLT

– Without XPath knowledge you will not be able to create XSLT documents (different documents).

9

Introduction (cont.)

• XPath is a W3C Standard

– XPath became a W3C Recommendation 16. November 1999.

– XPath was designed to be used by XSLT, XPointer and other XML parsing software

• XPath vs. XSLT, XPoint, XQuery, …

XML

document

XPath

XSLTXPointXQuery

…………

Variabledocuments

the locations of document

structures or data

process the information

finding the information

using XPath

Generate

10

XPath Version

• XPath 2.0

– XPath 2.0 is a superset of XPath 1.0 and currently a W3C Working Draft.

– Two W3C working groups are working on version 2.0 of XPath: the XML Query Working Group and the XSL Working Group.

– XPath 2.0 has more power and is more robust because it supports a broader set of data types.

– XPath 2.0 values use XML Schema types rather than simple strings, numbers, or booleans.

– XPath 2.0 is backward-compatible so that 1.0 expressions behave the same in 2.0, with exceptions listed in the specification.

11

XPath Nodes – use to model a document tree

• An XML document– Are treated as trees of nodes (Tree structure with nodes)

– Each node represents part of an XML document

• Seven types of node

– Root

– Element

– Attribute

– Text

– Comment

– Processing instruction

– Namespace

• Attributes and namespaces are not children of their parent node

– They describe their parent nodes

12

XPath Nodes

• An XPath tree has a single root node

<?xml version = “1.0”?>

• Each XPath tree node has a string representation

– Called a string-value, only text() nodes, not attribute and namespace nodes

– Example: <book> Web Programming II </book>

– ? Example II: <book> <title> Web </title> Text Book </book>

• Document order: Nodes in an XPath tree have an ordering

– Determined by the order appeared in the original XML doc.

• Expanded-name of certain nodes (refers to Fig 11.5)

– Local part: tag name

– Namespace URI: prefix

13

Fig. 11.5 XPath node types

Node Type string-value expanded-name Description

root

Determined by concatenating the string-values of all text-node descendents in document order.

None. Represents the root of an XML document. This node exists only at the top of the tree and may contain element, comment or processor-instruction children.

element

Determined by concatenating the string-values of all text-node descendents in document order.

The element tag, including the namespace prefix (if applicable).

Represents an XML element and may contain element, text, comment or processor-instruction children.

attribute

The normalized value of the attribute.

The name of the attribute, including the namespace prefix (if applicable).

Represents an attribute of an element.

14

Fig. 11.5 XPath node types. (Part 2)

Node Type string-value expanded-name Description

text

The character data contained in the text node.

None. Represents the character data content of an element.

comment

The content of the comment (not including <!-- and -->).

None. Represents an XML comment.

processing instruction

The part of the processing instruction that follows the target and any whitespace.

The target of the processing instruction.

Represents an XML processing instruction.

namespace The URI of the namespace. The namespace

prefix. Represents an XML namespace.

15

XPath Nodes (cont.)

<?xml version="1.0" encoding="ISO-8859-1"?><bookstore>

<book> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price></book>

</bookstore>

Example of nodes in the XML document above:

<bookstore> (element node)<author>J K. Rowling</author> (element node)lang="en" (attribute node)

16An Example of Presenting an XML Doc. In

XPath<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="AuctionItemSummary-Base.xsl"?><list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://MyXPathExample.com AuctionItemList.xsd">

<item type="BidOnly" private="false" id="itemId0001"><bidIncrement>1</bidIncrement><currentPrice currency="USD">5</currentPrice><endOfAuction>56</endOfAuction><description>Miles Smiles album, CD</description><sellerId>miles1965</sellerId>

</item><item type="FixedPrice" private="true" id="itemId0302">

<bidIncrement>0</bidIncrement><currentPrice currency="GBP">70</currentPrice><endOfAuction>2</endOfAuction><description>New 256m MP3 player</description><sellerId>jimmy</sellerId>

</item>………………………………

</list>

17

XPath's view of an XML doc.

Outline18

Root node

Comment nodes

Element nodes

Attribute nodes

Text nodes

1 <?xml version = "1.0"?>

2

3 <!-- Fig. 11.1 : simple.xml -->

4 <!-- Simple XML document -->

5

6 <book title = "C++ How to Program" edition = "3">

7

8 <sample>

9 <![CDATA[

10

11 // C++ comment

12 if ( this->getX() < 5 && value[ 0 ] != 3 )

13 cerr << this->displayError();

14 ]]>

15 </sample>

16

17 C++ How to Program by Deitel &amp; Deitel

18 </book>

Comment nodes

Root node

Element nodes

Attribute nodes

Text nodes

Fig. 11.1 Simple XML document.

19

Fig. 11.2 XPath tree for Fig. 11.1.

AttributeTitle

C++ How to Program

Elementbook

CommentFig. 11.1 : simple.xml

CommentSimple XML document

Attributeedition 3

Root

TextC++ How to Program by Deitel & Deitel

Elementsample Text

// C++ comment if (this -> getX() < 5 && value[ 0 ] != 3 )

cerr << this->displayError();

Outline20

Fig. 11.3XML document with processing-instruction and namespace nodes.

Root node

Comment nodes

Namespace nodes

Processing instruction node

Element nodes

Text nodes

Attribute nodes

1 <?xml version = "1.0"?>

2

3 <!-- Fig. 11.3 : simple2.xml -->

4 <!-- Processing instructions and namespacess -->

5

6 <html xmlns = "http://www.w3.org/TR/REC-html40">

7

8 <head>

9 <title>Processing Instruction and Namespace Nodes</title>

10 </head>

11

12 <?deitelprocessor example = "fig11_03.xml"?>

13

14 <body>

15

16 <deitel:book deitel:edition = "1"

17 xmlns:deitel = "http://www.deitel.com/xmlhtp1">

18 <deitel:title>XML How to Program</deitel:title>

19 </deitel:book>

20

21 </body>

22

23 </html>

Comment nodes

Root node

Element nodes

Namespace nodes

Text nodes

Processing instruction node

Attribute nodes

21

Continued on next slide...

Fig. 11.4 Tree diagram of an XML documentwith a processing-instruction node

Root

CommentFig. 11.3 : simple2.xml

CommentProcessing instructions and namespaces

Elementhtml

Namespacehttp://www.w3.org/TR/REC-html40

Elementhead

TextProcessing instructions and Namespcae Nodes

Elementtitle

22

Fig. 11.4 Tree diagram of an XML document with a processing-instruction node. (Part 2)

Continued from previous slide

Processing Instructiondeitelprocessor

example = "fig11_03.xml"

Elementbody

Elementbook

Attributeedition

1

Namespacehttp://www.deitel.com/xmlhtp1

Elementtitle

TextXML How to Program

23

Location Paths

• What we already know?

– The structure of an XML document in XPath

• How can we use the structure to locate particular parts of a document? (Location path)

– Just like we use to locate a specific file or folder in a file system?

– The most useful and widely used feature of XPath

– An expression specifying how to navigate XPath tree

24

Location Paths (cont.)

• A location path is composed of location steps

• Each location step composed of– Each location step has the following form:

axis-name :: node-test [predicate]*

– Axis: specifies the tree relationship between the nodes selected by the location step and the context node

– Node test: specifies the node type and expanded-name of the nodes selected by the location step

– Predicate: use arbitrary expressions to further refine the set of nodes selected by the location step

25

Location Paths (cont.)

• The location path sets the context of the node that you're trying to find.

• The context is set using the location path of the root (match="/").

• To code a location path, you can use an abbreviated or non-abbreviated syntax.

• “abbreviated” is the most widely used; the unabbreviated syntax is also more

complex

• You might need to check which one your parser supports.

• An example of the non-abbreviated syntax is shown below. (From the May 2000 release, the MSXML parser supports both.)

– child::para selects the para element children of the context node

26

Location Paths (cont.)

• Two kinds of location path: relative location paths and absolute location paths

• A relative location path is a sequence of location steps separated by /. For example:

list/item[ currentPrice < 20.0 ]

– This location path consists of two location steps:

• the first, list, selects a set of nodes relative to the context node;

• the second, item[currentPrice < 20.0], selects a set of nodes in the subset identified by the first step;

• and so on, if there are more nodes.

27

Location Paths (cont.)

• An absolute location path consists of a /, optionally followed by a relative location path,

• with / referring to the root node.

• An absolute location path is basically a relative location path evaluated in the context of the root node, for example:

/list/item[ currentPrice < 20.0 ]

– With absolute location paths (location paths that start with /), the context node isn't meaningful because the path is always evaluated from the root node

28

Axes

• XPath searches are made relative to context node

• The context for a query is the node in the source XML document currently being processed

– Context node: reference node where you start to locate specific parts in a document

– Examp1: xsl:template match="/", we are in the context of the root of the XML document

– Examp2: xsl:for-each loop, the context is whichever node we are currently looping through

• Axis

– Indicates which nodes, relative to context node, are included in search

– Dictates node ordering in set

– Forward axes select nodes that follow context node

– Reverse axes select nodes that precede context node

29Fig. 11.6 XPath axes.Summaries the 13 XPath Axes and their ordering and provides a description

Axis Name Ordering Description

self none The context node itself.

parent reverse The context node’s parent, if one exists.

child forward The context node’s children, if they exist.

ancestor reverse The context node’s ancestors, if they exist.

ancestor-or-self reverse The context node’s ancestors and also itself.

descendant forward The context node’s descendants.

descendant-or-self forward The context node’s descendants and also itself.

following forward The nodes in the XML document following the context node, not including descendants.

following-sibling forward The sibling nodes following the context node.

preceding reverse The nodes in the XML document preceding the context node, not including ancestors.

preceding-sibling reverse The sibling nodes preceding the context node.

attribute forward The attribute nodes of the context node.

namespace forward The namespace nodes of the context node.

30

Node Tests

• Node tests

– A set of nodes selected by axis is refined with node tests

– Rely upon axis’ principle node type

• For attribute axes, the principle node type is attribute

• For namespace axes, the principle node type is namespace

• All other axes, the principle node type is element

– Corresponds to type of node axis can select

31

Fig. 11.7 Some XPath node tests.

Node Test Description

* Selects all nodes of the same principal node type.

node() Selects all nodes, regardless of their type.

text() Selects all text nodes.

comment() Selects all comment nodes.

processing-instruction() Selects all processing-instruction nodes.

node name Selects all nodes with the specified node name.

32

Location Paths Using Axes and Node Tests

• Location step– Axis and node test separated by double colon (::)

– Optional predicate enclosed in square brackets ([])

– Some examples:• Select all element-node children of context nodechild::*

• Select all text-node children of context nodechild::text()

• Select all text-node grandchildren of context nodechild::*/child::text()

33

Fig. 11.8 Some location-path abbreviations.

Location Path Description

child:: This location path is used by default if no axis is supplied and may therefore be omitted.

attribute:: The attribute axis may be abbreviated as @.

/descendant-or-self::node()/ This location path is abbreviated as two slashes (//).

self::node() The context node is abbreviated with a period (.).

parent::node() The context node’s parent is abbreviated with two periods (..).

Outline34

Fig. 11.9XML document that marks up book translations.

1 <?xml version = "1.0"?>

2

3 <!-- Fig. 11.9 : books.xml -->

4 <!-- XML book list -->

5

6 <books>

7

8 <book>

9 <title>Java How to Program</title>

10 <translation edition = "1">Spanish</translation>

11 <translation edition = "1">Chinese</translation>

12 <translation edition = "1">Japanese</translation>

13 <translation edition = "2">French</translation>

14 <translation edition = "2">Japanese</translation>

15 </book>

16

17 <book>

18 <title>C++ How to Program</title>

19 <translation edition = "1">Korean</translation>

20 <translation edition = "2">French</translation>

21 <translation edition = "2">Spanish</translation>

22 <translation edition = "3">Italian</translation>

23 <translation edition = "3">Japanese</translation>

24 </book>

25

26 </books>

35

Output for Fig. 11.9

36

Fig. 11.10 XPath tree for books.xml

Othernodes…

Continued on next slide…

Elementbook

TextJava How to Program

Elementtitle

Attributeedition 1

Elementtranslation

TextSpanish

Attributeedition 1

Elementtranslation

TextChinese

37

Fig. 11.10 XPath tree for books.xml

Continued from previous slide…

Othernodes…

Attributeedition 2

Elementtranslation

TextFrench

Elementtranslation

Attributeedition 2

TextJapanese

Elementtranslation

Attributeedition 1

TextJapanese

38

Location Paths Using Axes and Node Tests (cont.)

• Which books have Japanese translations?

– Use root node of XPath tree as context node

– Use predicate

• Boolean expression for filtering nodes from search

• Compare string value of current node to string ‘Japanese’

/books/book/translation[. = ‘Japanese’]/../title

39

XPath Syntax

• XPath uses path expressions to select nodes or node-sets in an XML document.

• The node is selected by following a path or steps

• The XML Example Document

<?xml version="1.0" encoding="ISO-8859-1"?><bookstore>

<book> <title lang="eng">Harry Potter</title> <price>29.99</price>

</book><book>

<title lang="eng">Learning XML</title> <price>39.95</price>

</book></bookstore>

40

XPath Syntax (cont.)

• Selecting Nodes– XPath uses path expressions to select nodes in an XML document.

– The node is selected by following a path or steps.

– The most useful path expressions are listed below

Expression Description

element Selects all child nodes of the node

/ Selects from the root node

//Selects nodes in the document from the current node that matches the selection no matter where they are

. Selects the current node

.. Selects the parent of the current node

@ Selects attributes

41

XPath Syntax (cont.)• Examples

– In the table below we have listed some path expressions and the result of the expressions

Path Expression Result

bookstore Selects all the child nodes of the bookstore element

/bookstoreSelects the root element bookstore Note: If the path starts with a slash ( / ) it always represents an absolute path to an element!

bookstore/bookSelects all book elements that are children of bookstore

//bookSelects all book elements no matter where they are in the document

bookstore//bookSelects all book elements that are descendant of the bookstore element, no matter where they are under the bookstore element

//@lang Selects all attributes that is named lang

42

XPath Syntax (cont.)• Predicates

– Predicates are used to find a specific node or a node that contains a specific value.

– Predicates are always embedded in square brackets [ ]

• Examples– In the table below we have listed some path expressions with predicates and

the result of the expressions

Path Expression Result

/bookstore/book[1] Selects the first book element that is the child of the bookstore element

/bookstore/book[last()] Selects the last book element that is the child of the bookstore element

//title[@lang] Selects all the title elements that have an attribute named lang

//title[@lang='eng'] Selects all the title elements that have an attribute named lang with a value of 'eng'

/bookstore/book[price>35.00]

Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00

/bookstore/book[price>35.00]/title

Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00

43

XPath Syntax (cont.)

Selecting Unknown Nodes

XPath wildcards can be used to select unknown XML elements.

Wildcard Description

* Matches any element node

@* Matches any attribute node

node() Matches any node of any kind

44

XPath Syntax (cont.)

Examples

In the table below we have listed some path expressions and the result of the expressions:

Path Expression Result

/bookstore/*Selects all the child nodes of the bookstore element

//* Selects all elements in the document

//title[@*] Selects all title elements which have any attribute

45

XPath Syntax (cont.)Selecting Several Paths

By using the | operator in an XPath expression you can select several paths.

Examples

In the table below we have listed some path expressions and the result of the expressions:

Path Expression Result

//book/title | //book/priceSelects all the title AND price elements of all book elements

//title | //priceSelects all the title AND price elements in the document

/bookstore/book/title | //price

Selects all the title elements of the book element of the bookstore element AND all the price elements in the document

46

Predicates

• Predicates are used in location paths to filter the current set of nodes.

• A predicate contains a boolean expression (or an expression that can be easily converted to boolean)

• Each member of the current node-set is tested against the boolean expression and kept if the expression is true; otherwise, it is rejected.

• A predicate is enclosed in square brackets, [ ].

47

Predicates (cont.)

• Have a look at the following location path:

List / item / currentPrice [ @currency = "EUR“ ]

– During evaluation, all currentPrice elements in the XML doc. are in the selected node-set.

– Then, the @currency="EUR" predicate is evaluated and the currentPrice elements whose currencies do not contain the EUR value are rejected.

• Predicates can also use the relational operators >, <, >=, <=, and !=. They can also use Boolean operators,

48

XPath Operator

• XPath expressions returns either a node-set, a string, a Boolean, or a number

• A list of the operators that can be used in XPath expressions

Oper. Description Example Return value

| Computes two node-sets

//book | //cd Returns a node-set with all book and cd elements

+ Addition 6 + 4 10

- Subtraction 6 - 4 2

* Multiplication 6 * 4 24

div Division 8 div 4 2

= Equal price=9.80 true if price is 9.80false if price is 9.90

!= Not equal price!=9.80 true if price is 9.90false if price is 9.80

49

XPath Operator (cont.)

< Less than price<9.80 true if price is 9.00false if price is 9.80

<= Less than or equal to

price<=9.80 true if price is 9.00false if price is 9.90

> Greater than price>9.80 true if price is 9.90false if price is 9.80

>= Greater than or equal to

price>=9.80 true if price is 9.90false if price is 9.70

or or price=9.80 or price=9.70

true if price is 9.80false if price is 9.50

and and price>9.00 and price<9.90

true if price is 9.80false if price is 8.50

mod Modulus (division remainder)

5 mod 2 1

50

51XPath Example

• Learn some basic XPath syntax by looking at some examples

"books.xml":

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore><book category="COOKING">

<title lang="en">Everyday Italian</title>

<author>Giada De Laurentiis</author>

<year>2005</year>

<price>30.00</price>

</book>

<book category="CHILDREN">

<title lang="en">Harry Potter</title>

<author>J K. Rowling</author>

<year>2005</year>

<price>29.99</price>

</book>

<book category="WEB">

<title lang="en">XQuery Kick Start</title>

<author>James McGovern</author>

<author>Per Bothner</author>

<author>Kurt Cagle</author>

<author>James Linn</author>

<author>Vaidyanathan Nagarajan</author>

<year>2003</year>

<price>49.99</price>

</book>

……………………………………………………………………………

</bookstore>

52

XPath Example (cont.)applied XPath expression in XML DOM object

1. Selecting NodesUse the Microsoft XMLDOM object to load the XML document and the selectNodes() function to select nodes from the XML document:

set xmlDoc=CreateObject("Microsoft.XMLDOM")

xmlDoc.async="false"

xmlDoc.load("books.xml")

xmlobject.selectNodes(path expression)

53

XPath Example (cont.)

1. Select all book NodesThe following example selects all the book nodes under the bookstore element:

xmlDoc.selectNodes("/bookstore/book")

2. Select the First book NodeThe following example selects only the first book node under the bookstore element:

xmlDoc.selectNodes("/bookstore/book[0]")

Note: IE 5 and 6 has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]

54

XPath Example (cont.)

3. Select the pricesThe following example selects the text from all the price nodes:

xmlDoc.selectNodes("/bookstore/book/price/text()")

4. Selecting price Nodes with Price>35The following example selects all the price nodes with a price higher than 35:

xmlDoc.selectNodes("/bookstore/book[price>35]/price")

5. Selecting title Nodes with Price>35The following example selects all the title nodes with a price higher than 35:

xmlDoc.selectNodes("/bookstore/book[price>35]/title")

55

Node-set Operators and Functions

• Node-set operators– Manipulate node sets to form others

• Node-set functions– Perform actions on node-sets returned by location paths

56

Fig. 11.11 Node-set operators.

Node-set Operators Description

pipe (|)

Performs the union of two node-sets.

slash (/) Separates location steps.

double-slash (//) Abbreviation for the location path /descendant-or-self::node()/

57

Fig. 11.12 Some node-set functions.

Node-set Functions Description

last() Returns the index of last items in the processed node list

Example: //book[last()] Result: Selects the last book element

position() Returns the position number of the current node in the node-set being tested.

count( node-set ) Returns the number of nodes in node-set.

id( string ) Returns the element node whose ID attribute matches the value specified by argument string.

local-name( node-set ) Returns the local part of the expanded-name for the first node in node-set.

namespace-uri( node-set ) Returns the namespace URI of the expanded-name for the first node in node-set.

name( node-set ) Returns the qualified name for the first node in node-set.

http://www.w3.org/TR/xpath-functions

58

Node-set Operators and Functions (cont.)

• Location-path expressions

• Combine node-set operators and functions

• Select all head and body children element nodes

head | body

• Select last title element node in head element node

head/title[ last() ]

• Select third book element

book[ position() = 3 ]– Or alternatively

book[ 3 ]

• Return total number of element-node children

count( * )

• Select all book element nodes in document

//book

Outline59

Fig. 11.13 List of companies with stock symbols.

1 <?xml version = "1.0"?>23 <!-- Fig. 11.13 : stocks.xml -->4 <!-- Stock list -->56 <stocks>78 <stock symbol = "INTC">9 <name>Intel Corporation</name>10 </stock>1112 <stock symbol = "CSCO">13 <name>Cisco Systems, Inc.</name>14 </stock>1516 <stock symbol = "DELL">17 <name>Dell Computer Corporation</name>18 </stock>1920 <stock symbol = "MSFT">21 <name>Microsoft Corporation</name>22 </stock>2324 <stock symbol = "SUNW">25 <name>Sun Microsystems, Inc.</name>26 </stock>2728 <stock symbol = "CMGI">29 <name>CMGI, Inc.</name>30 </stock>3132 </stocks>

Outline60

Fig. 11.14Demonstrating some String functions.

XPath string functions

1 <?xml version = "1.0"?>23 <!-- Fig. 11.14 : stocks.xsl -->4 <!-- string function usage -->56 <xsl:stylesheet version = "1.0"7 xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">89 <xsl:template match = "/stocks">10 <html>11 <body>12 <ul>1314 <xsl:for-each select = "stock">1516 <xsl:if test = 17 "starts-with(@symbol, 'C')">1819 <li>20 <xsl:value-of select = 21 "concat(@symbol,' - ', name)"/>22 </li>23 </xsl:if>2425 </xsl:for-each>26 </ul>27 </body>28 </html>29 </xsl:template>30 </xsl:stylesheet>

XPath string functions

Outline61

Output for Fig. 11.14

62

That’s it for today!

• HomeWork # 3– Text book P. 316, – Exercises 11.3 & 11.4