如何使用xPath将一个xml的节点附加到另一个xml

时间:2017-03-03 06:08:44

标签: xml xpath

我有一个像这样的XML文件:

<?xml version="1.0" encoding="UTF-8"?>
 <Rowsets>
    <Rowset>
        <Row>
            <Product>Product Name 1</Product>
            <EmployeeID>12345</EmployeeID>
            <SampleID>1</SampleID>
            <LineNo>Line1</LineNo>
        </Row>
        <Row>
            <Product>Product Name 2</Product>
            <EmployeeID>123456</EmployeeID>
            <SampleID>2</SampleID>
            <LineNo>Line2</LineNo>
        </Row>
        <Row>
            <Product>Product Name 3</Product>
            <EmployeeID>1234567</EmployeeID>
            <SampleID>3</SampleID>
            <LineNo>Line3</LineNo>
        </Row>
   </Rowset>
 </Rowsets>

和另一个XML文件,如:

<Rowsets>
    <Rowset>
        <Row>
            <Prod_Shift>1</Prod_Shift>
            <Target>2</Target>
            <FileName>FileName</FileName>
        </Row>
     </Rowset>
</Rowsets>

现在,对于第一个XML中的每个“Row”节点,我需要附加第二个XML的内容。

在第一个XML附加第二个XML之后,第一个XML应如下所示:

<?xml version="1.0" encoding="UTF-8"?>
 <Rowsets>
    <Rowset>
        <Row>
            <Product>Product Name 1</Product>
            <EmployeeID>12345</EmployeeID>
            <SampleID>1</SampleID>
            <LineNo>Line1</LineNo>
            <Prod_Shift>1</Prod_Shift>
            <Target>2</Target>
            <FileName>FileName</FileName>
        </Row>
        <Row>
            <Product>Product Name 2</Product>
            <EmployeeID>123456</EmployeeID>
            <SampleID>2</SampleID>
            <LineNo>Line2</LineNo>
            <Prod_Shift>1</Prod_Shift>
            <Target>2</Target>
            <FileName>FileName</FileName>
        </Row>
        <Row>
            <Product>Product Name 3</Product>
            <EmployeeID>1234567</EmployeeID>
            <SampleID>3</SampleID>
            <LineNo>Line3</LineNo>
            <Prod_Shift>1</Prod_Shift>
            <Target>2</Target>
            <FileName>FileName</FileName>
        </Row>
   </Rowset>
 </Rowsets>

我是xPath的新手。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您需要XSLT:

$routeProvider