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

when to use keys?

Subject: when to use keys?
From: Matthew Hixson <mhixson@xxxxxxxxxxxx>
Date: Wed, 11 Oct 2000 18:17:19 -0700
menu xml jsp
The burning question today at work is whether or not we should use keys in our
current project.  The problem is this.  We need to contruct an HTML navigation
menu based upon a user's credentials.  A JSP custom tag is using a Java class
to determine what credentials this user has, and returns those results as
XML.  So we have:

<menu-key>welcome.jsp</menu-key>
<menu-key>doSomething_1.jsp</menu-key>
<menu-key>doSomething_2.jsp</menu-key>
<menu-key>doSomething_3.jsp</menu-key>

This is available underneath the <root> node of this document, which means that
we know how to access it directly using XPath.  By "directly" I mean that we
don't need to do any time wasting XPath expressions like //menu-key.
  We also include a XML file with content like so:

<menu-item href="welcome.jsp">Home</menu-item>
<menu-item href="doSomething_1.jsp">Page 1</menu-item>
<menu-item href="doSomething_2.jsp">Page 2</menu-item>
<menu-item href="doSomething_3.jsp">Page 3</menu-item>
<menu-item href="doSomething_4.jsp">Page 4</menu-item>

The <menu-key>'s are the items which should be shown (according to our custom
tag) and the <menu-item>'s are all of the items which could be displayed if the
user had all of the necessary credentials (according to our static file,
menu.xml).
  So now the problem (which we have already solved) is to construct the menu in
HTML with the corresponding hyperlinks and menu text.
  Since we know exactly where both of these sets of data exist in the XML tree
is there any point in using keys?  We know where the <menu-key>'s are:
/root/menu-key, and we know where the <menu-item>'s are:
document('menu.xml')/menu-item.
  Can anyone see a benefit to using keys in this situation or would you
accomplish it by doing something like:

<xsl:for-each select="/root/menu-key">
 <xsl:variable name="current-item" select="."/>
  <a href="{.}"><xsl:value-of
select="document('menu.xml')/menu-item[@href=$current-item]"/></a>
</xsl:for-each>

Are keys primarily useful when you don't know where the data exists in the XML
tree, but you need quick and/or repetitive access to it?  Would there be any
large performance increase in using keys in this situation where we are
iterating through the list of <menu-key>'s?
  Thanks for your time,
   -M@

-- 
Matt Hixson
Aventail Corporation
Seattle, Washington


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


Current Thread
  • when to use keys?
    • Matthew Hixson - Wed, 11 Oct 2000 18:17:19 -0700 <=
      • <Possible follow-ups>
      • Kay Michael - Fri, 13 Oct 2000 10:03:53 +0100

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.