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

Re: Matching on keys

Subject: Re: Matching on keys
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 6 Jan 2017 20:16:46 -0000
Re:  Matching on keys
On Fri, Jan 06, 2017 at 05:56:02PM -0000, Wendell Piez wapiez@xxxxxxxxxxxxxxx scripsit:
> Question: I can define a key, as in
> 
> <xsl:key name="elements-by-class" match="*[matches(@class,'\S')]"
> use="tokenize(@class,'\s+')"/>
> 
> then
> 
> <xsl:template match="key('elements-by-class','foo')">
>  ...
> </xsl:template>
> 
> I regard this as a neat trick, and think it might be an "improvement"
> :-) but I suppose from one point of view at least, that may be
> arguable.
> 
> What do readers think? Should I prefer a stylesheet function instead?

I've been doing something similar (@xmi:id and @xmi:idref rather than
@class) and finding that creating global variables with maps in them
that relate the key value to a node in the source document works very
well even with Saxon 9.6 which presumably doesn't have all the
optimizations for 3.0.  One can

<xsl:apply-templates select="$map($key)" />

even when there's a sequence of element nodes being mapped by that key
and (if I understand xsl:map correctly) away it goes to the node of the
source document via indirection rather than a copy.

There'd probably be a structural difference to the "can we match all of
these by template?" approach which might not be useful for what you want
to do; I find most of the logic wanders into the map-building steps in
the variables.

It does mean you have to use 3.0 but I'm inclined to claim that's a
feature. :)

-- Graydon

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.