Download presentation
Presentation is loading. Please wait.
Published byJob Hancock Modified over 9 years ago
1
Grouping Robin Burke ECT 360
2
Outline Extra credit Numbering, revisited Grouping: Sibling difference method Uniquifying in XPath Grouping: Muenchian method Generated ids Keys Moded Templates Lab
3
Extra credit XSLT assignment convert polls.xml data to SVG due 3/8 no homework that week good prep for SVG part of final project
4
Numbering Issues what is counted? what is the format of the numbering? how are numbers at different places in the tree related?
5
Numbering, cont’d count attribute indicates what is being counted default = count elements of the same name otherwise = specify an XPath pattern all matching elements included Example
6
Formatting format type 1, a, A, i, I other punctuation Example
7
Numbering relationships how does the number of one element depend on other elements? Possibilities only depends on immediate siblings single depends on “parent” multiple depends on “cousins” any
8
Example
9
Grouping Problem we want to impose a new hierarchy “organize books by rating” Requires more tree manipulation Characteristic requirement a list of unique elements the ratings a way to find elements for each value all books with a given rating
10
Two Techniques First easy to understand inefficient Second more complex more likely to be efficient
11
Sibling difference How do I get a list of unique elements? Idea Sort this groups like elements together Grab elements different from their preceding sibling the “start points” of each bucket
12
Example Document book1(3), book2(2), book3(3), book5(2), book6(5) Sort book6(5),book1(3),book3(3),book2(2), book5(1) Select elements different from preceding sibling book6(5), book1(3), book2(2)
13
Implementation Need preceding-sibling axis no abbreviation XPath expression all nodes such that they are not equal to their preceding sibling Example /book-list/book[not(@rating = preceding-sibling::book/@rating)]
14
Example
15
Problem To build unique list must sort then scan whole list To find matching nodes must scan whole list again for each value Not efficient O(n 2 )
16
Muenchian grouping Idea index the elements retrieve from the index Can also be used to filter document contents
17
Muenchian grouping What we need ids keys
18
IDs id unique identifier for each element DTD / schema can define attributes as ID attributes but document writers must encode must ensure uniqueness
19
generate-id XSLT can generate ids for each node guaranteed unique Uses within-page navigation node comparison /entries/entry[5] = /entries/entry[last()] checks string contents, not node identity Example
20
Note Alternate attribute syntax Example Shorthand for #
21
Keys IDs don't allow grouping on content Keys generate an index into document based on XPath expression
22
Example Key element Interpretation Create an index for book elements index by the rating attribute call it "books_by_rating" Key function key ('books_by_rating', 5) Interpretation Return a node set of all of the nodes Indexed in the "books_by_rating" index with value 5
23
Example, cont'd
24
Muenchian grouping Need list of unique values retrieve based on these values The idea create a key index solves step #2 how to get unique values
25
Unique values First node with a given value key('books_by_rating', 5)[1] Can't go through all values must go through all nodes checking for these In other words go through all the books test if the current node is the first one in the index list if so, use it and its associated value otherwise ignore
26
XPath rendering Example /book-list/book[generate-id() = generate-id(key('books_by_rating', @rating)[1])] How to read this for all book nodes b grab the first indexed book node b 1 with the same rating filter b = b 1
27
Alternate logic A node set is a set if x = y then { x, y } = { x } = { y } Example /book-list/book[ count(. | key('books_by_rating', @rating)[1]) = 1] How to read this for all book nodes b create a node set consisting of b and b 1 the first indexed book node with the same rating filter set size = 1
28
Example id method count method
29
Building a page index Index labels at the top of the page one for each unique key Sections in the page one for each unique key Links from labels to sections label section name
30
Example
31
More complex example Index First letter of author's first names Need substring function substring(author-list/author[1], 1, 1) Use variables for complex XPath expressions
32
Moded templates We process the same nodes twice using for-each Can we process the same nodes twice with apply-templates? Problem template match criterion in both cases the same
33
Moded templates cont'd Solution additional attribute: mode specified in apply-templates call and in template definition only the template of the appropriate mode will be used
34
Example
35
Lab
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.