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

Re: NodeTest expected here - problem with creating xs

Subject: Re: NodeTest expected here - problem with creating xsl:key fromdocument(url)
From: Chuck White <chuckwh@xxxxxxxxxxx>
Date: Mon, 26 Aug 2002 15:53:59 -0700
xsl nodetest expected here
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


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.