Re: XSLT key() function document argument
I have a stylesheet that initializes some keys based on content in the input document. Then, the stylesheet applies templates to a node set variable whose contents come from an external file. For awhile I was very confused, because the keys weren't accessible from the templates that were being applied in the different context.
I find it interesting you are using <xsl:copy-of/> ... why not just point to the document root node rather than occupying the memory by creating an entire copy of the document:
<xsl:variable name="wf" select="document($wf-filepath)"/>
<xsl:template match="/rm:contentList"> <xsl:apply-templates select="$wf"/> </xsl:template>
That is exactly how I would do it, with a global:
<xsl:variable name="orig-context" select="/"/>
... and there is nothing inefficient at all about this since it is only storing a single node ... just like in my suggested modification for $wf above.
Is there some special syntax to access the original context from a context created when applying templates to a node set variable?
Nothing special about applying templates to a node set variable ... keeping the original context in a variable is entirely acceptable and quite common.
And, with my modification for $wf above you don't have a node set variable, you are just pushing another document through the template rules without incurring the overhead of creating the complete copy in a node set variable.
Remember that document() returns a document node (formerly called a root node) after reading the XML document into memory ... so the document is in memory somewhere, it just isn't *also* in a variable through your use of <xsl:copy/>.
I've often used a global variable storing the root node for precisely the purpose you've described. Not at all inefficient, nor wasteful, nor inelegant in my opinion.
I hope this helps.
. . . . . . . . . Ken
-- Upcoming: hands-on XSLT, XQuery and XSL-FO Washington DC Nov 2009 Interested in other classes? http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
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