Subject: Re: keys: repeated nodes from same key value From: Joe English <jenglish@xxxxxxxxxxxxx> Date: Thu, 10 Aug 2000 17:03:25 -0700 |
"Pawson, David" <DPawson@xxxxxxxxxxx> wrote: > > One more on keys(). > > Given two xml documents a.xml b.xml > How to create a key on b.xml > then iterate over an element in a.xml > [...] I recently struggled with this problem myself... The key() function returns "a node-set containing the nodes *in the same document as the context node* that have a value for the named key" [XSLT, 12.2]. Keys are defined without reference to any particular document; the <xsl:key> specification applies separately to each document that's loaded. So the trick is to select a node in 'b.xml', call the 'key()' function, then go back to the original node. In my situation, I had an index file that looked something like <index> <entry name="foo" href="asdf.html#section1"/> <entry name="bar" href="qwerty.html#section238"/> ... </index> To look up a key in the index, something like this worked: (untested...) <xsl:key name="index" match="entry" use="@name" /> <xsl:variable name="theIndex" select="document('index.xml')" /> <xsl:template match="reference"> <xsl:variable name="refname" select="@refname"/> <xsl:variable name="sourceNode" select="."/> <xsl:for-each select="$theIndex"> <xsl:variable name="href" select="key('index', $refname)"/> <xsl:for-each select="$sourceNode"> <A href="{href}"> <xsl:apply-templates/> </A> </xsl:for-each> </xsl:for-each> </xsl:template> --Joe English jenglish@xxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: keys: repeated nodes from same , Kay Michael | Thread | URGENT - my first xsl, Søren Neigaard |
Re: Is there an elegant way to copy, Mike Brown | Date | Re: Special characters and XML-to-W, Mike Brown |
Month |