2014-10-09 139 views
1

我有以下XML代碼XSLT刪除父某些子節點的屬性

<root_el> 
<cell> 
    <button id="btn_phone_mvg"> 
    <text>…</text> 
    </button> 
</cell> 
<cell> 
    <button id="btn_email_cmb"> 
    <text>…</text> 
    </button> 
</cell> 
<cell> 
    <button id="btn_address_mvg"> 
    <text>…</text> 
    </button> 
</cell> 
</root_el> 

,我需要把它轉換爲另一種XML,所有細胞與孩子按鈕ID_mvg結尾將被刪除

到目前爲止,我已經知道,要刪除所有具有某個id屬性值的子按鈕的單元格將需要此

<xsl:template match="cell[button/@id='value']"/> 

,並獲得最後的4個字符id屬性就會進行下一步的XPath表達式

substring(@id,string-length(@id)-4) 

但我不知道如何把這個一起,並得到所需的輸出

回答

4

試試這個方式與孩子<button>匹配<cell>具有與最後四個字符ID等於_mvg

<xsl:template match="cell[button[substring(@id,string-length(@id)-3)='_mvg']]"/> 

或者如果有的話,你可以用ends-with()功能字面上匹配字符串結尾:

<xsl:template match="cell[button[ends-with(@id, '_mvg')]]"/> 
+0

它的作品)謝謝 – 2014-10-09 13:18:06

相關問題