Subject: Re: [xsl] Processing 2 files and using one with key() lookups? From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 28 Oct 2015 15:07:47 -0000 |
Hi, Actually even the name of a key called can be dynamic -- for example, a variable reference -- as long as it resolves to a string that happens to be the (namespaced) name of a key. So key($mykey,$myval) will work as long as $mykey yields a string that happens to be the name of a key declared in my stylesheet. Naturally this isn't very common, since one generally doesn't wish the key itself (which works essentially like a function, retrieving nodes according to a logic declared in the key) to depend on factors at runtime. But it can be useful. (I think I've even done this, maybe once.) What is much more useful in the ordinary case is to vary the second argument to key($name,$val). It will commonly depend on processing content and it's sometimes helpful to pass it in as a parameter. Where things get even trickier is that the key will retrieve nodes from a given subtree, which can be identified in XSLT 2.0 with a third argument, so key($name,$val,$source) -- where $source does not have to be a subtree containing the node $val (when $val is a node at all) -- or the subtree containing the context node -- but any document at all, whether called or constructed. This can be really useful, indeed essential in many cases. Since key() doesn't have that third argument in XSLT 1.0, one must jump through hoops to use keys to get nodes from documents other than the one containing the context node. In XSLT 1.0 the source of the key retrieval is the document containing the context node (again, not any node $val), which is why we change context (typically using xsl:for-each) in order to get what we want. Keys are also good exercise for the brain, and working key problems may, if practiced regularly, stave off certain kinds of dementia. (Or it may cause certain others.) Cheers, Wendell On Tue, Oct 27, 2015 at 7:51 PM, David Carlisle d.p.carlisle@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > >> Any suggestions on how to call the <xsl:key> with a variable? Still can't >> make that work > > ? Sorry can't guess what you mean by that. > > The name attribute has to be fixed, the match attribute is a pattern like a > template match and can use variables in the same way, and the use attribute > is an Xpath expression so can use variables. > > David > > XSL-List info and archive > EasyUnsubscribe (by email) -- Wendell Piez | http://www.wendellpiez.com XML | XSLT | electronic publishing Eat Your Vegetables _____oo_________o_o___ooooo____ooooooo_^
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Processing 2 files and us, David Carlisle d.p.c | Thread | Re: [xsl] Processing 2 files and us, Michael Kay mike@xxx |
Re: [xsl] Processing 2 files and us, David Carlisle d.p.c | Date | [xsl] a sequence of regex-group(), Geert Bormans geert@ |
Month |