[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Can keys go out of scope?
key() always selects nodes in the document containing the context node. You problem is probably that you are calling it at a point where the context node is in a different document (or temporary tree). Usual circumvention (in XSLT 1.0) is (a) define a global variable <xsl:variable name="root" select="/"/> (b) use key() within a for-each: <xsl:for-each select="$root"> <xsl:.... select="key('a', 'b')" </xsl:for-each> With XPath 2.0 you can write <xsl:.... select="$root/key('a', 'b')" to switch documents. Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of > TSchutzerWeissmann@xxxxxxxxxxxxxxxx > Sent: 01 March 2002 18:19 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Can keys go out of scope? > > > I know keys can't go out of scope, I just want to know why > I'm having to do > this: > > <xsl:template match="Billcode"> > <xsl:variable name="current" select="."/> > <xsl:apply-templates > select="$template/sc:static/*" mode="static"> > <xsl:with-param name="current" select="$current"/> > <xsl:with-param name="score" > select="key('scores',@ScoreRef)"/> #I > shouldn't need to do this > </xsl:apply-templates> > </xsl:template> > > > The key only gets used at the other end of some chained > templates, and I > would have hoped to be able to do this: > <xsl:value-of select="key('scores',$current/@ScoreRef)"/>, > > given that I'm passing the Billcode element down the chain in > the $current > parameter. I've been through this n times, it even works on a > different > stylesheet. I've tested the value of $current/@ScoreRef at > every step of the > way, and it's what it was in the first template shown above. > Any idea what's > going on (or, (@~!# as Captain Haddock would say)? > > Thanks for your help > Tom > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|