|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Using XSLT's key() function while context in seco
If you look at s.xml, and look at your 'chnam' key, you'll see that chnam matches <Chnl> elements, of which there are none in s.xml. Remember that key() returns key-matches from the document containing the context node only. Does that make sense? ~ Scott -----Original Message----- From: Michael Ludwig [mailto:mlu@xxxxxxxxxxxxx] Sent: Monday, February 18, 2008 1:04 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Using XSLT's key() function while context in secondary document? I have a key I use to look up values. It works fine. Now I process another document using XSLT's document() function. My key stops working. What a pity. Why does it not work? Can I work around this situation? xsltproc a.xsl x.xml #### x.xml - principal document <XPG> <Channels> <Chnl ID="ard">ARD</Chnl> <Chnl ID="zdf">ZDF</Chnl> </Channels> </XPG> #### s.xml - document pulled in via XSLT's document() function <BcStat> <Channel>zdf</Channel> <Channel>ard</Channel> <Channel>zdf</Channel> </BcStat> #### a.xsl <?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" indent="yes"/> <xsl:variable name="pntr" select="/XPG/Channels/Chnl"/> <xsl:key name="chnam" match="Chnl" use="@ID"/> <xsl:template match="/"> <Urmel> <p><xsl:value-of select="key('chnam', 'ard')"/> key works</p> <xsl:for-each select="document('s.xml')//Channel"> <div> <p> <xsl:value-of select="$pntr[ @ID = current() ]"/> <xsl:text> variable works</xsl:text> </p> <p><xsl:value-of select="key('chnam', current())"/> key doesn't</p> <p><xsl:value-of select="key('chnam', .)"/> NO</p> <p><xsl:value-of select="key('chnam', string())"/> NO</p> <p><xsl:value-of select="key('chnam', 'ard')"/> NO</p> </div> </xsl:for-each> </Urmel> </xsl:template> </xsl:stylesheet> Michael
|
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
|

Cart








