Jak połączyć dwa lub więcej plików XML przy użyciu xslt i zachować kolejność?
Jeśli mam ten plik:plik wejściowy1.xml:
<code><schema> <sequence> <nodeA id="a"> <fruit id="small"> <orange id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </orange> </fruit> <fruit id="small"> <apple id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </apple> </fruit> <fruit id="medium"> <orange id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </orange> </fruit> </nodeA> <nodeB id="b"> <dog id="large"> <doberman id="x" method="create"> <condition> <color>Black</color> </condition> </doberman> </dog> </nodeB> </sequence> </schema> </code>
file2.xml:
<code><schema> <sequence> <nodeA id="a"> <fruit id="small"> <melon id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </melon> </fruit> </nodeA> <nodeB id="b"> <dog id="small"> <poodle id="x" method="create"> <condition> <color>White</color> </condition> </poodle> </dog> </nodeB> </sequence> </schema> </code>
Po połączeniu:output: concate.xml
<code><schema> <sequence> <nodeA id="a"> <fruit id="small"> <orange id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </orange> </fruit> <fruit id="small"> <apple id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </apple> </fruit> <fruit id="medium"> <orange id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </orange> </fruit> <fruit id="small"> <melon id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </melon> </fruit> </nodeA> <nodeB id="b"> <dog id="large"> <doberman id="x" method="create"> <condition> <color>Black</color> </condition> </doberman> </dog> <dog id="small"> <poodle id="x" method="create"> <condition> <color>White</color> </condition> </poodle> </dog> </nodeB> </sequence> </schema> </code>
Na koniec będziezależą od kolejności plików więc węzeł w pliku2.xml zostanie umieszczony pod węzłem pliku1.xml (jak widać na przykładzie). I mam do 5 plików. Jak można to osiągnąć przy użyciu transformacji xsl, tzn. Xslt wprowadzi 5 plików jednocześnie i wyśle 1 plik?
To jest struktura dokumentu i punkt, w którym łączymy:
<code><schema> <sequence> <nodeA id="a"> <fruit id="small"> <orange id="x" method="create"> ... </orange> </fruit> <fruit id="small"> ... </fruit> <fruit id="large"> ... </fruit> <!-- we merge below this --> </nodeA> <nodeB id="b"> <dog id="large"> <doberman id="x" method="create"> ... </doberman> </dog> <dog id="small"> <doberman id="x" method="create"> ... </doberman> </dog> <!-- we merge below this --> </nodeB> <somenode id="any"> ... </somenode> </sequence> </schema> </code>
Uwaga: Jeśli nie jest to możliwe, połączenie tylko dwóch plików wejściowych będzie dobre, ponieważ zawsze można je powtórzyć dla innych plików. Istnieją również różne nazwy węzłów w pliku (nodeA, nodeB, SomeNode itp.), Więc potrzebne jest coś, co może uogólnić ten problem.
możemy użyć xs1.0 lub 2.0.
Dziękuję bardzo. Jan