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

Re: A problem using the xsl:key facility

Subject: Re: A problem using the xsl:key facility
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Tue, 20 Jul 2010 21:30:53 +0100
Re:  A problem using the xsl:key facility
On 20/07/2010 21:17, Nathan Potter wrote:

The key() function, when called with two arguments, always searches within the current document (more accurately, the document containing the context node). Your xsl:for-each changes the current document, so you are searching the wrong thing. In XSLT 2.0 you can use the third argument of the key() function to indicate which document you want to search.

I've included some other comments on your code in case you find them helpful.


<xsl:choose> <xsl:when test="boolean(dataset)">
Calling boolean() is redundant here: the test attribute does it anyway.
<xsl:element name="NestedDataset">
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
That's a rather longwinded way of doing

<NestedDataSet name="{@name}"><xsl:apply-templates/></NestedDataSet>

<xsl:variable name="sName"><xsl:value-of select="."/></xsl:variable>

You can almost invariably rewrite this as <xsl:variable name="sName" select="."/> (or perhaps select="string(.)"). This isn't just a stylistic issue, it's a lot more efficient to bind a variable to a node or a string than to construct a temporary tree.


Michael Kay
Saxonica

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.