[xsl] Re: xsl:key on variable containing result of apply-templates

Subject: [xsl] Re: xsl:key on variable containing result of apply-templates
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Mon, 25 Nov 2002 00:30:02 -0800 (PST)
--- Grainne Reilly  wrote:
 
> Thanks Joerg for your reply.
> In trying to isolate the problem (and maybe show too much of what I
> had
> 
> tried) I was not clear enough that I do a lot of processing, creation
> of 
> elements, attributes etc. in order to create the node-set I'd like to
> key on.
> As a result I cannot use an XPath as the match for the key.  My real
> xml is 
> an XML spreadsheet and you would not like to see the real xslt
> template
> :-)
> So my question remains if it is possible to create a key on the
> result
> of 
> apply-templates (using an extension function perhaps)?  Since xslt
> does
> not 
> permit the use of a variable reference in the match attribute of the 
> xsl:key element, I am less than hopeful that there is.
> Grainne.


Joerg gave you the solution -- you seem to have difficulties
understanding it and how xsl:key and the key() function work.

It is possible to declare xsl:key and use the key() function with the
name of this xsl:key on many different xml documents, including an xml
document that is the converted RTF, which contains results of the
current transformation.

And Joerg explained this well in his reply.

The steps are:

1. Collect the results of processing as the RTF contents of an
xsl:variable

2. Convert this RTF to a normal node-set (this will contain a root node
and will be a totally different xml document)

3. Use xsl:for-each to set the current document to the converted RTF
(the "select" attribute usually specifies just the single root node and
has no other purpose than shifting the context).

4. Use the key function -- if the named xsl:key is used for the first
time on this document, the necessary indices will be created now, if
this is not the first time -- they will be reused.

Therefore, the xsl:key you need to create is:

<xsl:key name="alphabets" match="alphabet" use="@col"/> 


Just follow the solution outlined by Joerg -- it must work.




=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus ? Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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


Current Thread