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

Match values? (sorry so big)

Subject: Match values? (sorry so big)
From: RShonk@xxxxxxxxxxxxx
Date: Fri, 20 Sep 2002 16:06:56 -0400
match value
Quick background:
I am merging 4 xml documents into a PDF doc using xsl-fo and xslt.
I have one xml document containg filenames. XML file 1 contains
header information. XML file 2 contains addresses and
the XML file 3 contains detail items. What I want to do is loop through all
the header records. On each header select a matching address from file3
using an account number element value from file 1 and then select multiple
detail
records from file 2 using an id element value from file 1. My problem is 2
fold
1) the xml files returned from the database share the same top level
elements
<ROWSET> and <ROW> and the key elements have the same name in both
files, <ACCOUNT> and <SHIPID> so can I differentiate file1.rowset.row from
file2.rowset.row in my template match values?
2) The key is defined before the file variables so what can I use as a
match value.

My xml files look like this

<ROWSET>
  <ROW id="1">
    <A>xxxx</A>
    <B>yyyy</B>
    <C>zzzz</C>
  </ROW>
  <ROW id="2">
    ...
</ROWSET> where <B> is shared with file 1 & 2
and <C> is shared with file 2 & 3
Elements in file2 would be <B>, <D> and <E>
Elements in file3 would be <C>, <F> and <G>

My stylesheet looks like:

<xsl:stylesheet ... >
  <xsl:output method="html"/>
  <!-- key for file1 to file2 join -->
  <xsl:key name="acctkey" match="???//ROW" use="ACCOUNT"/>
  <!-- key to file1 to file3 join -->
  <xsl:key name="shipkey" match="???//ROW" use="SHIPID"/>

<!-- template for xml file name document -->
<xsl:template match="/xml-files">
  <xsl:variable name="headers" select="document(@file1)"/>
  <xsl:variable name="accounts" select="document(@file2)"/>
  <xsl:variable name="lineitems" select="document(@file3)"/>

  <xsl:apply-templates select="$headers//ROW"/>
</xsl:template>

<!-- file1 ROW -->
<xsl:template match="???//ROW">  <!-- all forms of $headers gives invalid
token -->
  <xsl:apply-templates/>
</xsl:template>

...

<!-- template file1 account number -->
<xsl:template match="B"/>  <!-- match value? -->
  <xsl:value-of select="."/>
  <xsl:apply-templates select="key('acctkey', '.')"/>
</xsl:template>

<!-- template file1 account number -->
<xsl:template match="B"/>  <!-- match value? so file 1 <B> only -->
  <xsl:value-of select="."/>
  <xsl:apply-templates select="key('acctkey', '.')"/>
</xsl:template>

<!-- file 2 ROW -->
<xsl:template match="???//ROW">
  <xsl:value-of select="D"/>
  <xsl:value-of select="E"/>
</xsl:template>

</xsl:stylesheet>

Thanks,
Richard Shonk
Flowserve Corp.
Programmer / Analyst
Parts Distribution Center
Moosic, Pa.
(570) 451-2225


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


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.