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
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format