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

Re: Match values? (sorry so big)

Subject: Re: Match values? (sorry so big)
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Sun, 22 Sep 2002 02:06:21 +0200
xslt match value
Hi Richard,

I can't see your real intention, but mybe my suggestions can help. While I think the approach should be changed, I can't really improve it, only more or less fix your code.

RShonk@xxxxxxxxxxxxx wrote:
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"/>

In XSLT there are modes possible, so that you can process a node multiple times or write templates for one node name in different modes.


<xsl:apply-templates select="$headers/ROWSET/ROW" mode="header"/>

</xsl:template>

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

You can't use a variable in template match, it's forbidden in XSLT. But you can also add the mode attribute here.


<xsl:template match="ROW" mode="header">

  <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:template match="ROW" mode="account">


  <xsl:value-of select="D"/>
  <xsl:value-of select="E"/>
</xsl:template>

</xsl:stylesheet>

Thanks,
Richard Shonk

Hmm, hope this helps a bit.


Regards,

Joerg



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.