This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Match values from XML-file A with values from XML-file B
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Match values from XML-file A with values from XML-file B
- From: Adam Turoff <ziggy at panix dot com>
- Date: Thu, 24 May 2001 13:09:24 -0400
- References: <5FA67811FB598647AFABF8409922CAEA05F69F@tobey.net.klopotek.de>
- Reply-To: xsl-list at lists dot mulberrytech dot com
On Thu, May 24, 2001 at 06:37:35PM +0200, "Sellmer-Brüls, Barbara" wrote:
>
> [source documents snipped]
>
> Idea 1:
> The stylesheet operates on file A (codes) and selects products from file B.
> Somehow I feel that there must be an elegant solution, but I don't know how
> to match n codes from the chapter code list to m codes within each product
> od the export file, AND sort the complete result of each chapter :-(
This is quite workable.
First, you want to load up the second document (B.xml), so you have
it around when processing the first document (A.xml). This should
be done at the top level.
<xsl:variable name="doc" select="document('B.xml')"/>
Then, when processing the report template (A.xml), refer back to the
second document, and select out the relevant portions.
<xsl:template match="category">
<!-- keep track of the code we want -->
<xsl:variable name="code" select="@code"/>
<!-- select products with that category code -->
<xsl:variable name="products"
select="$doc/export/product[class/category/category/@code=$code]"/>
<!-- process this category...-->
<category code="{$code}">
<!-- ...and process each product matching this category -->
<xsl:apply-templates select="$products"/>
</category>
</xsl:template>
That's it. Of course, you'll need to define templates to match
<product/>, but that's to be expected.
Hope this helps,
Z.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list