1
我需要將<amendment/>
元素拉到<sectionid/>
,<amendmenttext/>
和<sponsor/>
元素(如果可用)。使用XSLT得到最後一組兄弟前代
下面是一個例子:
來自:
<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>
注1:<sectionid/>
元件適用於所有<amendments/>
下一<sectionid/>
之前注2:<sponsor/>
元素適用於所有<amendments/>
之前的下一個<sponsor/>
列表。
注3://amendment/id
的值不是連續的。
注4:<amendment/>
不能有<sponsor/>
或<sectionid/>
作爲前兄弟。
注5:<amendmenttext>
僅適用於以下<amendment/>
這怎麼轉型與XSLT 1.0完成。
上一個問題的修改http://stackoverflow.com/questions/4096481/refactor-xml-with-xsl是次要的。我認爲這不值得一個新的問題。 – 2010-12-07 16:25:07
Oki。不知道解決方案是相似的。我認爲原來的迴應者在回答問題後改變問題的背景是不公平的。但有一點要說。 – 2010-12-07 17:07:22