我需要一些編寫xsl的幫助。如何編寫xsl以獲取所有重複標籤的值?
我有如下的XML數據。
<Data>
<so_offer_display_value action="add">XXXX</so_offer_display_value>
<so_offer_id action="add">51005577</so_offer_id>
<so_offer_view_id action="add">3932079043</so_offer_view_id>
<so_offer_display_value action="add">YYYYY</so_offer_display_value>
<so_offer_id action="add">51005541</so_offer_id>
<so_offer_view_id action="add">3932080043</so_offer_view_id>
</Data>
我想要的輸出是:
<inst>
<offerId>51005577</offerId>
<instId>3932079043</instId>
<Description>XXXX</Description>
<Action>Add</Action>
</inst>
<inst>
<offerId>51005541</offerId>
<instId>3932080043</instId>
<Description>YYYY</Description>
<Action>Add</Action>
</inst>
我試圖像下面,但它打印相同值的兩倍。
<xsl:if test="/Data/so_offer_id/@action = 'add'">
<xsl:for-each select="/Data/so_offer_id">
<inst>
<offerId>
<xsl:value-of select="/Data/so_offer_id[@action='add']"/>
</offerId>
<instId>
<xsl:value-of select="/Data/so_offer_view_id[@action='add']"/>
</instId>
<Description>
<xsl:value-of select="/Data/so_offer_display_value[@action='add']"/>
</Description>
<Action>Add</Action>
<Quantity>1</Quantity>
</inst>
</xsl:for-each>
</xsl:if>
鑰匙在這裏並沒有真正做到有用的東西。而不是' '你可以簡單地說' '。 –
P.S.我不認爲你可以單獨使用索引,因爲問題表明可能存在其「行爲」不是「添加」的干預項目。但是,如果OP是幸福的... –
我認爲*鍵*比普通的模式選擇更快。這對於大量輸入尤其重要。 –