hi Jonty...thanks again for sorting this out..below are all my input files and xslts. [this is going to be a long post]
------------------first.xml----------------------
<?xml version="1.0"?>
<root1>
<object partid ="4" name = "def" price = "3000"/>
<object partid ="5" name = "jkl" price = "130"/>
<object partid ="1" name = "abc1" price = "0"/>
<object partid ="2" name = "def" price = "430"/>
<object partid ="3" name = "abc" price = "350"/>
<object partid ="4" name = "abc" price = "230"/>
</root1>
----------------second.xml-----------------------
<?xml version="1.0"?>
<root2>
<object ID ="2" name = "def" price = "430"/>
<object ID ="4" name = "defijk" price = "3000"/>
<object ID ="50" name = "jkl" price = "130"/>
<object ID ="1" name = "abc" price = "0"/>
<object ID ="7" name = "abc" price = "2"/>
<object ID ="17" name = "xyz" price = "2"/>
</root2>
-----------------input1.xml----------------------
<?xml version="1.0"?>
<input>
<file1>first.xml</file1>
<param1>partid</param1>
<file2>second.xml</file2>
<param2>ID</param2>
</input>
----------------test2.xslt-------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xsl:variable name="file1" select="//file1" />
<xsl:variable name="file2" select="//file2" />
<xsl:variable name="param2" select="//param2" />
<xsl:variable name="param1" select="//param1" />
<xsl:template match="/">
<root>
<xsl:variable name ="attribute1" select = "document($file2)//@ID"/>
<xsl:copy-of select="document($file1)//*[@partid=$attribute1]"/>
</root>
</xsl:template>
</xsl:stylesheet>
--------------------result.xml-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<root>
<object partid="4" name="def" price="3000"/>
<object partid="1" name="abc1" price="0"/>
<object partid="2" name="def" price="430"/>
<object partid="4" name="abc" price="230"/>
</root>
As you can see the result is fine...only matching nodes are copies. I am using xalan parser and
following is the command that I use to run the xslt engine...
java org.apache.xalan.xslt.Process -in input1.xml -xsl test2.xsl -out result.xml
What i am doing is that I am processing input1.xml which contains the filenames for the two files
and also the attribute names. Then using the xslt...I am opening these files and copying the
content using the following two lines
<xsl:variable name ="attribute1" select = "document($file2)//@ID"/>
<xsl:copy-of select="document($file1)//*[@partid=$attribute1]"/>
but when I try to make the attribute name generic by replacing the above two lines with this....
<xsl:variable name ="attribute1" select = "document($file2)//@*[name(.)=$param2]"/>
<xsl:copy-of select="document($file1)//*[@*[name(.)=$param1]=$attribute1]"/>
it gives an xpath error...
my new xslt is
-------------------------------------------------------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xsl:variable name="file1" select="//file1" />
<xsl:variable name="file2" select="//file2" />
<xsl:variable name="param2" select="//param2" />
<xsl:variable name="param1" select="//param1" />
<xsl:template match="/">
<root>
<xsl:variable name ="attribute1" select = "document($file2)//@*[name(.)=$param2]"/>
<xsl:copy-of select="document($file1)//*[@*[name(.)=$param1]=$attribute1]"/>
</root>
</xsl:template>
</xsl:stylesheet>
What is wrong here...even I try to delcare a simple variable and try to use it...still could not
get it.
Thank you for your earlier responses and I will wait for this one as well. Plus, if you any good
idea about solving this problem i.e. taking the intersection of two xml files bases on some
attributes and similarly doing other operations such as taking union of two xml files...I would
really appreciate that. There is a limitation as well...because we will be working on very large
sets of data...millions of records...so we need a memory efficient solution.
Thanks jonty.