[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
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

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.