+ All Categories
Home > Documents > XPath XQuery XSLT

XPath XQuery XSLT

Date post: 12-Sep-2021
Category:
Upload: others
View: 19 times
Download: 0 times
Share this document with a friend
72
Query Languages for XML XPath XPath XQuery XSLT 1
Transcript
Page 1: XPath XQuery XSLT

Query Languages for XML

XPathXPathXQueryXSLT

1

Page 2: XPath XQuery XSLT

The XPath/XQuery Data Model

Corresponding to the fundamental “relation” of the relational model is: sequence of items.qAn item is either:

1 A i iti l i t t i1. A primitive value, e.g., integer or string.2. A node (defined next).

2

Page 3: XPath XQuery XSLT

Principal Kinds of Nodes

1. Document nodes represent entire d tdocuments.

2. Elements are pieces of a document pconsisting of some opening tag, its matching closing tag (if any), and g g g ( y),everything in between.

3 Attributes names that are given3. Attributes names that are given values inside opening tags.

3

Page 4: XPath XQuery XSLT

Document Nodes

Formed by doc(URL) or document(URL).Example: doc(/usr/class/cs145/bars.xml)All XPath (and XQuery) queries refer to aAll XPath (and XQuery) queries refer to a doc node, either explicitly or implicitly.

Example: key definitions in XML Schema have Xpath expressions that refer to the document described by the schema.

4

Page 5: XPath XQuery XSLT

DTD for Running Example

<!DOCTYPE BARS [<!ELEMENT BARS (BAR* LEMONADE*)><!ELEMENT BARS (BAR*, LEMONADE*)><!ELEMENT BAR (PRICE+)>

<!ATTLIST BAR name ID #REQUIRED><!ATTLIST BAR name ID #REQUIRED><!ELEMENT PRICE (#PCDATA)>

!ATTLIST PRICE IDREF #REQUIRED<!ATTLIST PRICE theLemonade IDREF #REQUIRED><!ELEMENT LEMONADE EMPTY>

!ATTLIST LEMONADE ID #REQUIRED<!ATTLIST LEMONADE name ID #REQUIRED><!ATTLIST LEMONADE soldBy IDREFS #IMPLIED>

]5

]>

Page 6: XPath XQuery XSLT

Example Document

<BARS>An element node

<BAR name = ”JoesBar”><PRICE theLemonade = ”Bud”>2.50</PRICE>/<PRICE heLemonade = ”Miller”>3.00</PRICE>

</BAR></BAR> …<LEMONADE name = ”Bud” soldBy = ”JoesBar

SuesBar … ”/> …</BARS>

An attribute node

6

/Document node is all of this, plusthe header ( <? xml version… ).

Page 7: XPath XQuery XSLT

Nodes as Semistructured DataNodes as Semistructured Databars.xml

BARS

LEMONADEBAR name =”JoesBar”

SoldBy= ”…”

name =”Bud”

PRICEPRICE theLemonade =theLemonade PRICEPRICE ”Miller”= ”Bud”

3 002 50

Rose =documentGreen = elementGold = attribute3.002.50 Gold = attributePurple = primitive

value7

value

Page 8: XPath XQuery XSLT

Paths in XML Documents

XPath is a language for describing paths in XML documents.The result of the described path is aThe result of the described path is a sequence of items.

8

Page 9: XPath XQuery XSLT

Path Expressions

Simple path expressions are sequences of slashes (/) and tags, starting with /.

Example: /BARS/BAR/PRICEExample: /BARS/BAR/PRICE

Construct the result by starting with just the doc node and processing eachjust the doc node and processing each tag from the left.

9

Page 10: XPath XQuery XSLT

Evaluating a Path Expression

Assume the first tag is the root.Processing the doc node by this tag results in a sequence consisting of only the root q g yelement.

Suppose we have a sequence of itemsSuppose we have a sequence of items, and the next tag is X.

F h it th t i l t dFor each item that is an element node, replace the element by the subelements

ith t X10

with tag X.

Page 11: XPath XQuery XSLT

Example: /BARS

<BARS><BAR name = ”JoesBar”><PRICE theLemonade = ”Bud”>2.50</PRICE>/<PRICE theLemonade = ”Miller”>3.00</PRICE>

</BAR></BAR> …<LEMONADE name = ”Bud” soldBy = ”JoesBar

SuesBar … ”/> …</BARS>

O it th11

/One item, theBARS element

