[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] NodeTest expected here - problem with creating xsl:key from document(url)


Subject: [xsl] 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

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
Keywords