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

Re: efficient use of key element and function

Subject: Re: efficient use of key element and function
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Wed, 7 Sep 2005 09:51:20 +0100
element of function
On 9/6/05, Manfred Staudinger <manfred.staudinger@xxxxxxxxx> wrote:
> Hi all,
> Given a rather long list of unique names I want to know for a
> certain name if it is on that list. The stylesheet below does
> this, but is this the best (most efficient) solution? In the most
> common case around 95% of the names will be found.
> - is the key element correct (I have no use for @use)?
> - should I sort the names?
>
> In the real stylesheet the names represent files and are used
> to avoid a file-not-found for doc(). They are retrieved by means
> of collection().
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <xsl:stylesheet version="2.0"
>             xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:key name="find" match="*" use="."/>
> <xsl:template match="/">
> <xsl:variable name="Index-alt">
>     <doc>
>         <name>
>             <xsl:text>schmid_hans</xsl:text>
>         </name>
>         <name>
>             <xsl:text>prunauer_katharina</xsl:text>
>         </name>
>         <name>
>             <xsl:text>senkenwald_wolfgang</xsl:text>
>         </name>
>     </doc>
> </xsl:variable>
> <xsl:value-of select="empty(key('find', 'prunauer_regina', $Index-alt))"/>
> <xsl:value-of select="empty(key('find', 'strada_jacopo', $Index-alt))"/>
> </xsl:template>
> </xsl:stylesheet>

Not sure about your key definition:

* matches all elements
. gets all the descedant text nodes and concatenates them together

so

<name>schmid_hans</name>

and

<doc><name>schmid_</name><name>hans</name></doc>

when keyed with 'schmid_hans' would both return an element, but is
probably not want you want.

If might be better to match on text() than on *

cheers
andrew

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.