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

Re: merging two documents - only if second document ma

Subject: Re: merging two documents - only if second document matches
From: Oliver Becker <obecker@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 1 Feb 2001 18:43:30 +0100 (MET)
document.ma
Hi Matt,

> I have two documents, file A and file B.  I want to join them on the id of
> the first, but only if a matching id is in the 2nd.  How do I do this?
> 
> File A              File B               Desired Output
> <id> A </id>        <id> A </id>         <id> A </id>
> <id> B </id>        <id> C </id>         <id> D </id>
> <id> D </id>        <id> D </id>

This looks like the intersection of the elements of the two files.
Assuming there is a root element <ids> in each file, these are
named fileA.xml and fileB.xml respectively, the following lines
produce the desired output:

<xsl:variable name="idsA" select="document('fileA.xml')/ids/id" />
<xsl:variable name="idsB" select="document('fileB.xml')/ids/id" />

<xsl:template match="/">
   <xsl:for-each select="$idsA[. = $idsB]">
      <xsl:copy-of select="." />
   </xsl:for-each>
</xsl:template>

The question is, if your input is really as simple as you said.
For example it might be reasonable comparing the normalized string
values like this
   normalize-space() = normalize-space($idsB)
inside of the predicate.

Hope that helps,
Oliver


/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@xxxxxxxxxxxxxxxxxxxxxxx             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/


 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.