[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Can xsl:key use a globally declared variable?
Hi Folks, I have an airports document containing data for several airports: <airports> <row> <icao>KBOS</icao> <name>Boston Logan Airport</name> </row> <row> <icao>KIAD</icao> <name>Washington Dulles Airport</name> </row> </airports> I want my XSLT program to output the <row> element for the airport with icao = KBOS. I declare a variable to hold the airports document: <xsl:variable name="airport-file" select="doc('airports.xml')"/> I declare an xsl:key to index the rows, using the <icao> element to identity the desired <row>: <xsl:key name="airports-with-icao" match="$airport-file/airports/row" use="icao"/> In a template I declare a variable to hold the icao of the desired airport: <xsl:variable name="airport-icao" select="'KBOS'"/> I use the key() function to obtain the desired <row>: <xsl:sequence select="key('airports-with-icao', $airport-icao)" /> The output is empty. Why? What am I doing wrong? How to fix it? Below is my complete XSLT program. /Roger <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" /> <xsl:variable name="airport-file" select="doc('airports.xml')"/> <xsl:key name="airports-with-icao" match="$airport-file/airports/row" use="icao"/> <xsl:template match="/"> <results> <xsl:variable name="airport-icao" select="'KBOS'"/> <xsl:variable name="Boston-airport-version1" select="key('airports-with-icao', $airport-icao)"/> <version1-results> <xsl:sequence select="$Boston-airport-version1" /> <!-- This produces no output --> </version1-results> <xsl:variable name="Boston-airport-version2" select="$airport-file/airports/row[icao eq $airport-icao]"/> <version2-results> <xsl:sequence select="$Boston-airport-version2" /> <!-- This produces the desired output --> </version2-results> </results> </xsl:template> </xsl:stylesheet>
|
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
|