This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: merging two documents - only if second document matches
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] merging two documents - only if second document matches
- From: Oliver Becker <obecker at informatik dot hu-berlin dot de>
- Date: Thu, 1 Feb 2001 18:43:30 +0100 (MET)
- Reply-To: xsl-list at lists dot mulberrytech dot com
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@informatik.hu-berlin.de |
| op|qo WWW: http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list