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

Re: xsl:key

Subject: Re: xsl:key
From: Michael French <mfrench@xxxxxxxxxxxxx>
Date: Wed, 3 May 2000 17:10:50 -0500
michael french
Michael French asks:
>Is there any way to key nodes from an external document() ?

David Marston wrote:
> I think the example given at the end of section 12.2 of the
> XSLT spec does what you want. This example is known to work
> with Xalan.

Scott Boag wrote:
> If you want to find key in another source tree, you have 
> to call the key() function inside a for-each which selects 
> a node using the document() function

I can now see how this would work, but the problem I have
(I think), is scalability and computational complexity. 

For example, I prefer:

   .. select="id('foo')" 

to:

   .. select="//*[@id = 'foo']" 

because I assume id() is a hashtable lookup,
and //*[@id='foo'] is probably a loop over elements.

So I want to prefer:

  <xsl:key match="document('bar.xml')//bar" ...  >
  ...
  ..  select="key(...)"
  
over a solitary:

  .. select="document('bar.xml')//bar[..]"

because I assume the xsl:key is a hashtable (?).
Perhaps the extra generality of xsl:key mean it cannot
be a hashtable, and must always be a map or dynamic 
expression re-writer.

Maybe it's always dangerous to assume some underlying 
data structure and consequent performance characteristics 
without benchmarking a particular implementation !!?
But it is natural for developers to form some 
mental picture of the plausible implementations, 
and use that model to make decisions about the 
possible (in)efficiency of their stylesheets.

Looking at the XSLT spec end-of-12.2 example
(slightly modified to make name an attribute 
 for both <entry> and <bibref> elements):

What's the point of doing:

  <xsl:key name="bib" match="entry" use="@name"/>

  <xsl:template match="bibref">
    <xsl:variable name="name" select="@name"/>
    <xsl:for-each select="document('bib.xml')">
      <xsl:apply-templates select="key('bib',$name)"/>
    </xsl:for-each>
  </xsl:template>

rather than say:

  <xsl:template match="bibref">
    <xsl:variable name="name" select="@name"/>
    <xsl:apply-templates 
     select="document('bib.xml')//entry[@name = $name]"/>
  </xsl:template>

if the xsl:key is not a static hashtable ?

What I want to do is build a table and look up entries:

  <xsl:key name="bib" select="document('bib.xml')//entry" use="@name"/>
                      ^^^^^^
  <xsl:template match="bibref">
    <xsl:apply-templates select="key('bib',@name)"/>
  </xsl:template> 

Mike




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.