Re: XSLT 2.0 Idea: third argument for key()
In brief: I'd like to suggest having a third argument for key(), a node set, such that the key only retrieves nodes with the relevant key value that are within this node set.
When the node set is subset based entirely on hierarchy, I do this today using generate-id() based on the premise that generate-id() produces a name token (that never includes a space).
Here's an example of the second area in which this would be useful, restricting nodes to a known node set: say I had a document with a massive dataset like:
What I would do in this case is:
... <!ENTITY lookup-athletes "concat( generate-id(parent::country), ' ', @event )> ... <xsl:key name="athletes" match="athlete" use="&lookup-athletes;"/> ... key('athletes', &lookup-athletes;) ...
Any thoughts? Objections? Implementation issues?
Below are fragments from the solution to one of the exercises in my two-day hands-on course where students are required to group hockey team statistics based on the number of games played within either their division or their conference (two separate tables).
The Muenchian Method of grouping uses *all* members of the source node tree which isn't *directly* applicable since the grouping has to be subset by the hierarchy. What I do is calculate the key table value to include the generated id of the ancestral point in the source node tree. The space delimiter ensures no possible ambiguity in the concatenated value (provided all values are calculated the same way ... which I do using a general entity to ensure I don't screw up my typing).
<!DOCTYPE xsl:stylesheet [
<!--use entities to keep typing down and promote consistency-->
"concat( generate-id(ancestor::division), ' ', g)">
"concat( generate-id(ancestor::conference), ' ', g)">
<xsl:key name="games-division" match="team"
use="&lookup-games-division;"/> <!--games played within division-->
<xsl:key name="games-conference" match="team"
use="&lookup-games-conference;"/><!--games played within conference-->
<h3><xsl:value-of select="name"/> Division</h3>
<h2><xsl:value-of select="name"/> Conference</h2>
The above works quite smoothly and is the basis of how I teach students to group subsets of the source node tree (after teaching the Muenchian Method of grouping all found members in the source node tree).
I hope this helps.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format