[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] A problem using the xsl:key facility


Subject: Re: [xsl] A problem using the xsl:key facility
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Tue, 20 Jul 2010 21:30:53 +0100

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
Keywords