Je dois tirer dans un élément <amendment/>
les éléments <sectionid/>
, <amendmenttext/>
et <sponsor/>
si disponible.obtenir le dernier groupe de frères et soeurs précédents avec XSLT
Voici un exemple:
De:
<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>
à:
<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>
Note 1: l'élément <sectionid/>
applique à tous les <amendments/>
avant la prochaine <sectionid/>
Note 2: le <sponsor/>
élément s'applique à tous les <amendments/>
avant la liste suivante <sponsor/>
.
Note 3: Les valeurs de //amendment/id
ne sont pas séquentielles.
Remarque 4: Un <amendment/>
ne peut pas avoir un <sponsor/>
ou <sectionid/>
comme un frère précédent.
Note 5: <amendmenttext>
applique uniquement sur les points suivants <amendment/>
Comment cette transformation peut être fait avec XSLT 1.0.
Modifications de la question précédente http://stackoverflow.com/questions/4096481/refactor-xml-with-xsl est une mineure. Je ne pense pas qu'il mérite une nouvelle question. –
Oki. Ne sachant pas que la solution serait similaire. Je pensais que ce n'était pas juste pour les premiers intervenants de changer le contexte de la question après qu'ils aient répondu. Mais point pris. –