| 
 
Subject: RE: [xsl] Using XSLT's key() function while context in  secondary document? From: "Scott Trenda" <Scott.Trenda@xxxxxxxx> Date: Tue, 19 Feb 2008 11:35:41 -0600  | 
Unless there's going to be a processing error at
"document('s.xml')//Channel" when s.xml does not exist, then the pattern
should be solid here. From the XSLT 1.0 specification:
"When the second argument to the key function is of type node-set, then
the result is the union of the result of applying the key function to
the string value of each of the nodes in the argument node-set."
So, by passing document('s.xml')//Channel as the second argument to
key(), you can bypass the explicit context switch below, and jump right
into processing the key results. I had mentioned before that this is
beneficial only if no other processing is needed for the
document('s.xml')//Channel nodes, but that was part of the original
example.
~ Scott
-----Original Message-----
From: Andrew Welch [mailto:andrew.j.welch@xxxxxxxxx]
Sent: Tuesday, February 19, 2008 11:24 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Using XSLT's key() function while context in
secondary document?
On 19/02/2008, Scott Trenda <Scott.Trenda@xxxxxxxx> wrote:
>       <xsl:for-each select="key('chnam', document('s.xml')//Channel)">
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I don't know the origins of this thread but that looks highly dubious
- the key lookup would be the string value of all of the <Channel>
elements in s.xml.
If this is XSLT 1.0 then the pattern is:
<xsl:variable name="this" select="/">
<xsl:variable name="sDoc" select="document('s.xml')"/>
<xsl:for-each select="$sDoc//Channel">
  <xsl:variable name="lookup" select="."/>
  <xsl:for-each select="$this">
    <xsl:apply-templates select="key('chnam', $lookup)"/>
  ..
..
In 2.0 its much easier because you don't have to maintain a pointer to
the original source XML, and you have the slash operator, so the
equivalent is:
<xsl:apply-templates select="$sDoc//Channel/key('chnam', ., /)"/>
cheers
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/
| Current Thread | 
|---|
  | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] Using XSLT's key() functi, Andrew Welch | Thread | Re: [xsl] Using XSLT's key() functi, Andrew Welch | 
| Re: [xsl] [saxon - Help] SystemID a, Andrew Welch | Date | Re: [xsl] Using XSLT's key() functi, Andrew Welch | 
| Month |