[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: NodeTest expected here - problem with creating xs
Hi Malcom, The only functions allowed in a pattern are id() and key(). So you just need to get around that. Something like this, but you can probably do better: <xsl:variable name="lookup" select="document('LookupTable.xml')" /> <xsl:key name="keyedLookupTable" match="LookupTable/Value" use="@key"/> <xsl:template match="/"> <Output> <xsl:for-each select="/Data/key"> <xsl:variable name="currentKey" select="."/> <data> <xsl:value-of select="$lookup[key('keyedLookupTable' , $currentKey)]"/> </data> </xsl:for-each> </Output> </xsl:template> Cheers, Charles White The Tumeric Partnership http://www.tumeric.net chuck@xxxxxxxxxxx http://www.javertising.com ________________________________________ Author, Mastering XSLT, Sybex Books Co-Author, Mastering XML, Premium Edition, Sybex Books ----- Original Message ----- From: "Macaulay,Malcolm (US)" <Malcolm.Macaulay2@xxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Monday, August 26, 2002 3:02 PM Subject: NodeTest expected here - problem with creating xsl:key from document(url) > 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 > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|