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

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


Subject: AW: AW: [xsl] Using key() from outside the default namespace
From: Markus Abt <abt@xxxxxxxx>
Date: Wed, 6 Aug 2003 17:07:33 +0200

Hello Peter,

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.

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>.

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

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.


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"/>


Regards,
Markus
__________________________
Markus Abt
Comet Computer GmbH
http://www.comet.de


----------
Von: 	Peter Flynn
Gesendet: 	Mittwoch, 6. August 2003 01:21
An: 	xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Betreff: 	Re: AW: [xsl] Using key() from outside the default namespace

On Tue, 2003-08-05 at 02:16, Peter Flynn wrote:
> I'll sort out a minimal instance to demonstrate this.

This is in http://www.silmaril.ie/xslt/minimal.zip

 Length   Method    Size  Ratio   Date   Time   CRC-32    Name
--------  ------  ------- -----   ----   ----   ------    ----
     198  Defl:N      138  30%  08-05-03 23:40  8e998f3c  styles.xml
     952  Defl:N      367  61%  08-05-03 23:42  8b778bd3  bibstyle.css
      67  Defl:N       52  22%  08-06-03 00:06  73f11633  demo.css
     820  Defl:N      428  48%  08-06-03 00:15  d198d1a9  README
    1113  Defl:N      295  74%  08-06-03 00:16  270ec157  doc.html
    3611  Defl:N     1102  70%  08-06-03 00:16  b8c75731  doc2htm.xsl
     273  Defl:N      184  33%  08-06-03 00:16  66c1701f  doc.xml
--------          -------  ---                            -------
    7034             2566  64%                            7 files

README says:

This is a minimal set of files to reproduce the problem:

    How do you use a key which indexes nodes in the
    main document, when processing nodes from an
    auxiliary document via for-each using document()?

The canonical answer is to set a global variable to the document root
and then within the for-each of the document(), set a variable to hold
the desired key node, containing a dummy for-each to process the
global variable (which sets the context back to the main document),
within which you make the call to key().

This set of files does exactly that, and shows that this procedure
of using the global variable causes the document root template to
be fired, outputting unwanted nested literal result elements.

To run this, use something like

	$ saxon doc.xml doc2htm.xsl doc.html

<peter@xxxxxxxxxxx>
 




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



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



Current Thread