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

NodeTest expected here - problem with creating xsl:ke

Subject: NodeTest expected here - problem with creating xsl:key from document(url)
From: "Macaulay,Malcolm (US)" <Malcolm.Macaulay2@xxxxxxxxx>
Date: Mon, 26 Aug 2002 17:02:44 -0500
xsl nodetest
Hi everyone,

I'm trying to create a key based on the contents of an external 'lookup' document, i.e. something like:

<xsl:key name="keyedLookupTable" match="document('LookupTable.xml')/LookupTable/Value" use="@key"/>

Is this allowed? I get a 'NodeTest expected here' error. I've tried a few alternatives (e.g. first assigning the external doc to a variable then using match="msxsl:node-set($myVariable) etc).

Can anyone point me in the right direction? I'm using MSXML4.

Below are two XSLTs below - one uses xsl:key and gives the error, the other works fine but I am querying into the lookupTable XML each time. My application has a large lookupTable and data file so I need the speed available from a key.

Data.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="C:\temp\for XSLT-List\XSLT without key.xslt"?>
<Data>
	<key>a</key>
	<key>b</key>
	<key>c</key>
</Data>

LookupTable.xml 

<?xml version="1.0" encoding="UTF-8"?>
<LookupTable>
	<Value key="a">value keyed by a</Value>
	<Value key="b">value keyed by b</Value>
	<Value key="c">value keyed by c</Value>
</LookupTable>

XSLT which doesn't work (gives 'NodeTest expected here' error)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

	<xsl:key name="keyedLookupTable" match="document('LookupTable.xml')/LookupTable/Value" use="@key"/>

	<xsl:template match="/">
		<Output>
			<xsl:for-each select="/Data/key">
				<xsl:variable name="currentKey" select="."/>
				<data>
					<xsl:value-of select="key('keyedLookupTable' , $currentKey)"/>
				</data>
			</xsl:for-each>
		</Output>
	</xsl:template>

</xsl:stylesheet>

XSLT which works (no key - look directly into 'Lookup.xml')

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	
	<xsl:variable name="lookupTable" select="document('LookupTable.xml')"/>
	
	<xsl:template match="/">
		<Output>
			<xsl:for-each select="/Data/key">
				<xsl:variable name="currentKey" select="."/>
				<data>
					<xsl:value-of select="$lookupTable/LookupTable/Value[ @key = $currentKey ]"/>
				</data>
			</xsl:for-each>
		</Output>
	</xsl:template>

</xsl:stylesheet>

Output expected (as produced by XSLT above):

<?xml version="1.0" encoding="UTF-8"?>
<Output>
	<data>value keyed by a</data>
	<data>value keyed by b</data>
	<data>value keyed by c</data>
</Output>

Thanks in advance.

cheers

Malcolm





 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.