[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

problem building a lookup table and find match from a

Subject: problem building a lookup table and find match from a different template
From: "Leslie Young" <xlr8sx@xxxxxxxxxxx>
Date: Tue, 29 Aug 2006 20:38:36 -0500
match problems
Hi,
I am trying to create a table lookup using a set of data (dataset2), then process a different set of data (dataset1). While going through each item in the dataset1, if a value is found for the item in dataset2, use dataset2's value. If not, display dataset1's value in a html page. I have a couple of problems, not sure what to do with it.


1) All the data stored in the table display on the html page as a long string. The data is supposed to be used for lookup. I do not know why it shows up in the html page.

2) I have a statement to do a quick lookup, but it does not seem find the match in the lookup table. How to do the lookup in a different template than the template where the lookup table is built? If I move the statement to where the lookup table is built, it can find the value.

Any suggestion is greatly appreciated.
Thanks!

Here is my xml: (simplied version)

<dataset1 someData>
 <Root>
   <Item ID="A" Value="001"></Item>
   <Item ID="B" Value="002"></Item>
   <Item ID="C" Value="003"></Item>
   <Item ID="D" Value="004"></Item>
 </Root>
</dataset2>

<dataset2 someData>
 <Root someData
   <Item ID="B" Value="222"></Item>
   <Item ID="D" Value="444"></Item>
 </Root>
</dataset2>


Desired output: A 001 B 222 C 003 D 444



Xsl:
<xsl:stylesheet version="1.0"
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               xmlns:xalan="http://xml.apache.org/xalan"
               xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:s="http://recs.data"
               >

<xsl:key name="rec-lookup" match="s:rec" use="s:keyid"/>
<xsl:variable name="recs-top" select="document('')/*/s:recs"/>


<xsl:template name="main-html">


 <!-- use dataset2 to build table    -->
    <xsl:choose>
     <xsl:when test="dataset2/Root">
       <xsl:call-template name="build-rec-lookup-table">
         <xsl:with-param name="dataset" select="dataset2/Root"/>
       </xsl:call-template>
     </xsl:when>
   </xsl:choose>

 <!-- process dataset 1 -->
 <div align="center" class="whitebg">
   <!-- process raw data -->
   <xsl:choose>
     <xsl:when test="dataset1/Root">
       <xsl:call-template name="generate-html">
         <xsl:with-param name="dataset" select="dataset1/Root"/>
       </xsl:call-template>
     </xsl:when>
   </xsl:choose>

</div>

</xsl:template>


<xsl:template name="build-rec-lookup-table"> <xsl:param name="dataset"/>

 <s:recs>
 <xsl:for-each select="$dataset/Item">
         <s:rec>
         <s:keyid><xsl:value-of select="@ID" /></s:keyid>
         <s:value><xsl:value-of select="@Value" /></s:value>
         </s:rec>
 </xsl:for-each>
 </s:recs>

</xsl:template>


<xsl:template name="generate-html">


 <!-- incomplete coding, only a brief testing to look up the table -->
 <td>
    A<xsl:value-of select="key('rec-lookup','A')" />
 </td>

</xsl:template>

_________________________________________________________________
Call friends with PC-to-PC calling -- FREE http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline


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.