[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Processing 2 files and using one with key() lookup

Subject: Re: 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
Re:  Processing 2 files and using one with key() lookup
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.