[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

Subject: RE: Using XSLT's key() function while context in secondary document?
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Mon, 18 Feb 2008 13:07:50 -0600
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

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
     <Chnl ID="ard">ARD</Chnl>
     <Chnl ID="zdf">ZDF</Chnl>

#### s.xml - document pulled in via XSLT's document() function

#### a.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  <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="/">
    <p><xsl:value-of select="key('chnam', 'ard')"/> key works</p>
    <xsl:for-each select="document('s.xml')//Channel">
       <xsl:value-of select="$pntr[ @ID = current() ]"/>
       <xsl:text> variable works</xsl:text>
      <p><xsl:value-of select="key('chnam', current())"/> key
      <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>


Current Thread


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.
First Name
Last Name
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.