2012-11-29 43 views
0

我想這個XML轉換如何刪除下面的xml文件中的子元素?

<root> <c.head ampexmnem="dl1"><h.info><text>CALENDAR YEAR: 2012</text></h .info></c .head> </root> 

<root> <dl1>CALENDAR YEAR: 2012</dl1> </root> 

我怎麼能這樣做?

+0

您的XML無效(標記名稱中帶有空格的「轉義」引號和結束標記)。 –

+0

它在java程序中 – Phoenix

+0

結束標記仍然存在錯誤。我試圖直接編輯它,但它不會讓我刪除少於六個字符。 –

回答

0

這個怎麼樣:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="node()"> 
    <xsl:copy> 
     <xsl:apply-templates/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="c.head"> 
    <xsl:element name="{@ampexmnem}"> 
     <xsl:value-of select="."/> 
    </xsl:element> 
    </xsl:template> 

</xsl:stylesheet> 

當然,實際的模式取決於您的文檔的實際結構。我懷疑他們中有不止一個分支。

+0

根中可能有多個子元素,我只想刪除c.head ampexmnem =「dl1」>並用替換 – Phoenix

+0

是否有不同的'ampexmnem'屬性?根據此屬性的值,結果元素是否應具有不同的名稱? –

+0

是的,有一個屬性值dl1和另一個直到,我想只得到dl1轉換,而不是直到 – Phoenix