0

XML ファイルの一部のノードを、別の XML ファイルの同等のノードに置き換えたいと考えています。これは十分に挑戦的ではないので、比較に使用される ID を子の値にしたいと考えています。

「古い」XML は次のようになります。

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <Documents>
        <Document id="001">
            <Tags>
                <Tag id="document_id">someIDfilename.pdf</Tag>
                <Tag id="document_type">Type A</Tag>
                <Tag id="document_text">A very important document of course.</Tag>
            <Tags>
        </Document>
        <Document id="018">
            <Tags>
                <Tag id="document_id">someOtherIDfilename.pdf</Tag>
                <Tag id="document_type">Type B</Tag>
                <Tag id="document_text">Another very important document.</Tag>
            <Tags>
        </Document>
    </Documents>
</Root>

2 番目のドキュメントは、次の XML に相当するものに置き換えられます。これにより、使用する必要がある ID は document_id の値になります (ドキュメント ノードの「id」は上書きまたは変更されることがあるため)。

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <Documents>
        <Document id="014">
            <Tags>
                <Tag id="document_id">someOtherIDfilename.pdf</Tag>
                <Tag id="document_type">Type B</Tag>
                <Tag id="document_text">The oh so important new document text.</Tag>
            <Tags>
        </Document>
    </Documents>
</Root>

結果は次のようになると予想されます。

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <Documents>
        <Document id="001">
            <Tags>
                <Tag id="document_id">someIDfilename.pdf</Tag>
                <Tag id="document_type">Type A</Tag>
                <Tag id="document_text">A very important document of course.</Tag>
            <Tags>
        </Document>
        <Document id="018">
            <Tags>
                <Tag id="document_id">someOtherIDfilename.pdf</Tag>
                <Tag id="document_type">Type B</Tag>
                <Tag id="document_text">The oh so important new document text.</Tag>
            <Tags>
        </Document>
    </Documents>
</Root>

Q1: XSLT で可能ですか? または、Java / DOM を使用する必要がありますか?

Q2: Q1==yes の場合: 誰かここで解決できますか?

一番!フィリップ

4

1 に答える 1