|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT 2.0 Idea: third argument for key()
At 00/09/04 19:56 +0100, Jeni Tennison wrote:
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--> <!ENTITY lookup-games-division "concat( generate-id(ancestor::division), ' ', g)"> <!ENTITY lookup-games-conference "concat( generate-id(ancestor::conference), ' ', g)"> ]> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <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--> ... <xsl:for-each select="division"> <h3><xsl:value-of select="name"/> Division</h3> <xsl:for-each select=".//team [generate-id(.)=generate-id(key('games-division', &lookup-games-division;)[1])]"> ... <xsl:for-each select="key('games-division',&lookup-games-division;)"> ... <h2><xsl:value-of select="name"/> Conference</h2> <xsl:for-each select=".//team [generate-id(.)=generate-id(key('games-conference', &lookup-games-conference;)[1] &lookup-games-conference;)[1])]"> ... <xsl:for-each select="key('games-conference',&lookup-games-conference;)"> ... 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. .................... Ken
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
|

Cart








