Subject: Re: [xsl] Match values? (sorry so big) From: Joerg Heinicke <joerg.heinicke@xxxxxx> Date: Sun, 22 Sep 2002 02:06:21 +0200 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Match values? (sorry so big), RShonk | Thread | Re: [xsl] Match values? (sorry so b, RShonk |
Re: [xsl] using attribute value as , Joerg Heinicke | Date | Re: [xsl] Can you apply a template , Mike Carlisle |
Month |