[xsl] Singling Out Nodes in Look-up Table

Subject: [xsl] Singling Out Nodes in Look-up Table
From: Chuck White <chuckwh@xxxxxxxxxxx>
Date: Mon, 14 Jan 2002 19:40:59 -0800
Hello:

In the following stylesheet I'm trying to map field element id attribute
values against both the Position element in the first source document and
the name="Position" attribute value pair in the second source document. The
second source doc is a lookup table, which is actually a proper mapping
against the first document, created by a separate, prior transform. You
might not be able to tell because I truncated each here because they're so
long, and I presume I ruined the association doing the truncating. So what I
want is, for example, to report on the id value for:

 <field id="IDAHBMIB" name="Position">ASM</field>
from the second document, mapped against original mapped element from whence
it came, which in this case was this from the first source document:
<ASM>
     <Department/>
     <Position>ASM</Position><!-- this is a key -->
     <Type>All Amounts</Type>
     <Status/>
    </ASM>
The mapping key is the Position element and "name" attribute value pair
within their respective documents.

I can get close with the key I'm using, which gives me the node set I'm
after, but I really need to map each node within that set, so that instead
of this statement:

<xsl:value-of select="$lookup/@id"/>

getting only the first node of the node set, I need a better statement that
iterates through the set. An apply-templates gets me the whole set, instead
of individual nodes, which makes sense to me. These are truncated source
docs -- the full docs would reveal that the key exposes large node sets
consisting of several id="xxxxxx" attribute value pairs.

I think I'm missing something hugely obvious here, but there seems to be a
party going on in my head, and most people on this list are a lot smarter
than me. I've stared at this long enough. Anyone see anything obvious that
I'm missing? My apologies for such a large question, but I'm in one of those
blind spots that I can't get out of on my own. My sincerest thanks in
advance!

------- the stylesheet:

<xsl:transform
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 version="1.0">
 <xsl:output method="text"/>
 <xsl:key name="lookup" match="row" use="field"/>
  <xsl:variable name="rma" select="document('rmaTables.xml')/dbdata"/>
  <xsl:template match="/">
  <xsl:apply-templates select="/RMASignature/Accounts/*/*/*"/>
    </xsl:template>


 <xsl:template match="/RMASignature/Accounts/*/*/*">
 <xsl:variable name="index" select="position()" />
  <xsl:value-of select="Position"/>
  <xsl:text>, </xsl:text>
    <xsl:value-of select="Department"/>
    <xsl:text> ------ The ID# for this position is </xsl:text>

  <xsl:apply-templates select="$rma">
   <xsl:with-param name="position" select="Position"/>
  </xsl:apply-templates>
<xsl:text>&#013;</xsl:text><xsl:text>&#013;</xsl:text>
 </xsl:template>

 <xsl:template match="dbdata">
 <xsl:param name="position"/>

    <xsl:variable name="lookup" select="key('lookup',
$position)/field[@name='Position']"/>
  <xsl:value-of select="$lookup/@id"/>

 </xsl:template>
</xsl:transform>

----------------------------------------------------------
ORIGINAL SOURCE DOCUMENT (truncated):

<?xml version="1.0" encoding="UTF-8"?>
<RMASignature>
 <Header>
   <DocHead>Please sign in appropriate box above title</DocHead>
   </Header>
 <Accounts>
  <GeneralAccounts AccountsType="General Accounts">
   <NonTechnical ProductLine="DRAM">
    <ASM>
     <Department/>
     <Position>ASM</Position>
     <Type>All Amounts</Type>
     <Status/>
    </ASM>

   </NonTechnical>
   <NonTechnical ProductLine="SRAM, Graphics, Flash, Mask ROM &amp; TFT">
    <ASM>
     <Department/>
     <Position>ASM</Position>
     <Type>All Amounts</Type>
     <Status/>
    </ASM>
       </Technical>
  </GeneralAccounts>
  <CorporateAccounts AccountsType="Corporate Accounts">
   <NonTechnical ProductLine="All Product Lines">
    <CAManager>
     <Department>C/A</Department>
     <Position>Manager</Position>
     <Type>All Amounts</Type>
     <Status/>
    </CAManager>

   </NonTechnical>
   <Technical ProductLine="All Product Lines">
    <CAManager>
     <Department>C/A</Department>
     <Position>Manager</Position>
     <Type>All Amounts</Type>
     <Status/>
    </CAManager>
     </Technical>
  </CorporateAccounts>
 </Accounts>
 <Footer>info here</Footer>
</RMASignature>

EXTERNAL DOCUMENT FOR MERGING:

<dbdata>
 <jdbc_info driver="sun.jdbc.odbc.JdbcOdbcDriver"
db_url="jdbc:odbc:some_uri"/>
 <user-info>
  <uname>Pugal St. James</uname>
  <uspass>test</uspass>
 </user-info>
 <table name="bindings" id="IDAUDMIB">
  <row id="IDAECMIB" productLine="DRAM">
   <field id="IDAHBMIB" name="Position">ASM</field>
   <field id="IDASDMIB" name="AccountsType">GeneralAccounts</field>
   <field id="IDAJEMIB" name="Department"></field>
   <field id="IDANCMIB" name="Type">All Amounts</field>
   <field id="IDASEMIB" name="Status"></field>
   <field id="IDAHCMIB" name="NonTechnical ProductLine">NonTechnical</field>
  </row>
<!-- many more rows here, truncated -->
  <row id="IDAWAMIB" productLine="DRAM">
   <field id="IDABFMIB" name="Position">Senior Manager</field>
   <field id="IDASDMIB" name="AccountsType">GeneralAccounts</field>
   <field id="IDAMFMIB" name="Department">Inside Sales</field>
   <field id="IDAWCMIB" name="Type">Over $10K</field>
   <field id="IDAREMIB" name="Status"></field>
   <field id="IDAHCMIB" name="NonTechnical ProductLine">NonTechnical</field>
  </row>
     </table>
</dbdata>




Chuck White
The Tumeric Partnership
http://www.tumeric.net
chuck@xxxxxxxxxxx
________________________________________
Co-Author, Mastering XML, Premium Edition
Sybex Books, May, 2001
http://www.javertising.com


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


Current Thread