[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: keys: repeated nodes from same key value

Subject: Re: keys: repeated nodes from same key value
From: Joe English <jenglish@xxxxxxxxxxxxx>
Date: Thu, 10 Aug 2000 17:03:25 -0700
key value index
"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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.