2013-08-22 159 views
1

我想刪除包含值的記錄「()Z()」和空標籤, 輸入XML:刪除標籤包含特定值

<R> 
    <B_01> 
    <C_01_02>()z()</C_01_02> 
    <C_01_03>()z()</C_01_03> 
    <C_01_04>()z()</C_01_04> 
    <C_01_05>()z()</C_01_05> 
    <B_01_01> 
    <C_01_01_01>()z()</C_01_01_01> 
    <C_01_01_02>()z()</C_01_01_02> 
    </B_01_01> 
    </B_01> 
    <B_01> 
    <C_01_01>1116</C_01_01> 
    <C_01_02>0</C_01_02> 
    <C_01_03>1944-01-01T00:00:00</C_01_03> 
    <B_01_01> 
    <C_01_01_01>1900001761</C_01_01_01> 
    <M_01_01_01>0</M_01_01_01> 
    <M_01_01_01>1</M_01_01_01> 
    <M_01_01_02/><M_01_01_03/> 
    </B_01_01> 
    <M_01_01/> 
    <M_01_02/> 
    <M_01_03/> 
    <T1_01_01>ARNAUD</T1_01_01> 
    <T1_01_02>JEAN MARIE</T1_01_02> 
    </B_01> 
</R> 

我試過很多scirpts但事與願違工作

謝謝你的幫助

+0

Does http://stackoverflow.com/questions/6648679/removing-empty-tags-from-xml-via-xslt help? –

回答

0

也許這一個?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output omit-xml-declaration="no" indent="no"/> 
    <xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
    </xsl:template> 
    <!--xsl:template match="*[not(text()) or text() = '()z()']"/--> 
    <xsl:template match="*[not(node()) or text() = '()z()']"/> <!-- better --> 
</xsl:stylesheet> 
+0

我想一個腳本,它完美的作品,但我一直這個問題: - 謝謝 – MAYA

+0

@ user2664376我改變了代碼,以更好,更安全的解決方案,但我不明白是什麼你期望在B_01元素的情況下。一個空的元素? – jvverde

+0

謝謝你們,我使用了一個腳本,刪除空標籤,它完美的作品 – MAYA