Re: [xsl] Match values from XML-file A with values from XML-file B

Subject: Re: [xsl] Match values from XML-file A with values from XML-file B
From: Adam Turoff <ziggy@xxxxxxxxx>
Date: Thu, 24 May 2001 13:09:24 -0400
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"

	 <!-- process this category...-->
	 <category code="{$code}">
	  <!-- ...and process each product matching this category -->
	  <xsl:apply-templates select="$products"/>

That's it.  Of course, you'll need to define templates to match 
<product/>, but that's to be expected.

Hope this helps,


 XSL-List info and archive:

Current Thread