Page 12: XPath XQuery XSLT

Example: /BARS/BAR

<BARS><BAR name = ”JoesBar”>

<PRICE theLemonade =”Bud”>2.50</PRICE>/<PRICE the Lemonade = ”Miller”>3.00</PRICE>

</BAR></BAR> …<LEMONADE name = ”Bud” soldBy = ”JoesBar

SuesBar …”/> …</BARS> This BAR element followed by

12

/all the other BAR elements

Page 13: XPath XQuery XSLT

Example: /BARS/BAR/PRICE

<BARS><BAR name = ”JoesBar”><PRICE theLemonade =”Bud”>2.50</PRICE>/<PRICE theLemonade = ”Miller”>3.00</PRICE>

</BAR></BAR> …<LEMONADE name = ”Bud” soldBy = ”JoesBar

SuesBar …”/> …</BARS>

These PRICE elements followedby the PRICE elements

13

/ by the PRICE elementsof all the other bars.

Page 14: XPath XQuery XSLT

Attributes in Paths

Instead of going to subelements with a given tag, you can go to an attribute of the elements you already have.y yAn attribute is indicated by putting @ in front of its namefront of its name.

14

Page 15: XPath XQuery XSLT

Example: /BARS/BAR/PRICE/@ theLemonade

<BARS><BAR name = ”JoesBar”>

<PRICE theLemonade = ”Bud”>2.50</PRICE>/<PRICE theLemonade = ”Miller”>3.00</PRICE>

</BAR></BAR> …<LEMONADE name = ”Bud” soldBy = ”JoesBar

SuesBar …”/> …</BARS>

These attributes contribute”Bud” ”Miller” to the result,f ll d b th th L d

15

/followed by other theLemonadevalues.

Page 16: XPath XQuery XSLT

Remember: Item Sequences

Until now, all item sequences have been sequences of elements.When a path expression ends in anWhen a path expression ends in an attribute, the result is typically a sequence of values of primitive typesequence of values of primitive type, such as strings in the previous example.

16

Page 17: XPath XQuery XSLT

Paths that Begin Anywhere

If the path starts from the document node and begins with //X, then the first step can begin at the root or any p g ysubelement of the root, as long as the tag is Xtag is X.

17

Page 18: XPath XQuery XSLT

Example: //PRICE

<BARS><BAR name = ”JoesBar”>

<PRICE theLemonade =”Bud”>2.50</PRICE>/<PRICE theLemonade= ”Miller”>3.00</PRICE>

</BAR></BAR> …<LEMONADE name = ”Bud” soldBy = ”JoesBar

SuesBar …”/> …</BARS>

These PRICE elements andany other PRICE elements

18

/ any other PRICE elementsin the entire document

Page 19: XPath XQuery XSLT

Wild-Card *

A star (*) in place of a tag represents any one tag.Example: /*/*/PRICE represents allExample: / / /PRICE represents all price objects at the third level of nestingnesting.

19

Page 20: XPath XQuery XSLT

