xsl-list
[Top] [All Lists]

Re: [xsl] Techniques for Sorting and Reducing Maps in XSLT 3/XPath 3?

2018-07-06 11:28:21
On Thu, 2018-07-05 at 20:51 +0000, Eliot Kimber ekimber(_at_)contrext(_dot_)com
wrote:
[...]

maps seem like an obvious way to do this:

1. Use Saxon's collection() function with the metadata=yes option to
get a set of maps, one for each file, that includes the full path to
the file (this avoids loading a bunch of files I don't actually want
and gives me maps as a starting point).

2. Using these maps, add the version, locale, and 3rd-level directory
name as separate entries in each map, creating a more complete set of
"descriptor" maps that make it easy to access to relevant fields I
care about.

3. Create a new map where the keys are 3rd directory name ("course
ID") and the values are the descriptor maps a given course id/locale
pair with the highest version.

My question: How best to implement step 3?

If you keep the values as tree nodes, you shuld be able to use base-
uri() and/or document-uri() to get at the filename.

On your xsl:iterate question, i'd generally try for-each and/or for-
each-group before xsl:iterate. The reason is largely that i think it
encourage thinking in terms of a functional mapping rather than an
imperative loop, and that can help clarity of thought.

What is the better way to do this kind of "find the map entries that
meet a specific requirement relative to other members of the map"
processing?

Well, this sounds like an XQuery question of course, where you want to
process a tuple stream with a where clause. But in XSLT it also sounds
like a sort of Visitor pattern where you'd pass in an isWanted function
to a recursive tree walk; the tree walk would know about your map
structure enough to visit every node you cared about, and would use
isWanted() to return only the appropriate nodes. (there are some
performance optimizations you can do with this architecture too of
course, e.g. letting isWanted also say, "all done, stop looking now")

Don't know if this helps. 

Liam

-- 
Liam Quin,  http://www.fromoldbooks.org/

Available for XML/Document/Information Architecture/
XSLT/XQuery/Web/Text Processing work and consulting.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>