Subject: Re: [xsl] merging two documents - only if second document matches From: Oliver Becker <obecker@xxxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 1 Feb 2001 18:43:30 +0100 (MET) |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] merging two documents - o, Michael Kay | Thread | Re: [xsl] merging two documents - o, Jeni Tennison |
RE: [xsl] Javascript Function with , Michael Fitzgerald | Date | Re: [xsl] hyperlinks, David Carlisle |
Month |