Ich muss in ein Element die <sectionid/>
, <amendmenttext/>
und <sponsor/>
Elemente ziehen, wenn verfügbar. Hierletzte Gruppe der vorherigen Geschwister erhalten mit XSLT
ein Beispiel:
Von:
<root>
<amendment>
<id>1</id>
<text>some text</text>
</amendment>
<sectionid>A</sectionid>
<sponsor>jon</sponsor>
<sponsor>peter</sponsor>
<amendment>
<id>8</id>
<text>some text</text>
</amendment>
<sectionid>B</sectionid>
<sponsor>matt</sponsor>
<sponsor>ben</sponsor>
<amendmenttext>some intro text</amendmenttext>
<amendment>
<id>5</id>
<text>some text</text>
</amendment>
<amendment>
<id>4</id>
<text>some text</text>
</amendment>
<sponsor>max</sponsor>
<amendment>
<id>6</id>
<text>some text</text>
</amendment>
<amendment>
<id>7</id>
<text>some text</text>
</amendment>
</root>
zu:
<root>
<amendment>
<id>1</id>
<text>some text</text>
</amendment>
<amendment>
<sectionid>A</sectionid>
<sponsor>jon</sponsor>
<sponsor>peter</sponsor>
<id>8</id>
<text>some text</text>
</amendment>
<amendment>
<sectionid>B</sectionid>
<sponsor>matt</sponsor>
<sponsor>ben</sponsor>
<amendmenttext>some intro</amendmenttext>
<id>5</id>
<text>some text</text>
</amendment>
<amendment>
<sectionid>B</sectionid>
<sponsor>matt</sponsor>
<sponsor>ben</sponsor>
<id>4</id>
<text>some text</text>
</amendment>
<amendment>
<sectionid>B</sectionid>
<sponsor>max</sponsor>
<id>6</id>
<text>some text</text>
</amendment>
<amendment>
<sectionid>B</sectionid>
<sponsor>max</sponsor>
<id>7</id>
<text>some text</text>
</amendment>
</root>
Anmerkung 1: Das <sectionid/>
Element gilt für alle <amendments/>
vor dem nächsten <sectionid/>
Anmerkung 2: die <sponsor/>
Element gilt für alle <amendments/>
vor der nächsten <sponsor/>
Liste.
Hinweis 3: Die Werte //amendment/id
sind nicht sequenziell.
Hinweis 4: Ein konnte keine <sponsor/>
oder <sectionid/>
als Vorgänger-Geschwister haben.
Note 5: <amendmenttext>
gilt nur für die folgenden <amendment/>
Wie diese Transformation mit XSLT 1.0 getan werden kann.
Änderungen von der vorherigen Frage http://StackOverflow.com/Questions/4096481/Refactor-XML-with-xsl ist eine Minderjährige. Ich denke nicht, dass es eine neue Frage verdient. –
Oki. Nicht wissen, dass die Lösung ähnlich wäre. Ich dachte, es sei nicht fair gegenüber den ursprünglichen Respondern, den Kontext der Frage zu ändern, nachdem sie geantwortet hatten. Aber Punkt genommen. –