Example: /BARS/*Example: /BARS/*This BAR element, all other BARelements, the LEMONADE element, allother LEMONADE elements<BARS>

<BAR name = ”JoesBar”>

other LEMONADE elements

<PRICE theLemonade = ”Bud”>2.50</PRICE><PRICE theLemonade = ”Miller”>3 00</PRICE><PRICE theLemonade = Miller >3.00</PRICE>

</BAR> …LEMONADE ”B d” ldB ”J B<LEMONADE name = ”Bud” soldBy = ”JoesBar

SuesBar … ”/> …20</BARS>

Page 21: XPath XQuery XSLT

Selection Conditions

A condition inside […] may follow a tag.If so, then only paths that have that tag and also satisfy the condition aretag and also satisfy the condition are included in the result of a path expressionexpression.

21

Page 22: XPath XQuery XSLT

Example: Selection Condition

/BARS/BAR/PRICE[. < 2.75]The current

<BARS><BAR name = ”JoesBar”>

The currentelement.

<BAR name JoesBar ><PRICE theLemonade = ”Bud”>2.50</PRICE><PRICE th L d ”Mill ”>3 00</PRICE><PRICE theLemonade = ”Miller”>3.00</PRICE>

</BAR> …The condition that the PRICE beThe condition that the PRICE be< $2.75 makes this price but notthe Miller price part of the result.

22

p p

Page 23: XPath XQuery XSLT

Example: Attribute in Selection

/BARS/BAR/PRICE[@ theLemonade = ”Miller”]<BARS>

<BAR name = ”JoesBar”><BAR name JoesBar ><PRICE theLemonade = ”Bud”>2.50</PRICE><PRICE th L d ”Mill ”>3 00</PRICE><PRICE theLemonade = ”Miller”>3.00</PRICE>

</BAR> …Now this PRICE elementNow, this PRICE elementis selected, along withany other prices for Miller.

23

any other prices for Miller.

Page 24: XPath XQuery XSLT

XQuery

XQuery extends XPath to a query language that has power similar to SQL.Uses the same sequence-of-items dataUses the same sequence of items data model.XQ i i lXQuery is an expression language.

Like relational algebra --- any XQuery g y Q yexpression can be an argument of any other XQuery expression.

24

Q y p

Page 25: XPath XQuery XSLT

More About Item Sequences

XQuery will sometimes form sequences of sequences.All sequences are flattenedAll sequences are flattened.Example: (1 2 () (3 4)) = (1 2 3 4).

Emptysequence

25

Page 26: XPath XQuery XSLT

FLWR Expressions

1. One or more for and/or let clauses.2. Then an optional where clause.3 A return clause3. A return clause.

26

Page 27: XPath XQuery XSLT

Semantics of FLWR Expressions

Each for creates a loop.let produces only a local definition.

At each iteration of the nested loops ifAt each iteration of the nested loops, if any, evaluate the where clause.If the where clause returns TRUE, invoke the return clause, and append its , ppvalue to the output.

27

Page 28: XPath XQuery XSLT

FOR Clauses

for <variable> in <expression>, . . .Variables begin with $.A for variable takes on each item in theA for-variable takes on each item in the sequence denoted by the expression, in turn.Whatever follows this for is executedWhatever follows this for is executed once for each value of the variable.

28

Page 29: XPath XQuery XSLT

Example: FOR “Expand the en-closed string byreplacing variables

Our exampleBARS document

for $lemonade in d t(”b l”)/BARS/LEMONADE/@

p gand path exps. bytheir values.”

document(”bars.xml”)/BARS/LEMONADE/@namereturn<LEMONADENAME> {$lemonade} </LEMONADENAME>

$lemonade ranges over the name attributes of all$lemonade ranges over the name attributes of all lemonades in our example document.Result is a sequence of LEMONADENAME elements:Result is a sequence of LEMONADENAME elements:

< LEMONADENAME> Bud </LEMONADENAME >

29< LEMONADENAME> Miller </LEMONADENAME > . . .

Page 30: XPath XQuery XSLT

Use of Braces

When a variable name like $x, or an expression, could be text, we need to surround it by braces to avoid having it y ginterpreted literally.

Example: <A>$x</A> is an A elementExample: <A>$x</A> is an A-element with value ”$x”, just like <A>foo</A> is an A-element with ”foo” as valuean A-element with foo as value.

30

Page 31: XPath XQuery XSLT

Use of Braces --- (2)

But return $x is unambiguous.You cannot return an untagged string without quoting it, as return ”$x”.without quoting it, as return $x .

31

Page 32: XPath XQuery XSLT

LET Clauses

let <variable> := <expression>, . . .Value of the variable becomes the sequence of items defined by thesequence of items defined by the expression.N l d i i fNote let does not cause iteration; fordoes.

32

Page 33: XPath XQuery XSLT

Example: LET

let $d := document(”bars.xml”)let $lemonades := $d/BARS/LEMONADE/@namereturnreturn<LEMONADENAMES>{$lemonades}</ LEMONADENAMES>

Returns one element with all the names of the lemonades, like:,

< LEMONADENAMES>Bud Miller …</ LEMONADENAMES>

33

Page 34: XPath XQuery XSLT

Order-By ClausesOrder-By Clauses

FLWR is really FLWOR: an order-by clause can precede the return.can precede the return.Form: order by <expression>

With optional ascending or descending.

The expression is evaluated for eachThe expression is evaluated for each assignment to variables.Dete mines placement in o tp t seq enceDetermines placement in output sequence.

34

Page 35: XPath XQuery XSLT

Example: Order-By

List all prices for Bud, lowest first.let $d := document(”bars.xml”)for $p infor $p in

$d/BARS/BAR/PRICE[@theLemonade=”Bud”]order by $preturn $p

Generates bindingsfor $p to PRICE

Order those bindingsby the values insidereturn $p elements.the elements (auto-matic coersion).Each binding is evaluated

for the output The35

for the output. Theresult is a sequence ofPRICE elements.

Page 36: XPath XQuery XSLT

Aside: SQL ORDER BY

SQL works the same way; it’s the result of the FROM and WHERE that get ordered, not the output., pExample: Using R(a,b),

b

Then, the b-valuesare extracted from theseSELECT b FROM R

WHERE b > 10

are extracted from thesetuples and printed in thesame order.

ORDER BY a;R tuples with b>10

36

pare ordered by theira-values.

Page 37: XPath XQuery XSLT

PredicatesPredicates

Normally, conditions imply existential quantification.quantification.Example: /BARS/BAR[@name] means “all th b th t h ”the bars that have a name.”Example: /BARS/LEMONADE[@soldAt = p / / [@”JoesBar”] gives the set of lemonades that are sold at Joe’s Barthat are sold at Joe s Bar.

37

Page 38: XPath XQuery XSLT

Example: Comparisons

Let us produce the PRICE elements (from all bars) for all the lemonades that are sold by Joe’s Bar.yThe output will be BLP elements with the names of the bar and lemonade asthe names of the bar and lemonade as attributes and the price element as a subelement.

38

Page 39: XPath XQuery XSLT

Strategy

1. Create a triple for-loop, with variables ranging over all LEMONADE elements, all BAR elements, and all PRICE ,elements within those BAR elements.

2 Check that the lemonade is sold at2. Check that the lemonade is sold at Joe’s Bar and that the name of the lemonade and theLemonade in the PRICE element match.

393. Construct the output element.

Page 40: XPath XQuery XSLT

The Query

let $bars = doc(”bars.xml”)/BARSfor $lemonade in $bars/LEMONADEfor $bar in $bars/BAR

True if ”JoesBar”appears anywhere

for $price in $bar/PRICEwhere $lemonade/@soldAt = ”JoesBar” and

appears anywherein the sequence

where $lemonade/@soldAt = JoesBar and $price/@theLemonade = $lemonade/@namet <BLP b {$b /@ } l dreturn <BLP bar = {$bar/@name} lemonade = {$lemonade/@name}>{$price}</BLP>

40

Page 41: XPath XQuery XSLT

Strict Comparisons

To require that the things being compared are sequences of only one element, use the Fortran comparison , poperators:

eq ne lt le gt geeq, ne, lt, le, gt, ge.

Example: $lemonade/@soldAt eq ”JoesBar” is true only if Joe’s is the only bar selling the lemonade.

41

g

Page 42: XPath XQuery XSLT

Comparison of Elements and Values

When an element is compared to a primitive value, the element is treated as its value, if that value is atomic.,Example: /BARS/BAR[@name=”JoesBar”]//BARS/BAR[@name= JoesBar ]/PRICE[@theLemonade=”Bud”] eq ”2.50”

is true if Joe charges $2.50 for Bud.

42

Page 43: XPath XQuery XSLT

Comparison of Two Elements

It is insufficient that two elements look alike.Example:/BARS/BAR[@name=”JoesBar”]/PRICE[@theLemonade=”Bud”] eq /BARS/BAR[@name=”SuesBar”]//BARS/BAR[@name SuesBar ]/PRICE[@the Lemonade =”Bud”]

i f l if J d S h this false, even if Joe and Sue charge the same for Bud.

43

Page 44: XPath XQuery XSLT

Comparison of Elements – (2)

For elements to be equal, they must be the same, physically, in the implied document.Subtlety: elements are really pointers to sections of particular documents notto sections of particular documents, not the text strings appearing in the section.

44

Page 45: XPath XQuery XSLT

Getting Data From Elements

Suppose we want to compare the values of elements, rather than their location in documents.To extract just the value (e.g., the price itself) from an element E use data(E )itself) from an element E, use data(E ).

45

Page 46: XPath XQuery XSLT

Example: data()

Suppose we want to modify the return for “find the prices of lemonades at bars that sell a lemonade Joe sells” to produce pan empty BLP element with price as one of its attributesof its attributes.return <BLP bar = {$bar/@name}

$ /lemonade = {$lemonade/@name} price = {data($price)} />

46

Page 47: XPath XQuery XSLT

Eliminating Duplicates

Use function distinct-valuesapplied to a sequence.Subtlety: this function strips tags awaySubtlety: this function strips tags away from elements and compares the string valuesvalues.

But it doesn’t restore the tags in the result.

47

Page 48: XPath XQuery XSLT

Example: All the Distinct Prices

return distinct-values(let $bars = doc(”bars.xml”)return $bars/BARS/BAR/PRICEreturn $bars/BARS/BAR/PRICE

)Remember: XQuery isan expression language.p g gA query can appear anyplace a value can.

48

Page 49: XPath XQuery XSLT

Effective Boolean Values

The effective boolean value (EBV) of an expression is:

1. The actual value if the expression is of1. The actual value if the expression is of type boolean.

2 FALSE if the expression evaluates to 0 ””2. FALSE if the expression evaluates to 0, [the empty string], or () [the empty sequence]sequence].

3. TRUE otherwise.

49

Page 50: XPath XQuery XSLT

EBV Examples

1. @name=”JoesBar” has EBV TRUE or FALSE, depending on whether the name attribute is ”JoesBar”.

2. /BARS/BAR[@name=”GoldenRail”] has EBV TRUE if some bar is named theEBV TRUE if some bar is named the Golden Rail, and FALSE if there is no such bar.

50

Page 51: XPath XQuery XSLT

B l O tBoolean Operators

E1 and E2, E1 or E2, not(E ), apply to any expressions.any expressions.Take EBV’s of the expressions first.Example: not(3 eq 5 or 0) has value TRUE.Also: true() and false() are functions that return values TRUE and FALSEthat return values TRUE and FALSE.

51

Page 52: XPath XQuery XSLT

Branching Expressions

if (E1) then E2 else E3 is evaluated by:Compute the EBV of E1.If true, the result is E2; else the result is E3.If true, the result is E2; else the result is E3.

Example: the PRICE subelements of $b id d th t b i J ’$bar, provided that bar is Joe’s.

if($bar/@name eq ”JoesBar”)qthen $bar/PRICE else ()

52Empty sequence. Note thereis no if-then expression.

Page 53: XPath XQuery XSLT

Quantifier Expressions

some $x in E1 satisfies E2

1. Evaluate the sequence E1.2. Let $x (any variable) be each item in2. Let $x (any variable) be each item in

the sequence, and evaluate E2.3 Return TRUE if E has EBV TRUE for at3. Return TRUE if E2 has EBV TRUE for at

least one $x.A l lAnalogously:

every $x in E1 satisfies E253

y $ 1 2

Page 54: XPath XQuery XSLT

Example: Some

The bars that sell at least one lemonadefor less than $2.

for $bar infor $bar indoc(”bars.xml”)/BARS/BAR

where some $p in $bar/PRICEsatisfies $p < 2 00satisfies $p < 2.00

return $bar/@name

54Notice: where $bar/PRICE < 2.00would work as well.

Page 55: XPath XQuery XSLT

Example: Every

The bars that sell no lemonade for more than $5.

for $bar infor $bar indoc(”bars.xml”)/BARS/BAR

where every $p in $bar/PRICEsatisfies $p <= 5 00satisfies $p < 5.00

return $bar/@name

55

Page 56: XPath XQuery XSLT

Document Order

Comparison by document order: << and >>.Example:Example: $d/BARS/LEMONADE[@name=”Bud”] << $d/BARS/ LEMONADE[@name ”Miller”] is$d/BARS/ LEMONADE[@name= Miller ] is true iff the Bud element appears before

$the Miller element in the document $d.

56

Page 57: XPath XQuery XSLT

Set Operators

union, intersect, except operate on sequences of nodes.

Meanings analogous to SQL.Meanings analogous to SQL.Result eliminates duplicates.Result appears in document orderResult appears in document order.

57

Page 58: XPath XQuery XSLT

XSLT

XSLT (extensible stylesheet language –transforms ) is another language to process XML documents.pOriginally intended as a presentation language: transform XML into an HTMLlanguage: transform XML into an HTML page that could be displayed.It can also transform XML -> XML, thus serving as a query language.

58

serving as a query language.

Page 59: XPath XQuery XSLT

XSLT Programs

Like XML Schema, an XSLT program is itself an XML document.XSLT has a special namespace of tagsXSLT has a special namespace of tags, usually indicated by xsl:.

59

Page 60: XPath XQuery XSLT

Templates

The xsl:template element describes a set of elements (of the document being processed) and what should be done with p )them.The form: <xsl:template match path >The form: <xsl:template match = path > … </xsl:template>

Attribute match gives anXPath expression describingh t fi d th d t hi h

60how to find the nodes to whichthe template applies.

Page 61: XPath XQuery XSLT

Example: BARS Document -> Table

In a running example, we’ll convert the bars.xml document into an HTML document that looks like the Sells(bar, ( ,lemonade, price) relation.The first template will match the root ofThe first template will match the root of the document and produce the table without any rows.

61

Page 62: XPath XQuery XSLT

The Template for the RootTemplate

<xsl:template match = ”/”>

pmatchesonly the

t<TABLE><TR><TH>bar</th><TH>lemonade</th>

root.

<TH>bar</th><TH>lemonade</th><TH>price</th></tr>

</table></xsl:template></xsl:template>

Output of the template isa table with the attributesNeeds to be fixed. As is,

th i t i t62

in the header row, noother rows.

there is no way to insertrows.

Page 63: XPath XQuery XSLT

Outline of Strategy

1. Inside the HTML for the table is xsl:apply-templates to extract data from the document.

2. From each BAR, use an xsl:variable b to remember the bar nameremember the bar name.

3. xsl:for-each PRICE subelement, generate ga row, using b, and xsl:value-of to extract the lemonade name and price.

63

the lemonade name and price.

Page 64: XPath XQuery XSLT

Recursive Use of Templates

An XSLT document usually contains many templates.Start by finding the first one that appliesStart by finding the first one that applies to the root.A l h i hi iAny template can have within it <xsl:apply-templates/>, which causes the pp y ptemplate-matching to apply recursively from the current node.

64

from the current node.

Page 65: XPath XQuery XSLT

Apply-Templates

Attribute select gives an XPath expression describing the subelements to which we apply templates.pp y pExample: <xsl:apply-templates select = ”BARS/BAR” /> says to follow all pathsBARS/BAR /> says to follow all paths tagged BARS, BAR from the current node and apply all templates there.

65

Page 66: XPath XQuery XSLT

Example: Apply-Templates

<xsl:template match = ”/”><TABLE><TR>

<TH>bar</th><TH>lemonade</th><TH>bar</th><TH>lemonade</th><TH>price</th></tr>

<xsl:apply-templates select = ”BARS” />BARS />

</table>

66</xsl:template>

Page 67: XPath XQuery XSLT

Extracting Values

<xsl:value-of select = XPath expression /> produces a value to be placed in the output.pExample: suppose we are applying a template at a BAR element and want totemplate at a BAR element and want to put the bar name into a table.

<xsl:value-of select = ”@name” />

67

Page 68: XPath XQuery XSLT

Variables

We can declare x to be a variable with l i bl ” ” /<xsl:variable name = ”x” />.

Example:<xsl:variable name = ”bar”><xsl:value-of select = ”@name” /><xsl:value of select @name />

</xsl:variable>

ithi t l t th t li t BAR l twithin a template that applies to BAR elements will set variable bar to the name of that bar.

68

Page 69: XPath XQuery XSLT

Using Variables

Put a $ in front of the variable name.Example: <TD>$bar</td>

69

Page 70: XPath XQuery XSLT

Completing the Table

1. We’ll apply a template at each BAR element.

2 This template will assign a variable b2. This template will assign a variable bthe value of the bar, and iterate over each PRICE childeach PRICE child.

3. For each PRICE child, we print a row, pusing l, the theLemonade attribute, and the PRICE itself.

70

and the PRICE itself.

Page 71: XPath XQuery XSLT

Iteration

<xsl:for-each select = Xpath expression> …

</xsl:for-each></xsl:for each>executes the body of the for-each at each hild f h d h i h dchild of the current node that is reached

by the path.y p

71

Page 72: XPath XQuery XSLT

The Template for BARSA variablefor each The Template for BARS<xsl:template match = ”BAR”> Constructs a bar-

bar

<xsl:template match = BAR ><xsl:variable name = ”b”>

<xsl:value-of select = ”@name” />

lemonade-price row.

<xsl:value of select @name /></xsl:variable><xsl:for-each select = ”PRICE”>

<TR><TD>$l</td><TD><xsl:value-of select = ”@theLemonade” />

</td><TD><xsl:value-of select = ”data(.)” />

</td></tr></xsl:for-each>

Iterates over allThisl t

72</xsl:template> Iterates over all

PRICE subelementsof the bar.

element


Recommended