2011-01-24 104 views
1

我有以下xml。XSLT從xml中移除元素

<?xml version="1.0" encoding="windows-1252"?> 
<Person> 
    <Header> 
     <Header>1</Header> 
    </Header> 
    <Details Id="2"> 
     <First>GERRARD</First> 
     <Last>STEVE1     </Last> 
    </Details> 
    <Details Id="3"> 
     <First>GERRARD</First> 
     <Last>STEVE2     </Last> 
    </Details> 
    <Details Id="3"> 
     <First>GERRARD</First> 
     <Last>STEVE3     </Last> 
    </Details> 
    <Footer> 
     <Footer>liverpool</Footer> 
    </Footer> 
</Person> 

我需要刪除Details元素,生成另一個XML看起來如下提前

<?xml version="1.0" encoding="windows-1252"?> 
<Person> 
    <Header> 
     <Header>1</Header> 
    </Header> 
    <Footer> 
     <Footer>liverpool</Footer> 
    </Footer> 
</Person> 

感謝。

+0

我花了一些時間,但是,確切的重複的[刪除XML標記使用XSLT(http://stackoverflow.com/questions/2641681/remove-xml-tags-with-xslt) – 2011-01-24 18:02:52

回答

7
<?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 select="node() | @*"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="Details"/> 

</xsl:stylesheet> 
+0

+1。正確答案。 – Flack 2011-01-24 12:35:17