[xsl] key definition

Subject: [xsl] key definition
From: "Steve Renshaw" <renshaw_steve@xxxxxxxxxxx>
Date: Sun, 28 Oct 2001 13:38:03 +0000
Given the following XML:

  <items>
   <item>
   <data id="1">alpha</data>
   <data id="2">gamma</data>
   </item>
   <item>
   <data id="1">alpha</data>
   <data id="2">delta</data>
   </item>
   <item>
   <data id="1">beta</data>
   <data id="2">gamma</data>
   </item>
  </items>

I am searching for a key definition that will return the set of <item>'s
that have a given @id and <data> value. I want to use key() in the following manner:


  given variables $id and $value
  select="key('MyKey',concat($id,$value))"

  examples
  select="key('MyKey',concat('1','alpha'))
  returns the first and second <item>'s

  select="key('MyKey',concat('2','gamma'))
  returns the first and third <item>'s

Anyone know how to complete this definition (or suggest another)?

<xsl:key name="MyKey" match="/items/item" use="?" />

Second question: What happens if I encounter markup that looks like
this:

  <item>
   <data id="1">01</data>
   <data id="10">1</data>
  </item>

in which case the usage of concat($id,$value) aliases into "101"

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread