使用 XSLT 删除 xml 标签 [英] remove xml tags with XSLT

查看:29
本文介绍了使用 XSLT 删除 xml 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 xml 文件:

I have the following xml file:

<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>

我想删除每次出现的商业类型、用户列表和办公室列表节点,所以我的输出是:

I want to remove every ocurrence of the commercialType, userList and officesList nodes, so my output would be :

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

我如何使用 XSLT 做到这一点?

How could I do that using XSLT?

谢谢

推荐答案

这种转换产生了预期的结果:

<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>

这篇关于使用 XSLT 删除 xml 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