我試圖使用XSLT將context-param
作爲最後一個兄弟。沒有共同的父元素,所以任務有點困難。XSLT - 追加兄弟
我想追加以下元素:
<context-param>
<param-name>miku</param-name>
<param-value>kawaii</param-value>
</context-param>
作爲最後context-param
元素以下(例如,所有context-param
元素必須是彼此相鄰,它們不能在任何地方散落XML) XML:
<web-app>
<not_interesting_element1/>
<not_interesting_element2/>
<context-param>
<param-name>not_interesting_param_key1</param-name>
<param-value>kawaii</param-value>
</context-param>
<context-param>
<param-name>not_interesting_param_key2</param-name>
<param-value>kawaii</param-value>
</context-param>
<context-param>
<param-name>parameterThatsGuaranteedToBeHere</param-name>
<param-value>someValue</param-value>
</context-param>
<not_interesting_element3/>
<not_interesting_element4/>
<!-- ... servlets, ... -->
</web-app>
結果應該是這樣的:
<web-app>
<not_interesting_element1/>
<not_interesting_element2/>
<context-param>
<param-name>not_interesting_param_key1</param-name>
<param-value>kawaii</param-value>
</context-param>
<context-param>
<param-name>not_interesting_param_key2</param-name>
<param-value>kawaii</param-value>
</context-param>
<context-param>
<param-name>parameterThatsGuaranteedToBeHere</param-name>
<param-value>someValue</param-value>
</context-param>
<context-param>
<param-name>miku</param-name>
<param-value>kawaii</param-value>
</context-param>
<not_interesting_element3/>
<not_interesting_element4/>
<!-- ... servlets, ... -->
</web-app>
我該怎麼做?
追加什麼?請編輯問題並提供XML文檔和特定的兄弟節點,您要在其中添加'context-param'元素。然後通過評論通知我。 – 2012-04-19 11:56:14
請發佈說明問題的輸入和期望輸出XML樣本。 – 2012-04-19 11:56:30
@Dimitre Novatchev:問題已更新。 – woky 2012-04-19 12:11:19