XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Cynthia van BovenSubject: Xquery to cross reference two files
Author: Cynthia van Boven
Date: 25 Mar 2009 12:31 PM
Hi Stylussees,

I am searching for a way to cross reference two xml files. My first file contains a list of payment/receipt request which all have a link to a project. My second file contains all projects.

The first file is imported after the second and if a payment/receipt is imported for a project which does not exist the import application returns an error.

What I want to do is cross reference the two xml files to check for projects which do not exist in file 2. So I made below xquery. Which either is not completey correct, cause it runs for hours without any result or my files are just too big - file 1 has 8525 records and file 2 2 has 20.000+ records.

Hope you can help me out,


for $ProjectNumber in doc('file:///e:/Klanten/Conversie/BetalingenOntvangsten/CrossReference/OnlyProjects.xml')/Projects/ProjectNumber return
let $arg1:=$ProjectNumber/text()
for $Project in doc('file:///e:/Klanten/Conversie/Projecten/5maart/AllProjectsOnly.xml')/Projects/Project return
let $arg2:=$Project/text()


if ($arg1=$arg2)
then ()

Ivan PedruzziSubject: Xquery to cross reference two files
Author: Ivan Pedruzzi
Date: 25 Mar 2009 06:14 PM

The following assumes that "ProjectNumber" from document 1 and "Project" from document 2 are the keys for testing your criteria

declare variable $OnlyProjects := doc('file:///e:/Klanten/Conversie/BetalingenOntvangsten/CrossReference/OnlyProjects.xml');
declare variable $AllProjectsOnly := doc('file:///e:/Klanten/Conversie/Projecten/5maart/AllProjectsOnly.xml');

for $ProjectNumber in $OnlyProjects/Projects/ProjectNumber
if(exists($AllProjectsOnly/Projects/Project[. = $ProjectNumber])) then ()
else concat("Project ", $ProjectNumber, " missing")

Ivan Pedruzzi
Stylus Studio Team

Cynthia van BovenSubject: Xquery to cross reference two files
Author: Cynthia van Boven
Date: 27 Mar 2009 05:33 AM
Thanks, I am gonna test it right away....

Posted another problem relating to these files in the XSLT board, cause besides valiation I also want to a separate ProjectMembers xml file into my Projects file. Posted under 'Performance xsl:for each and need for xsl:key instruction?'

Learned a lot this week! Thanks,


Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.