tags:

views:

86

answers:

3

I have 2 xml files. I would like wite xsl program that eliminates (and create an new xml) all the nodes of SearchApp_MA_Request from SearchApp_LA_Request when Field4 and field5 and field6 are same in both files.

SearchApp_LA_Request.xml

<Request>
    <Rows>
        <Row1>
            <Field1>Item1</Field1>
            <Field2>Item2</Field2>
            <Field3>Item3</Field3>
            <Field4>Item4</Field4>
            <Field5>Item5</Field5>
            <Field6>Item6</Field6>
        </Row1>
        <Row2>
            <Field1>Item1</Field1>
            <Field2>Item2</Field2>
            <Field3>Item3</Field3>
            <Field4>Item4</Field4>
            <Field5>Item5</Field5>
            <Field6>Item6</Field6>
        </Row2>
        <Row3>
            <Field1>Item1</Field1>
            <Field2>Item2</Field2>
            <Field3>Item3</Field3>
            <Field4>Item4</Field4>
            <Field5>Item5</Field5>
            <Field6>Item6</Field6>
        </Row3>
        <Row4>
            <Field1>Item1</Field1>
            <Field2>Item2</Field2>
            <Field3>Item3</Field3>
            <Field4>Item4</Field4>
            <Field5>Item5</Field5>
            <Field6>Item6</Field6>
        </Row4>
    </Rows>
</Request>

SearchApp_MA_Request.xml

<Request>
    <Rows>
        <Row1>
            <Field1>Item1</Field1>
            <Field2>Item2</Field2>
            <Field3>Item3</Field3>
            <Field4>Item4</Field4>
            <Field5>Item5</Field5>
            <Field6>Item6</Field6>
        </Row1>
        <Row2>
            <Field1>Item1</Field1>
            <Field2>Item2</Field2>
            <Field3>Item3</Field3>
            <Field4>Item4</Field4>
            <Field5>Item5</Field5>
            <Field6>Item6</Field6>
        </Row2>
        <Row3>
            <Field1>Item1</Field1>
            <Field2>Item2</Field2>
            <Field3>Item3</Field3>
            <Field4>Item4</Field4>
            <Field5>Item5</Field5>
            <Field6>Item6</Field6>
        </Row3>
        <Row4>
            <Field1>Item1</Field1>
            <Field2>Item2</Field2>
            <Field3>Item3</Field3>
            <Field4>Item4</Field4>
            <Field5>Item5</Field5>
            <Field6>Item6</Field6>
        </Row4>
    </Rows>
</Request>
A: 

I don't know if any off-the shelf XSLT parsers will do what you're suggesting...

You may want to read one of the documents into a DOM tree, and then read in the other, adding each of the children in.

You could then either manipulate the DOM directly in memory, or else write it out to one document and then do the XSL transformation to get the unique values...

That's how I'd approach it at least.

John Weldon
+2  A: 

Yes,

I googled your question (using keywords merge xml xslt) and found this resource which seems to hit your question spot on: 'Merge Two Files' http://www.dpawson.co.uk/xsl/sect2/merge.html#d7584e19

[facimilie from link above]

Michael Kay

> 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>
> 

<xsl:copy-of select="document('a.xml')//id[.=document('b.xml')//id]"/>

The solutions uses the xslt function document() which can access nodes in a xml document. More info about that you can find on w3school: http://www.w3schools.com/Xsl/func_document.asp

Makach
A: 

According to what I understand, u need to merge 2 xml files using XSLT.

Have a look at "document()" function in XSLT.

Cheers

Ratnesh Maurya