用XSLT

问题描述:

删除XML标记,我有以下XML文件:用XSLT

<xfa:data> 
    <form1> 
    <Page1> 
    <Page2> 
    <contractInfo> ... </contractInfo> 
    <paymentInfo> ... </paymentInfo> 
    </form1> 
    <commercialType> .... </commercialType> 
    <userList> ... </userList> 
    <officesList> ... </officesList> 
    <commercialType> .... </commercialType> 
    <userList> ... </userList> 
    <officesList> ... </officesList> 
    <commercialType> .... </commercialType> 
    <userList> ... </userList> 
    <officesList> ... </officesList> 
</xfa:data> 

我想删除commercialType,用户列表和officesList节点的每一个ocurrence,所以我的输出将是:

<xfa:data> 
    <form1> 
    <Page1> 
    <Page2> 
    <contractInfo> ... </contractInfo> 
    <paymentInfo> ... </paymentInfo> 
    </form1> 
</xfa:data> 

我怎么能这样做使用XSLT?

谢谢

+0

很好的问题(1)。 请参阅我的答案,了解使用并覆盖“身份规则”的完整解决方案。 :) – 2010-04-14 23:21:23

该变换产生所期望的结果

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 

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

<xsl:template match="commercialType|userList|officesList"/> 
</xsl:stylesheet> 
+0

谢谢,你的迅速反应是在这里节省了一天 – azathoth 2010-04-14 23:55:47

+0

它不适合我。任何想法? – Rohit 2013-08-19 14:21:10

+0

@Rohit,什么是“它”,什么“不起作用”?你确定你有和这个问题相同的源XML文档吗?你确定你执行与此答案中的转换相同的转换吗?您确定您使用的是兼容的,无bug的XSLT处理器吗? – 2013-08-19 14:27:30

身份转换加<xsl:template match="commercialType" priority="10"/>