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

Re: AW: AW: [xsl] Using key() from outside the default namespace


Subject: Re: AW: AW: [xsl] Using key() from outside the default namespace
From: Peter Flynn <peter@xxxxxxxxxxx>
Date: 07 Aug 2003 01:41:10 +0100

On Wed, 2003-08-06 at 16:07, Markus Abt wrote:
> I can see the problem. However, the reason for the root template to
> be instantiated more than once is not the global variable $maindoc
> that holds the root node of the main document, nor is it the dummy
> <xsl:for-each> to switch the context back to the main document.

OK.

> The reason is:
> 
> (1) In your entry template, you define the variable $content with:
>         <xsl:variable name="content">
>           <xsl:for-each select="$maindoc">
>             <xsl:value-of select="key($keyname,$entryid)"/>
>           </xsl:for-each>
>         </xsl:variable>
> The value of this variable is now a result tree fragment, containing a
> root node and a text node with the string from the <xsl:value-of>.

So this for-each applied to my $maindoc actually places a node into the
variable? Yuck.

Oddly, if I declare maindoc to be some empty unused element buried deep
in the document (*anything* which will get me back to the main doc), it
still triggers the root template. 

> (2) In your format template, you use this variable (via the param of
> the same name):
>         <xsl:apply-templates select="$content"/>

Right, because $content may contain further subelements which need
matching in templates.

> This results in applying ("firing" in your words):
> -  The root template, and then
> -  the default template for text nodes.
> 
> So you get the output from the root template more than once.

Thank you very much, this explains what's happening. I really hadn't
expected the for-each to insert anything into the variable.

What I need is a key-with-respect-to-where-I-tell-it($foo,$bar).

> One solution would be to replace the <xsl:apply-templates>
> with a <xsl:value-of> to output only the text node of this
> result tree fragment:
>         <xsl:value-of select="$content"/>

Unfortunately not. The possibility of subelements needing processing
within $content precludes this.

It looks as if it simply isn't possible in XSLT transparently to
revisit a document like this to retrieve a key value. 

///Peter



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



Current Thread
Keywords