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

Re: AW: AW: Using key() from outside the default names

Subject: Re: AW: AW: Using key() from outside the default namespace
From: Peter Flynn <peter@xxxxxxxxxxx>
Date: 07 Aug 2003 01:41:10 +0100
Re: AW: AW:  Using key() from outside the default names
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

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.